Although Apple builds Apache and support for PHP into OS X.2, it doesnt actually turn these features on. Youll have to do that part yourself. Heres how:
Turn PHP Support On
To activate Apaches PHP module, youll first need to modify the Apache configuration file. Since the configuration file is hidden from the Finder, youll have to make a trip to the command line.
Open Terminal (Applications: Utilities: Terminal). Before you make any changes, youll want to create a backup of your Apache configuration filejust in case something goes wrong. To do this, type the following commands into the Terminal window:
cd /etc/httpd
sudo cp httpd.conf httpd.conf.orig
Enter your administrator password when prompted, and then type sudo pico httpd.conf. This command opens your Apache configuration file in pico, a Unix text editor. In pico, press control-W to open the Find command, and then type php. When you hit the return key, your cursor should land on the line:
#LoadModule php4_module libexec/httpd/libphp4.so
Using the left-arrow key to move your cursor, remove the # character at the beginning of this line. Press control-W again. This time, type the string:
mod_php4.c and press return.
Remove the # character from the beginning of this line as well. Press control-W a third time and search for the string x-tar. When you land on it, move your cursor to the end of the line, press return, and then add the line:
AddType application/x-httpd-php .php
Once youve made these three changes, save the file by pressing control-O and then the return key. Press control-X to exit pico. Apache should now automatically load the PHP module on start-up. When the Web server encounters pages ending in .php, itll send them to the PHP module for interpretation.
Start Apache
With PHP enabled, youre ready to flip the switch on your Web server. Open your System Preferences and select Sharing. Click on the Services tab, and select the Personal Sharing option. Click on Start. (If Web sharing was already on, youll need to turn it off and then back on to activate the changes youve made.)
Testing
To find out whether the PHP module has been correctly activated, open your favorite text editor and create a new document. (If youre using Apples TextEdit, make sure youve turned off the pro grams Rich Text features, in Preferences, first.) In your blank document, type <? Phpinfo(); ?>. Save the file as test.php in the Sites folder in your users folder. Open your Web browser, and type in the address http I host/ ph p, where username is your short name on the OS X machine. (Because PHP is a server-parsed language, nothing will happen if you open a PHP file in your Web browser via the File menu or by double-clicking. To execute PHP pages, you must access them through a PHP-enabled Web server.)
Your browser should display tables packed with arcane data about your new PHP environment. If you see only one line of raw PHP code, repeat this step.