Apache vs. Lighttpd on PHP

Posted by Jetlogs @ 10:30 pm
Category: PHP, Technology

Let me share with you my research on the web about the advantages and disadvantages of Lighttpd vs. Apache, and how it might possible affect your applications ins PHP. The following article is a compilation of what I have found on different sites on the net.

Lighttpd or “Lighty” is a lightweight webserver made with speed and load balancing in mind, Unlike Apache which comes with a lot of modules that consumes a lot of server resources. One of the features of Lighttpd is that it is an event-driven web server. It uses select/poll/epoll/kqueue from a single process/thread.

Now for the Pros and Cons:

Pros:

  • Compared to Apache, it has a smaller CPU and memory usage. Since Lighttpd uses fewer resources per request than Apache alone, it can generally serve most static content faster than Apache.
  • Lighttpd has a better load-balancing than Apache
  • Lighttpd has easier configuration options compared to Apache
  • Lighttpd is recommended for static content, or dynamic content that is cached as a static page.
  • PHP has a better performance under Lighty due to its FastCGI module (which has its own disadvantage. see below)
  • Because of its FastCGI module, the server and application processes can be restarted independently which is important for busy websites
  • Also because of the FastCGI module, per-application security policies can be implemented
  • Cons:

  • Lighttpd doesn’t have support for .htaccess files which might break current security / functionality implementations for some of your applications (i.e. HTTP authentication)
  • Using Lighttpd will only support PHP running under FastCGI as opposed to running it as a module (mod_php) which might have additional implications for the application and server (PEAR modules won’t work under FastCGI)
  • Lighttpd has some problems processing request headers (specifically CR anf LF) from browsers like Opera. For example, Opera under SSL will hang under Lighttpd.
  • Lighttpd is incompatible with Apache modules (i.e. mod_security), and has its own module repository. Lighttpd has a smaller module repository compared to apache, and has a limited community which might become a problem when needing support.
  • Lighttpd doesn’t support some control panel applications like cPanel or Plesk and will require special configurations to run them
  • Given these Pros and Cons, its really hard to decide when to do a switch to Lighty. But as a basic rule, for server only serving mostly static content, Lighty is the better choice since it lesser overhead than Apache. Youtube’s video servers which serves static content runs on Lighty.

    However, if you are on the fringe case wherein you need Apache’s functionality, but lacking on server resources, and an upgrade is not a viable option, there is some good news for you. Lighttpd can be run behind Apache via Apache’s proxy module. Instructions on doing this can be found on this article:

    Running Lighttpd through Apache’s proxy module

    So what does this basically mean? In short, we can let Apache handle the dynamic content, while we let Lighty handle the static content from a server.

    Related links:

  • Official Lighttpd Website
  • Official Apache Website
  • Official FastCGI Website

  • 2 Comments »

    2 Comments to “Apache vs. Lighttpd on PHP”

    1. Angelo Mandato
      1

      I currently use Lighty (lighttpd) for serving static files and proxy requests for PHP scripts to Apache for a few of the web sites I manage. I am now investigating the possibility of using Lighttpd for PHP as well. I’ve found this post to be very informative.

      I wanted to know more information about the PEAR module problems with FastCGI and Lighty. I’ve read that others have successfully setup Lighttpd with php-fcgi to run Horde-imp. Since IMP Webmail uses many PEAR modules, I wonder which PEAR modules don’t work with a Lighty-PHP-FastCGI configuration?

      Thanks again for a very informative post,
      Angelo

    2. Geoffrey Lee
      2

      Where does it say that PEAR won’t work with PHP under FastCGI? I did a quick search on “PEAR FastCGI” and couldn’t find any references.

      Also, Lighttpd now has a work-around for the Opera bug as of version 1.4.12. http://trac.lighttpd.net/trac/ticket/579

    RSS Comment Feed Comments RSS |trackback TrackBack URI

    Leave a comment

  • Archives

  • Donations

  • Social Bookmarks

  • Jetlogs.org
    Some Rights Reserved 2007
    Creative Commons License