Both Apache 2.2 and PHP 5 come with every installation of Mac OS X 10.5 Leopard. MySQL does not. There are a couple of tricks for installing and/or turning them on –and thereby attaining Development Happiness.
Here’s how we configure our development machines at the studio, where our PHP work is primarily Drupal and we use several virtual hosts.
Not hard, but a little long for this post. Take a look at our instructions for installing MySQL on Leopard.
Configure Apache for PHP and Virtual Hosts
Though Leopard ships with PHP, it’s not turned on by default. Let’s change that, and also turn on the virtual hosts that we’ll use for our various Drupal installs.
- Edit Apache’s configuration file to make the following two changes:
sudo vi /etc/apache2/httpd.conf
- Uncomment line 114 so it looks like this:
LoadModule php5_module libexec/apache2/libphp5.so
- Uncomment line 461 so it looks like this:
Add your Virtual Hosts
/etc/apache2/extra/httpd-vhosts.conf to add your configuration. See our sample configuration for ideas.
NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin eric@localhost DocumentRoot "/Users/eric/Sites/agc" ServerName agc.local RewriteLog /private/var/log/apache2/rewrite_log RewriteLogLevel 0 </VirtualHost>
A couple items of note:
- For development, we put our virtual hosts under users’
~/Sitesfolder. That way there are no permissions issues to prevent Apache from serving the code – or from deploying fresh.
- You’ll also have to put agc.local into DNS.
Add the new virtual hostnames to /etc/hosts
/etc/hosts to add a couple of nicknames for localhost:
127.0.0.1 localhost agc.local giving.local givingedit.local miyo.local
- Start System Preferences from the Apple menu.
- Go to the Sharing tab
- Click the checkbox by “Web Sharing”
Done. Let’s test everything by starting Safari and visiting http://agc.local