Geir Arne Brevik, October 29 2007:

How to get Apache, php and mySQL to work on Leopard

The only trouble I had after upgrading from Mac OS X 10.4 Tiger to 10.5 Leopard was that my semi-custom LAMP-setup didn’t work. After a few hours of googling and reading config files, I found out the following:

Overview

  1. Leopard ships with Apache 2, with more restrictive security settings and new location and structure of it’s config files, compared to Tiger (the old files are still there, though)
  2. Leopard ships with php5 version 5.2.4, but it’s still turned off by default in Apache
  3. Leopard does not ship with mySQL, so you’ll still have to download and install (pretty easy), but beware that old installations might not communicate with php.

1: Getting to know Apache 2

Moved from /etc/httpd/, the running httpd.conf now resides in /etc/apache2/. And instead of keeping almost all of the contents in one monstrous long file, it has now been divided into task-specific files in subfolders, most notably /etc/apache2/extra/ and /etc/apache2/other/. But, here’s the thing (the ting that took me a couple of stupid hours to find out): Not all of those files are included in httpd.conf.

So, for instance, if you – like me – have your own set of virtual hosts, add them to /etc/apache2/extra/httpd-vhosts.conf and remove the comment hash from

Include /private/etc/apache2/extra/httpd-vhosts.conf

in httpd.conf (for me, on line 461, but ymmv).

The next thing you need to know is the tightened default security settings, that is

Order deny,allow
Deny from all

is set unless you override it. So in order to see anything on your site(s), make sure that you add

Order allow,deny
Allow from all

to your custom directory settings (for instance in httpd-vhosts.conf).

2: Getting php5 and mySQL to join the party

First, you need to tell Apache to load the php5 module, by removing the comment hash from the line

LoadModule php5_module libexec/apache2/libphp5.so

in httpd.conf. (for me, on line 114).
Then, after restarting your webserver, if your database connections and everything works wonderfully, you’re good to go.

If not, make sure your mySQL server is running and fix the mySQL socket alias by running these two commands in the Terminal:

sudo mkdir /var/mysql/
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Restart your webserver once again, and that should be it, really. Now, your Mac is a even better development environment than before!

Read on over at Apple’s bulletin board