Posts Tagged ‘lighttpd’

Installing WordPress on a Debian box, with lighttpd serving up the goods

Wednesday, February 4th, 2009

Apache users can simply install the Debian wordpress package.  lighttpd users can’t do this because Apache is one of the wordpress package dependencies.

1 – Install MySQL

According to the WordPress developers, moves are being made to port WordPress to PostgreSQL (and the sooner the better) but for the time being we have to make do with MySQL, memory hog that it is:

# apt-get install mysql-server-5.0

Important tip:  Don’t install the meta-package mysql-server if you don’t want your MySQL installation automatically upgraded when you run apt-get upgrade at some point in the future.  (You can of course delete mysql-server after it’s pulled in the latest version but then apt-get autoremove will include your MySQL installation in its list of packages which were automatically installed and are no longer required).

2 – Create a MySQL database for your WordPress blog

The easiest way to do this is with the MySQL client, called simply mysql.

# mysql -u adminusername -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 5340 to server version: 3.23.54
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> CREATE DATABASE databasename;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON databasename.*
-> TO "wordpressusername"@"hostname"
-> IDENTIFIED BY "password";
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> EXIT Bye
#
3 – Install PHP

There are three server-side versions of the PHP5 interpreter available as Debian packages.  We only want the ‘CGI’ version (and the MySQL PHP module).

# apt-get install php5-cgi php5-mysql
4 – Grab a copy of WordPress and configure it

Install Subversion if necessary (apt-get install subversion), cd to the document root of your website and run the command:

# svn co http://svn.automattic.com/wordpress/tags/2.7 wordpress

Make the sample config file your actual config file:

# mv wordpress/wp-config-sample.php wordpress/wp-config.php

Edit the database section of wp-config.php to reflect your choices in step 2.

5 – Configure lighttpd

Open /etc/lighttpd.conf and ensure the following lines are included:

server.modules += ( "mod_cgi" )
$HTTP["url"] =~ "^/wordpress/" { 
  cgi.assign = ( ".php" => "/usr/bin/php-cgi" )
}

This tells lighttpd to treat the wordpress subdirectory of your document root as a CGI executable directory.

If you want to hide the wordpress subdirectory in your blog’s URLs, ensure the following lines are included in your /etc/lighttpd.conf as well:

server.modules += ( "mod_rewrite" )
$HTTP["host"] =~ "^example.org$" {
  url.rewrite-once = ( "^/(.*)" => "/wordpress/$1" )
}

If there are some files or directories under your document root for which page requests shouldn’t be rewritten, alter the url.rewrite-once line above as in this example:

url.rewrite-once = ( "^/((?!(sitemap.xml$|robots.txt$|images/)).*)"
                     => "/wordpress/$1" )

And while we’re at it, and assuming your DNS records are set up appropriately, why not dispense with the visionary, but entirely unnecessary www in page requests that include it?

server.modules += ( "mod_redirect" )
$HTTP["host"] =~ "^www.example.org$" {
  url.redirect = ( "^/(.*)" => "http://example.org/$1" )
}

Don’t forget to restart lighttpd after making your changes:

# /etc/init.d/lighttpd restart
6 – Complete the installation

Visit http://example.org/wp-admin/install.php in your browser (or http://example.org/wordpress/wp-admin/install.php if you’ve chosen not to hide the wordpress subdirectory as described above), give your blog a title, enter an email address and login.

 

Hope this helps.  Feel free to comment on what you have read.