<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = 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',
    2 => 'Lighttpd 1.4 on Unix systems',
  ),
  'up' => 
  array (
    0 => 'install.unix.php',
    1 => 'Installation on Unix systems',
  ),
  'prev' => 
  array (
    0 => 'install.unix.nginx.php',
    1 => 'Nginx 1.4.x on Unix systems',
  ),
  'next' => 
  array (
    0 => 'install.unix.litespeed.php',
    1 => 'LiteSpeed Web Server/OpenLiteSpeed Web Server on Unix systems',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'install/unix/lighttpd-14.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<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">&raquo;&nbsp;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.
 </p>
 
 <div class="sect2" id="install.unix.lighttpd-14.lighttpd-spawn">
  <h3 class="title">Letting Lighttpd spawn php processes</h3>

  <p class="para">
   To configure Lighttpd to connect to PHP and spawn FastCGI processes, edit
   <var class="filename">lighttpd.conf</var>. Sockets are preferred to connect to FastCGI processes on
   the local system.
  </p>

  <div class="example" id="example-1">
   <p><strong>Example #1 Partial lighttpd.conf</strong></p>
   <div class="example-contents screen">
<div class="cdata"><pre>
server.modules += ( &quot;mod_fastcgi&quot; )

fastcgi.server = ( &quot;.php&quot; =&gt;
  ((
    &quot;socket&quot; =&gt; &quot;/tmp/php.socket&quot;,
    &quot;bin-path&quot; =&gt; &quot;/usr/local/bin/php-cgi&quot;,
    &quot;bin-environment&quot; =&gt; (
      &quot;PHP_FCGI_CHILDREN&quot; =&gt; &quot;16&quot;,
      &quot;PHP_FCGI_MAX_REQUESTS&quot; =&gt; &quot;10000&quot;
    ),
    &quot;min-procs&quot; =&gt; 1,
    &quot;max-procs&quot; =&gt; 1,
    &quot;idle-timeout&quot; =&gt; 20
  ))
)
</pre></div>

   </div>
  </div>

  <p class="para">
   The <var class="filename">bin-path</var> directive allows lighttpd to spawn FastCGI processes dynamically.
   PHP will spawn children according to the <var class="envar">PHP_FCGI_CHILDREN</var> environment
   variable. The <code class="literal">bin-environment</code> directive sets the environment for the
   spawned processes. PHP will kill a child process after the number of
   requests specified by <var class="envar">PHP_FCGI_MAX_REQUESTS</var> is reached. The directives
   <code class="literal">min-procs</code> and <code class="literal">max-procs</code> 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 <code class="literal">min-procs</code> is set to something greater than <code class="literal">1</code>,
   the total number of php responders will be multiplied <var class="envar">PHP_FCGI_CHILDREN</var>
   (2 min-procs * 16 children gives 32 responders).
  </p>
 </div>

 <div class="sect2" id="install.unix.lighttpd-14.spawn-fcgi">
  <h3 class="title">Spawning with spawn-fcgi</h3>  

  <p class="para">
   Lighttpd provides a program called spawn-fcgi to make the process of
   spawning FastCGI processes easier.
  </p>
 </div>

 <div class="sect2" id="install.unix.lighttpd-14.spawn-php">
  <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 <var class="envar">PHP_FCGI_CHILDREN</var> environment var
   controls how many children PHP will spawn to handle incoming requests.
   Setting <var class="envar">PHP_FCGI_MAX_REQUESTS</var> will determine how long (in requests) each
   child will live. Here&#039;s a simple bash script to help spawn php responders.
  </p>
     
  <div class="example" id="example-2">
   <p><strong>Example #2 Spawning FastCGI Responders</strong></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 &amp;

echo $! &gt; &quot;$PHP_PID&quot;

</pre></div>
   </div>
  </div>
 </div>

 <div class="sect2" id="install.unix.lighttpd-14.remote-fcgi">
  <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" id="example-3">
   <p><strong>Example #3 Connecting to remote php-fastcgi instances</strong></p>
   <div class="example-contents screen">
<div class="cdata"><pre>
fastcgi.server = ( &quot;.php&quot; =&gt;
   (( &quot;host&quot; =&gt; &quot;10.0.0.2&quot;, &quot;port&quot; =&gt; 1030 ),
    ( &quot;host&quot; =&gt; &quot;10.0.0.3&quot;, &quot;port&quot; =&gt; 1030 ))
)
</pre></div>
   </div>
  </div>
 </div>
</div><?php manual_footer($setup); ?>