Run Apache and PHP on Mac OS X
Following the instructions in this article a tdevarticles.com I modified the httpd.conf file to enable Apache and PHP on Mac OS X:
The steps I followed on my OS X 10.3.5 installation.
- Start Apache Web Server
- Open the “System Preferences" Control panel.
- Click on "Sharing".
- Check the "Personal Web Sharing" box. This starts up Web sharing which starts the Apache Web Server.
- Open a web browser and type http://localhost in the address box.
- If Apache is working the browser should display:
- "If you can see this, it means that the installation of the Apache Web server software on this system was successful. You may now add content to this directory and replace this page."
- If Apache is working the browser should display:
- Enable PHP by "uncommenting" four lines in the httpd.conf "Apache HTTP Server Configuration" file.
- Start the Terminal.app located in the "/Applications/Utilities/" directory.
- in Terminal, change the directory to the "httpd" directory using the command:
- cd /etc/httpd
- in Terminal, start up the text editor named "Pico" and edit the httpd.conf file using the command:
- sudo pico httpd.conf
- (You'll be asked for the root password)
- sudo pico httpd.conf
- Locate the 4 lines:
- #LoadModule php4_module
- #AddModule mod_php4.c
- #AddType application/x-httpd-php .php
- #AddType application/x-httpd-php-source .phps
- (This is a long script - much scrolling will be needed)
- Very carefully remove only the pound signs (#) from the beginning of these four lines. Warning: Only remove the pound signs!! Don't move the lines of code around!! You have been warned!
- The changed lines should look like this:
- LoadModule php4_module
- AddModule mod_php4.c
- AddType application/x-httpd-php .php
- AddType application/x-httpd-php-source .phps
- Save the file by hitting the CTRL + X keys and hit the Y key to say “YES”.
- in Terminal, change the directory to the "httpd" directory using the command:
- Start the Terminal.app located in the "/Applications/Utilities/" directory.
- For this change to take effect the Apache Web Server must be restarted.
- Stop Apache Web Server
- Open the “System Preferences" Control panel.
- Click on "Sharing".
- Uncheck the "Personal Web Sharing" box (or click the Stop button).
- Check the "Personal Web Sharing" box (or click the Start button).
- Stop Apache Web Server
To check that all is working:
- Create this PHP script in an html file:
<html> <head> <title>phpinfo</title> </head> <body> <?php phpinfo(); ?> </body> </html>
- Save it as phpinfo.php in your /Users/~yourusername/Sites/ directory.
- Type the following URL in your web browser:
http://localhost/~yourname/phpinfo.php
To access your personal web pages:
Put them in the sites folder at the root level of your user account. Create one if needed. Open a web browser and type http://localhost/~yourusername/ in the address box.
Tags: Macintosh