Install and Configure lighttpd + PHP on Gentoo

Install lighttpd and php

  1. Read http://gentoo-wiki.com/HOWTO_Lighttpd and decide which USE flags you will need. Write those flags into /etc/portage/package.use. Since I plan to use fastcgi and php, I do have at least these two flags set.
  2. Check php installation. If php was installed but cgi USE flag was off, you have to reinstall php with "USE=cgi".
  3. Now install lighttpd:
    # emerge -v lighttpd
  4. Among the few opcode cache for php, xcache is quite stable on lighttpd. So install that:
    # emerge dev-php5/xcache

Configure lighttpd

  1. Add this line to  /etc/php/cgi-php5/php.ini
    cgi.fix_pathinfo=1
  2. Enable mod_redirect in /etc/lighttpd/lighttpd.conf, so that we can use url.redirect to redirect "hostname.com" to "www.hostname.com".
  3. Add virtual host setup to /etc/lighttpd/lighttpd.conf
  4. Restart /etc/init.d/lighttpd

Configure Xcache for php

The configuration file for xcache-php is in /etc/php/cgi-php5/ext/xcache.ini

Reference http://xcache.lighttpd.net/wiki/XcacheIni for the changing the values in xcache.ini.

On my server that has dual-xeon, I set xcache.count="5" (n+1 where n is the number of processors) to take advantage of the Splitted Cache feature.

Reference: