Lighttpd 1.4 on Unix systems This section contains notes and hints specific to Lighttpd 1.4 installs of PHP on Unix systems. You are highly encouraged to take a look at the Lighttpd trac to get a basic understanding of the lighttpd server. Use the install instructions there before continuing. Fastcgi is the preferred SAPI to connect PHP and Lighttpd. Fastcgi is automagically enabled in php-cgi in PHP5.3, but for older versions configure php with --enable-fastcgi. To confirm that PHP has fastcgi enabled, php -v should contain PHP 5.2.5 (cgi-fcgi) Before PHP 5.2.3, fastcgi was enabled on the php binary (there was no php-cgi). Letting Lighttpd spawn your processes To configure Lighttpd to connect to php and spawn fastcgi processes, edit lighttpd.conf. Sockets are preferred to connect to fastcgi processes on the local system. Partial lighttpd.conf (( "socket" => "/tmp/php.socket", "bin-path" => "/usr/local/bin/php-cgi", "bin-environment" => ( "PHP_FCGI_CHILDREN" => "16", "PHP_FCGI_MAX_REQUESTS" => "10000" ) "min-procs" => 1, "max-procs" => 1, "idle-timeout" => 20 )) ) ]]> The bin-path directive allows lighttpd to spawn fastcgi processes for you. PHP will spawn children according to the PHP_FCGI_CHILDREN environment variable. The "bin-environment" directive sets the environment for the spawned processes. PHP will kill a child process after the number of requests specified by PHP_FCGI_MAX_REQUESTS is reached. The directives "min-procs" and "max-procs" should generally be avoided with PHP. PHP manages its own children and opcode caches like APC will only share among children managed by PHP. If "min-procs" is set to something greater than 1, the total number of php responders will be multiplied PHP_FCGI_CHILDREN (2 min-procs * 16 children gives 32 responders). Spawning with spawn-fcgi Lighttpd provides a program called spawn-fcgi to ease the process of spawning fastcgi processes easier. Spawning php-cgi It is possible to spawn processes without spawn-fcgi, though a bit of heavy-lifting is required. Setting the PHP_FCGI_CHILDREN environment var controls how many children PHP will spawn to handle incoming requests. Setting PHP_FCGI_MAX_REQUESTS will determine how long (in requests) each child will live. Here's a simple bash script to help spawn php responders. Spawning FastCGI Responders "$PHP_PID" ]]> Connecting to remote FCGI instances Fastcgi instances can be spawned on multiple remote machines in order to scale applications. Connecting to remote php-fastcgi instances (( "host" => "10.0.0.2", "port" => 1030 ), ( "host" => "10.0.0.3", "port" => 1030 )) ) ]]>