Enabling the default PHP on Mac OS X

Date: Fri Nov 09 2007
Mac OS X comes with a PHP interpreter built into the system. It is relatively easy to enable this so you can do PHP development.

First, make sure that "Web Sharing" is turned off.

Second, edit the file /etc/httpd/httpd.conf.

Third, search through that file for lines containing the string "php". You'll find two that are important, and that they commented out by having a '#' character at the beginning of the line. Remove the '#' character. The two lines are:

# LoadModule php4_module        libexec/httpd/libphp4.so
# AddModule mod_php4.c

Fourth, restart Web Sharing.

Fifth, test it by making a file in your ~/Sites directory named phpinfo.php and have it include the following:

<? phpinfo(); ?>

If this script successfully executes it prints a whole range of useful information about the PHP environment. You should keep this script handy.

By default Apple configures the directory "/Library/WebServer/Documents" so it appears on http://localhost. Each user has in their home directory a ~/Sites directory, which you can reach as http://localhost/~username.