Configuring lighttpd for python

Yesterday I was determined to get lighttpd configured for python. When I did a search I got results that talked about hooking it through fastcgi and having a script start up the python process on a certain port etc...

I ended up looking around for hours and could not get it to work.

I finally consulted a well configured server for a client and discovered how they do it.. and if I had known ahead of time.. I could have had it done in about 10 seconds.

I thought I'd share so others could avoid the endless searching which brought me frustration.

As it turns out fastcgi is not needed at all for python to work hand in hand with lighttp. Lighttpd just needs to have the cgi module enabled. So on my Ubuntu 8.04 box in /etc/lighttpd/conf-enabled/ I sym link back to /etc/lighttpd/conf-available/10-cgi.conf . That enables the cgi module in lighttpd.

If you look inside that file you'll see a few items.. but of note is this:

cgi.assign = (
".pl" => "/usr/bin/perl",
".php" => "/usr/bin/php-cgi",
".py" => "/usr/bin/python",

That is where it ties in requests for python (py) files with the python interpreter. It also allows php and perl to use the same methodology.

After validating the paths are routed properly you should be able to restart lighttpd and be off and running with python.

Good luck!