Switching from Apache CGI to Lighttpd FastCGI

Switching from Apache 2 and CGI to Lighttpd and FastCGI

I tripped over another httpd the other day that was advertised as being fast and efficient, which sounded interesting so I had a play with it on my linux server.

The short answer is that swapping from Apache2 to lighttpd and from CGI to FastCGI saved me something like 10Mb of RAM and about 30% of time per page impression.

This may not sound much, but I run all manner of crap on my Virtual Machine and every scrap of RAM counts because I’m too cheap to upgrade my VM’s resources.

I would publish some benchmarks but they really wouldn’t prove anything. Essentially, any modern software is going to perform adequately given enough hardware resources. This was an exercise in reducing memory footprint through efficiency rather than increasing the number of hits per second for the same resource allocation. If you’re running a site big enough to notice the performance increase from a different web server, chances are you’ve got a large IT crew to do your own benchmarks.

Installing the new setup was straightforward, the RPMs just worked, configuring PHP FastCGI was easy enough, although it did take me about half an hour before I’d caught all the different places that various applications had configured themselves into my apache installation. It’s quite nice having all the configuration in one place even though you do lose the flexibility of .htaccess.

Speaking of which, it was at this point I noticed that my wordpress installation was guilty of an almighty hack that I’d failed to notice. It seems that rather than doing some sort of cunning URL matching system, it just took over as my site’s default 404 handler, served up what it could (e.g. davstott.me.uk/feed) and defaulted to my index page (e.g. davstott.me.uk/pageThatDoesntExist) for what it couldn’t.

I’ve since reconfigured my wordpress such that its permalinks now include index.php and added a couple of rewriting rules so that feed bookmarks don’t break (yay for regexs). Sorry about the inconvenience.

It also reminded me to configure a low maximum for the number of concurrent requests that the httpd would serve, as it was entirely possible to swap my VM to death with as many as 10 simultaneous requests. That’s now set to two instances of PHP.

The bottom line is:
Lighttpd and FastCGI are both good m’kay, but only if you’ll notice the difference.