Henrik SjökvistNotebook

Setting up a Drupal development environment with lighttpd in Mac OS X

After upgrading to Leopard I finally got fed up with MAMP. I had used it for development for quite a while, but found it dog slow and never got the GUI tools to work right under 10.5. I had been using lighttpd on servers and decided to give it a go on my MacBook Pro. It runs superbly.

This setup requires MacPorts, a package management system in the Linux style. Everything you install through MacPorts lives in /opt and does not tamper with your existing OS X installation.

Install MacPorts

Download and install MacPorts. It requires that Apple's Xcode package is installed. Verify that you are using the latest version in Terminal:

sudo port selfupdate

If you do not have a ~/.profile file, create one and add the MacPorts paths. Close and reopen Terminal for the change to take effect:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

Install and configure lighttpd and PHP

I used the CML version of lighttpd for URL rewriting, so Lua is required:

sudo port install lua && sudo port install lighttpd +cml

This compiles the packages from source, so it takes a while.

Set up lighttpd.conf

Copy the configuration template:

cd /opt/local/etc/lighttpd/
sudo cp lighttpd.conf.default lighttpd.conf

Edit lighttpd.conf and enable mod_magnet and mod_fastcgi in the server.modules section. Enable PHP with FastCGI by adding a server block below that section. The exact setting names are listed in the lighttpd documentation.

Set the site directory and add a virtual host. My site lived in a Sites folder under my home directory, and the host name was mydrupalsite.

lighttpd does not support Apache's mod_rewrite syntax, so the .htaccess file that Drupal ships with does not help. I used a small Lua script for clean URLs. The script checks whether the requested path exists and, if it does not, sends the request to index.php with the original query string. The lighttpd documentation explains the functions used in the script.

Add the hostname

Add the hostname to /etc/hosts:

127.0.0.1       mydrupalsite

The default log directory may be outside /opt, so create it if it does not exist:

sudo mkdir /var/log/lighttpd

Make lighttpd start at boot and start it now:

sudo launchctl load /Library/LaunchDaemons/org.macports.lighttpd.plist
sudo launchctl start org.macports.lighttpd

If lighttpd fails to start, run it directly with the configuration file in the foreground and read the error message. A typo in the configuration is the usual cause.

Install MySQL

sudo port install mysql5 +server

Install the system tables and make MySQL start at boot:

sudo mysql_install_db5
sudo launchctl load /Library/LaunchDaemons/org.macports.mysql5.plist
sudo launchctl start org.macports.mysql5

Log in, secure the initial accounts, and create the Drupal database. See MySQL for the details.

Install PHP

PHP 5 came with Leopard, but the Apple build lacked GD support and I needed the FastCGI version too:

sudo port install php5 +fastcgi +mysql5

Create the socket directory defined in lighttpd.conf:

sudo mkdir /opt/local/var/run/php5

Install Drupal

Install Drupal in /Users/yourname/Sites/mydrupalsite/. Open http://mydrupalsite/ in a browser. To add another virtual server, duplicate the host entry in lighttpd.conf, give it a new hostname and path, and add the hostname to /etc/hosts.

Install phpMyAdmin

sudo port install phpmyadmin

Add it as a virtual host in lighttpd.conf. Add the hostname to /etc/hosts, copy the sample configuration, and set a blowfish_secret value:

127.0.0.1       phpmyadmin
sudo cp /opt/local/www/phpmyadmin/config.sample.inc.php /opt/local/www/phpmyadmin/config.inc.php

Restart lighttpd, then open http://phpmyadmin/. See phpMyAdmin for the browser client.

An AppleScript for restarts

I created a small AppleScript that restarts lighttpd and MySQL. Paste this into Script Editor, save it as an application, and add it to the dock:

do shell script "sudo launchctl stop org.macports.lighttpd && sudo launchctl start org.macports.lighttpd && sudo launchctl stop org.macports.mysql5 && sudo launchctl start org.macports.mysql5" with administrator privileges

See Apple for Leopard and Xcode.

Comments are closed. If a post needs a reply, use the contact form.

Search the notebook

Try Drupal, Safari or Markdown.

Press Escape to close. Press / anywhere to open search.