downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

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">&raquo; 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 += ( &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 bin-path directive allows lighttpd to spawn fastcgi processes dynamically.
   PHP will spawn children according to the PHP_FCGI_CHILDREN environment
   variable.  The &quot;bin-environment&quot; 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
   &quot;min-procs&quot; and &quot;max-procs&quot; 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 &quot;min-procs&quot; 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&#039;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 &amp;

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

</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 = ( &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(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites