Dave Perrett

PHP5 on OS X Leopard

osx, php, programming, web

PHP5 is already installed on Leopard by default - all you have to do is turn it on.

First, turn on web sharing - go to System Preferences->Sharing and make sure the ‘Web Sharing’ option is turned on.

Next, open the apache config file in a text editor using sudo.

1
$ sudo vi /etc/apache2/httpd.conf

Search for this line:

1
#LoadModule php5_module libexec/apache2/libphp5.so

And un-comment it by removing the ‘#’ at the start of the line:

1
LoadModule php5_module libexec/apache2/libphp5.so

The restart apache:

1
$ sudo apachectl restart

To test if it is working properly, make a file in the Sites folder for your user called test.php (in my case this is /Users/dave/Sites/test.php ) containing the following:

1
<?= phpinfo() ?>

Now if you go to http://localhost/~YOUR_USER_NAME/test.php (note the ‘~’ character before your username - it’s important), you should see something like this: