After several years of tinkering with my Drupal deployment stack, I’ve finally found one that I think is both stable and performant. There is usually a trade-off between the two, but not anymore.

Debian Setup

My stack starts with the latest version of Debian Etch. Both Slicehost and RimuHosting provide these as an OS choice for their VPS plans.

Now, some people will only use packages from the stable repositories on Debian. If you’re one of those people, you can still follow the majority of this tutorial. However, you will need to skip the part about updating sources.list and you also won’t be able to install the php5-xcache package using apt (as of this post its still only available in test). You will still be able to download and build XCache from source, but I won’t be going over that here.

From my own experience, I’ve found that the packages in test are “stable enough”. Of the small bugs that do get into test, I haven’t ran into them, nor (as of this post) are there any bugs in test that effect the packages we’ll be installing here.

So, first thing we’ll do is edit our sources.list file to include the testing repository if you haven’t already done so. nano /etc/apt/sources.list

Then add the following line to the bottom of the file: deb testing main contrib non-free

Save the file and then run: sudo apt-get update

This will update your packages list to include the packages from test. Once that is complete we’re ready to begin installing the required packages needed to run Drupal with Lighttpd. Run the following: sudo apt-get install lighttpd lighttpd-mod-magnet php5-cgi php5-curl php5-gd php5-mysql php5-xcache mysql-server

If you already have MySQL installed you can skip it in the package list above. Also, if you are not using the test repositories you will not be able to install php5-xcache, so omit it.

If you previously had Apache installed, its no longer needed, so we can remove it with: sudo apt-get remove apache2

PHP Setup

In order to use php5-cgi with lighttpd, we will need to modify one setting in the php.ini file. nano /etc/php5/cgi/php.ini

Search for “cgi.fix_pathinfo” and change its value to 1. If its not there add it: cgi.fix_pathinfo = 1

Drupal Setup

Before we configure lighttpd, let’s download the latest version of Drupal and get it ready to go. cd /var/www curl -O tar -xzvf drupal-5.3.tar.gz mv drupal-5.3 drupal cd drupal chown www-data:www-data files chown www-data:www-data sites/default/settings.php

You’ll notice in the last two lines of code we give the www-data user ownership of the files directory and the default settings.php. Drupal will change the permissions on the settings file back after installation is complete. Drupal needs write access to the files directory to handle uploads, so this setting stays.

Database Setup

Now you need to create the database for your drupal site. mysql -u username -p [enter password] create database drupal; GRANT ALL PRIVILEGES ON drupal.* TO someuser@localhost IDENTIFIED BY 'somepassword';

Replace “someuser” and “somepassword” with a username and password of your choice.

Lighttpd Configuration

Now that Drupal is ready to be installed, lets finish configuring lighttpd. Download my lighty_conf tar to your /etc/lighttpd directory and extract it cd /etc/lighttpd curl -O tar -xzvf lighty_conf.tar.gz mv lighty_conf/drupal.lua . mv lighty_conf/lighttpd.conf . mkdir -R /var/tmp/lighttpd/cache/compress

Thanks to nordisch by nature and this post for the drupal.lua file that makes clean URLs possible.

The important things to note about lighttpd.conf are:

  1. Ensure mod_fastcgi and mod_magnet are enabled
  2. Make sure you set your document-root to /var/www/drupal (or wherever you extracted your drupal install too)
  3. You will need the magnet.attract line to make sure clean urls work with Drupal
  4. Ensure the compression directory is created - lighttpd will not start correctly if its not there
  5. Depending on the resources you have avilable to you, you may need to adjust fastcgi.server settings, specifically min-procs and max-procs to avoid swapping

At this point we’re ready to restart Lighty (make sure that if you haven’t uninstalled Apache, that you’ve at least stopped it) /etc/init.d/lighttpd restart

Now you should be able to navigate to your site, install your Database and create the first user. Your site should be in a usable state.

XCache Configuration

XCache is a PHP opcode cacher that significantly boosts the performance of your PHP scripts by caching them in a pre-compiled state in your server’s memory.

If you installed the php5-xcache package above, all you need to do to enable it is edit /etc/php5/cgi/conf.d/xcache.ini. Change xcache.size to anything greater than zero. I’ve set mine at 64M. Also, if you have a multi-core processor, run cat /proc/cpuinfo |grep -c processor and use that as the value for xcache.count. Once you’ve updated this file, restart Lighttpd and you’re all set.

You should now have a fast stable Drupal installation ready for loads of traffic!