Taming Leopard for PHP
I recently upgraded to Mac OS X Leopard. After the upgrade, MySQL was still working but PHP was not working at all. (The MySQL preference pane doesn’t work but I usually start and stop it from the command line anyway.) I discovered that there are three problems. I will briefly describe how to resolve them in case you have the same problem.
Grant Access To Your Sites Directory
Mac OS X Leopard uses Apache 2 instead of Apache 1.3. This only presents a problem because Apache 2 uses a different directory for its configuration files and Apple’s installer scripts do not move all your existing configuration files over. Those old files grant access to your user directory. The old configuration directory is /etc/httpd. The new configuration directory is /etc/apache2.
Let’s move the user configuration files over. We will ignore +entropy-php.conf file because it is only necessary for the old setup.
>cd /etc/apache2/users
>ls -l
# it is empty
# Now go to the old config directory
>cd /etc/httpd/users
>ls -l
-rw-r--r-- 1 root wheel 493 Mar 19 2007 +entropy-php.conf
-rw-r--r-- 1 root wheel 140 Jan 25 2007 jsmith.conf
-rw-r--r-- 1 root wheel 145 Jan 9 2007 kskoglund.conf
#copy the user files, ignore the entropy file
>sudo cp jsmith.conf /etc/apache2/users/jsmith.conf
>sudo cp kskoglund.conf /etc/apache2/users/kskoglund.conf
If this is a new install and not an upgrade, then you’ll need to create a .conf file for your username. The contents of that file should be simply (swapping in your username for mine):
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</directory>
Enable PHP 5
PHP 5.2.4 is installed with Leopard, but it is not enabled by default. You need to make a tiny edit to the main Apache 2 configuration file to enable it.
#always a good idea to make a backup first
>sudo cp httpd.conf httpd.conf.bak
# I use nano to edit the file but you can use another text editor instead
>sudo nano /etc/apache2/httpd.conf
Find the line that looks like this: #LoadModule php5_module libexec/apache2/libphp5.so and remove the “#” from the start of the line to uncomment it.
Help PHP find MySQL
Apple’s version of PHP 5.2.4 will look for a connection to MySQL by looking for the file /var/mysql/mysql.sock. In the past, that file was /tmp/mysql.sock.
Here’s a good explanation of your choices in how to fix it. I like solution #1 unless you have the time and energy to tackle solution #4. If you use Ruby on Rails or any GUI client to connect to MySQL then do NOT use solution #3—MySQL will put the file where PHP can find it but also where no one else can.
>sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
Restart the Webserver
And the last step is to restart the server with: sudo apachectl graceful
PHP 5 should be enabled, ready to connect to MySQL and accessible through your Sites directory.
A more thorough guide is here if you run into different issues or need more help. I should note that I disagree with their choice on how to fix the mysql.sock problem.

January 13th, 2008 at 1:50 pm
I finally needed to repair my dev environment post-leopard, and this post saved me hours. Thank you.
Also I’m a fan of Patrick Gibson’s ‘virtualhost.sh’ script for setting up my virtual hosts, and he now has a Leopard-compatible version: http://patrickgibson.com/utilities/virtualhost/
This replaced, for me, the first part of your explanation, and worked perfectly. Back in business!
January 20th, 2008 at 2:59 am
Your tutorial really helped me, was really confused at first. Thanks!
July 23rd, 2008 at 11:52 pm
Kevin! You saved me a lot of grief! Thank you so much sir. Congrats on the new baby:)
October 4th, 2008 at 6:35 am
Thank you so much. I was very irritated that it wasn’t working and had NO idea why. (The Terminal still scares me a little.)
The good people at Lynda.com send me your link, and I’m happy to say it worked perfectly!