Configure PHP with lighttpd using fastcgi
From TekPedia
[edit] Installing PHP
lighttpd is know to be a light and fast server, but you dont appreciate it until you combine php with fastcgi
this is a oriented for Gentoo Linux, but its easy to adapt it to another distros.
before emerging php, make sure that you have enabled the flag fastcgi and the -apache and -apache2 choose the others as you wish or need.
you can enable individual use flags on the file /etc/portage/package.use with the syntax category/package flag1 flag2
dev-lang/php-5.1.4 use flags:
USE="bcmath berkdb calendar cdb cgi cli crypt ctype dbase force-cgi-redirect ftp gd imap ipv6 ldap memlimit mysql mysqli ncurses nls pcntl pcre pdo-external pic posix postgres readline reflection sasl session sharedmem soap sockets spl sqlite ssl truetype xml xmlrpc zlib -adabas -apache -apache2 birdstep bzip2 cjk curl curlwrappers db2 dbmaker debug -discard-path -doc -empress -empress-bcs -esoob -exif -fastbuild -fdftk -filepro -firebird -flatfile -frontbase -gd-external -gdbm -gmp -hardenedphp -hash -hyperwave-api -iconv -informix -inifile -interbase -iodbc -java-external -kerberos -libedit -mcve -mhash -ming -msql -mssql -oci8 -oci8-instant-client -odbc -pdo -qdbm -recode -sapdb -sharedext -simplexml -snmp -solid -spell -sybase -sybase-ct -sysvipc -threads -tidy -tokenizer -unicode -vm-goto -vm-switch -wddx -xmlreader -xmlwriter -xpm -xsl -yaz -zip"
now emerge it and go get a coffee as it could take a while
emerge dev-lang/php
[edit] Configuring lighttpd
after php compiles successfully lets edit the lighttpd.conf file, first make sure that the module fastcgi is uncommented at the server modules:
server.modules = ( "mod_fastcgi", "mod_access", "mod_accesslog" )
and then uncomment or include the fastcgi configuration file:
include "mod_fastcgi.conf"
that is just to make the configuration file more clear to the reader, the fastcgi configuration could be included at lighttpd.conf without problems.
now lets edit the mod_fastcgi.conf file, you could use the following configuration as example
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/lib/php5/bin/php-cgi",
"min-procs" => 2,
"max-procs" => 4,
"max-load-per-proc" => 8,
"idle-timeout" => 50,
# Fix PATH_INFO for PHP scripts that rely on it (like Wordpress).
"broken-scriptfilename" => "enable"
)
)
)
its very important, and more for us that are on a limited memory enviroment, to control the min and max proc variable, as it will burn more or less memory depending on how many procs we set, on a small site the it could be set at 2 or even 1 without problems, making lighttpd run with very low memory, but if you're going to use more populated applications, like a forum, feel free to edit it with your needs.
another alternative to starting the fastcgi within lighttpd, is using fastcg with a different init script, for that you just need to delete the line of bin-path, and make sure that you start the service /etc/init.d/spawn-fcgi everytime you start lighttpd too, everything else remains the same.
now you are set, restart the and enjoy your fast server
/etc/init.d/lighttpd restart
