Wednesday February 09, 2005
UPDATE: Lighttpd 1.3.11 has been released, which includes my patch for osx, I’ve updated this post to reflect this, since the patching step is no longer needed.
There’s been a lot of buzz in the Ruby on Rails community lately about lighttpd which claims to be a lightweight, secure and a friggin’ fast http server. And guess what? It most certainly is!
Below are my notes of getting lighttpd 1.3.10 up and running on Mac OSX 10.3 with mod_mysql_vhost and mod_fastcgi. Please note that the patch and symlinking of libmysql may or may not be needed in future versions of lighttpd. Also note that the MySQL version used below is based on the ServerLogistics Complete MySQL package, if you’re using a different package or your own the paths may be different, do a
locate mysql_config to figure out where it is.
First of all we need the FastCGI developer kit:
curl -O http://fastcgi.com/dist/fcgi-2.4.0.tar.gz tar xzvf fcgi-2.4.0.tar.gz cd fcgi-2.4.0 ./configure make sudo make install
We also need the pcre libraries:
(cd ..) curl -O ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-5.0.tar.gz tar xzvf pcre-5.0.tar.gz cd pcre-5.0 ./configure make sudo make install
Then, we need to download and unpack the lighttpd tarball:
(cd ..) curl -O http://www.lighttpd.net/download/lighttpd-1.3.11.tar.gz tar -xzvf lighttpd-1.3.11.tar.gz cd lighttpd-1.3.11/
I wanted to be able to use the mod_mysql_vhost and since I’m using the ServerLogistics MySQL package, installed in
/Library/MySQL/ a bit of manual tinkering was requirred. The easiest was to create a symlink for the header files to
sudo ln -s /Library/MySQL/include/mysql /usr/local/include/mysql
Note: This probably isn’t really the optimal solution, but I didn’t really feel like poking around too much in the sources to correct the path problem
Next we need to run the configure script, telling it we want to use mysql for the vhosts:
If all is good you should see something like this once the configure script is done:
Plugins: mod_rewrite : enabled mod_redirect : enabled mod_ssi : enabled mod_cgi : enabled mod_fastcgi : enabled mod_proxy : enabled mod_evhost : enabled mod_simple_vhost: enabled mod_mysql_vhost : enabled mod_access : enabled mod_alias : enabled mod_setenv : enabled mod_usertrack : enabled mod_compress : enabled mod_auth : enabled mod_status : enabled mod_accesslog : enabled mod_rrdtool : enabled mod_secdownload : enabled mod_expire : enabled
And finally we compile and install the binaries:
make sudo make install
Hooray! We’ve successfully installed lighttpd, now we just need to take care of the config and log files and we’re good to go, start by copying the lighttpd.conf to /etc (I think that’s a good place to have it, you may disagree)
sudo cp doc/lighttpd.conf /etc/lighttpd.conf
Configuring the lighttpd.conf should be a breeze, it’s fairly self explanatory, also, please consult the documention
Now create and set the proper permissions on our two log files:
sudo touch /var/log/lighttpd.error.log sudo chmod 666 /var/log/lighttpd.error.log sudo touch /var/log/lighttpd.access.log sudo chmod 666 /var/log/lighttpd.access.log
Finally, we can start the lighttpd webserver and start having some fun with it:
sudo lighttpd -f /etc/lighttpd.conf
You may wish to add the
-D flag so it’ll keep running in the console, instead of as a daemon, to make it easier to shut down while you’re testing your config and such.
That’s it! You’re all set to go, using mysql based vhosts is fairly straingforward, just take a look at the documentation example to get an idea how to set it up.
If one where to speculate freely one could imagine that we set ourselves up a complete environment for developing Rails projects, using Rails. Perhaps I’ll even write an article about that in the future, until then; enjoy your lighttpd!