Source of: /manual/en/install.unix.lighttpd-14.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/install.unix.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'install.unix.lighttpd-14.php',
1 => 'Lighttpd 1.4 on Unix systems',
),
'up' =>
array (
0 => 'install.unix.php',
1 => 'Installation on Unix systems',
),
'prev' =>
array (
0 => 'install.unix.apache2.php',
1 => 'Apache 2.x on Unix systems',
),
'next' =>
array (
0 => 'install.unix.caudium.php',
1 => 'Caudium',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="install.unix.lighttpd-14" class="sect1">
<h2 class="title">Lighttpd 1.4 on Unix systems</h2>
<p class="para">
This section contains notes and hints specific to Lighttpd 1.4 installs
of PHP on Unix systems.
</p>
<p class="para">
Please use the <a href="http://trac.lighttpd.net/trac/" class="link external">» Lighttpd trac</a>
to learn how to install Lighttpd properly before continuing.
</p>
<p class="para">
Fastcgi is the preferred SAPI to connect PHP and Lighttpd. Fastcgi is
automagically enabled in php-cgi in PHP 5.3, but for older versions configure
PHP with --enable-fastcgi. To confirm that PHP has fastcgi enabled,
<i>php -v</i> should contain <i>PHP 5.2.5 (cgi-fcgi)</i>
Before PHP 5.2.3, fastcgi was enabled on the php binary (there was no php-cgi).
</p>
<div id="install.unix.lighttpd-14.lighttpd-spawn" class="sect2">
<h3 class="title">Letting Lighttpd spawn php processes</h3>
<p class="para">
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.
</p>
<div class="example">
<p><b>Example #1 Partial lighttpd.conf</b></p>
<div class="example-contents screen">
<div class="cdata"><pre>
server.modules += ( "mod_fastcgi" )
fastcgi.server = ( ".php" =>
((
"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
))
)
</pre></div>
</div>
</div>
<p class="para">
The bin-path directive allows lighttpd to spawn fastcgi processes dynamically.
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).
</p>
</div>
<div id="install.unix.lighttpd-14.spawn-fcgi" class="sect2">
<h3 class="title">Spawning with spawn-fcgi</h3>
<p class="para">
Lighttpd provides a program called spawn-fcgi to ease the process of
spawning fastcgi processes easier.
</p>
</div>
<div id="install.unix.lighttpd-14.spawn-php" class="sect2">
<h3 class="title">Spawning php-cgi</h3>
<p class="para">
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.
</p>
<div class="example">
<p><b>Example #2 Spawning FastCGI Responders</b></p>
<div class="example-contents screen">
<div class="cdata"><pre>
#!/bin/sh
# Location of the php-cgi binary
PHP=/usr/local/bin/php-cgi
# PID File location
PHP_PID=/tmp/php.pid
# Binding to an address
#FCGI_BIND_ADDRESS=10.0.1.1:10000
# Binding to a domain socket
FCGI_BIND_ADDRESS=/tmp/php.sock
PHP_FCGI_CHILDREN=16
PHP_FCGI_MAX_REQUESTS=10000
env -i PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN \
PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS \
$PHP -b $FCGI_BIND_ADDRESS &
echo $! > "$PHP_PID"
</pre></div>
</div>
</div>
</div>
<div id="install.unix.lighttpd-14.remote-fcgi" class="sect2">
<h3 class="title">Connecting to remote FCGI instances</h3>
<p class="para">
Fastcgi instances can be spawned on multiple remote machines in order to
scale applications.
</p>
<div class="example">
<p><b>Example #3 Connecting to remote php-fastcgi instances</b></p>
<div class="example-contents screen">
<div class="cdata"><pre>
fastcgi.server = ( ".php" =>
(( "host" => "10.0.0.2", "port" => 1030 ),
( "host" => "10.0.0.3", "port" => 1030 ))
)
</pre></div>
</div>
</div>
</div>
</div><?php manual_footer(); ?>