<?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 => 'zh',
  ),
  'this' => 
  array (
    0 => 'install.unix.lighttpd-14.php',
    1 => 'Unix 平台的 Lighttpd 1.4',
    2 => 'Unix 平台的 Lighttpd 1.4',
  ),
  'up' => 
  array (
    0 => 'install.unix.php',
    1 => '在 Unix 系统上安装 PHP',
  ),
  'prev' => 
  array (
    0 => 'install.unix.nginx.php',
    1 => 'Unix 系统下的 Nginx 1.4.x',
  ),
  'next' => 
  array (
    0 => 'install.unix.litespeed.php',
    1 => 'Unix 系统下的 LiteSpeed、OpenLiteSpeed Web 服务器',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    '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">Unix 平台的 Lighttpd 1.4</h2>

 <p class="para">
  本节包括在 Unix 平台的 Lighttpd 1.4 下安装 PHP 的说明和提示。 
 </p>

 <p class="para">
  推荐阅读 <a href="http://trac.lighttpd.net/trac/" class="link external">&raquo;&nbsp;Lighttpd trac</a>
  了解一下正确安装 Lighttpd 然后继续。 
 </p>
 
 <p class="para">
  推荐使用 FastCGI 作为 SAPI 模块来连接 PHP 和 Lighttpd。
  在 php-cgi 中自动启用 FastCGI。
 </p>
 
 <div class="sect2" id="install.unix.lighttpd-14.lighttpd-spawn">
  <h3 class="title">使 Lighttpd 产生 php 进程</h3>

  <p class="para">
   要配置 Lighttpd 连接到 PHP 并产生 FastCGI 进程，
   编辑 <var class="filename">lighttpd.conf</var>。
   推荐使用套接字在本机连接 FastCGI 进程。
  </p>

  <div class="example" id="example-1">
   <p><strong>示例 #1 部分 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">
   <var class="filename">bin-path</var> 指令允许 lighttpd 动态产生 FastCGI 进程。PHP
   会根据 <var class="envar">PHP_FCGI_CHILDREN</var>
   环境变量产生子进程。<code class="literal">bin-environment</code> 指令设定了所产生的进行的环境。PHP
   会在达到 <var class="envar">PHP_FCGI_MAX_REQUESTS</var> 所指定的请求数目之后杀死一个子进程。在
   PHP 中通常应避免 <code class="literal">min-procs</code> 和 <code class="literal">max-procs</code> 指令。PHP
   自己管理其子进程，并且例如 APC 之类的 opcode 缓存仅在 PHP
   管理下的子进程之间共享。如果 <code class="literal">min-procs</code> 被设定成某个大于 <code class="literal">1</code>
   的值，则 PHP 应答器的总数目为该值乘以 <var class="envar">PHP_FCGI_CHILDREN</var>（如 min-procs 为
   2，PHP_FCGI_CHILDREN 为 16 则会产生 32 个应答器）。
  </p>
 </div>

 <div class="sect2" id="install.unix.lighttpd-14.spawn-fcgi">
  <h3 class="title">通过 spawn-fcgi 产生进程</h3>  

  <p class="para">
   Lighttpd 提供一个名为 spawn-fcgi 的程序来简化产生 FastCGI 进程的手续。
  </p>
 </div>

 

 <div class="sect2" id="install.unix.lighttpd-14.spawn-php">
  <h3 class="title">产生 php-cgi</h3>

  <p class="para">
   有可能不通过 spawn-fcgi 来产生进程，但需要做些工作。设定
   <var class="envar">PHP_FCGI_CHILDREN</var> 环境变量控制了 PHP 产生多少个子进程来处理请求。设定
   <var class="envar">PHP_FCGI_MAX_REQUESTS</var> 将决定每个子进程存活多久（以请求数目决定）。
   以下为一个简单的 bash 脚本来帮助产生 php 应答器。
  </p>
     
  <div class="example" id="example-2">
   <p><strong>示例 #2 产生 FastCGI 应答器</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">连接远程 FCGI 实例</h3>

  <p class="para">
   FastCGI 实例可被产生于多个远程机器以分散应用程序。
  </p>
   
  <div class="example" id="example-3">
   <p><strong>示例 #3 连接远程 php-fastcgi 实例</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); ?>