<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/configuration.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'configuration.file.php',
    1 => '配置文件',
    2 => '配置文件',
  ),
  'up' => 
  array (
    0 => 'configuration.php',
    1 => '运行时配置',
  ),
  'prev' => 
  array (
    0 => 'configuration.php',
    1 => '运行时配置',
  ),
  'next' => 
  array (
    0 => 'configuration.file.per-user.php',
    1 => '.user.ini 文件',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'install/ini.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="configuration.file" class="sect1">
  <h2 class="title">配置文件</h2>

  <p class="simpara">
   配置文件（<var class="filename">php.ini</var>）在 PHP 启动时被读取。对于服务器模块版本的 PHP，仅在 web
   服务器启动时读取一次。对于
   <abbr title="Common Gateway Interface">CGI</abbr> 和 <abbr title="Command Line Interpreter/Interface">CLI</abbr> 版本，每次调用都会读取。
  </p>
  <p class="para">
   <var class="filename">php.ini</var> 的搜索路径如下（按顺序）：
   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      SAPI 模块所指定的位置（Apache 2 中的 <code class="literal">PHPIniDir</code>
      指令，CGI 和 CLI 中的 <code class="literal">-c</code>
      命令行选项）。
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <var class="varname">PHPRC</var>  环境变量。
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      可以为不同版本的 PHP 指定不同的 <code class="literal">php.ini</code>
      文件位置。注册表目录所在的位置取决于你的系统是 32 位还是 64 位。32-bit
      的 PHP 运行在 32-bit 的系统或 64-bit 的 PHP 运行在 64-bit 系统时使用 <code class="literal">[(HKEY_LOCAL_MACHINE\SOFTWARE\PHP]</code>
      32-bit 的 PHP 运行在 64-bit 的系统上时，则使用 <code class="literal">[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\PHP]</code>] 替代。
      系统版本跟 PHP 版本架构一致时，会按以下顺序依次进行检查：
      <code class="literal">[HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z]</code>，
      <code class="literal">[HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y]</code> 和
      <code class="literal">[HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x]</code>，其中的
      x，y 和 z 指的是 PHP 主版本号，次版本号和发行批次。
      对于 32 bit 版本的 PHP 运行在 64 bit 系统上的情况，则会按以下顺序依次进行检查：
      <code class="literal">[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x.y.z]</code>，
      <code class="literal">[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x.y]</code> 和
      <code class="literal">[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x]</code>，其中的
      x，y 和 z 指的是 PHP 主版本号，次版本号和发行批次。如果在其中任何目录下的
      <code class="literal">IniFilePath</code> 有键值，则第一个值将被用作
      <code class="literal">php.ini</code> 的位置（仅适用于 Windows）。
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <code class="literal">[HKEY_LOCAL_MACHINE\SOFTWARE\PHP]</code> 内 <code class="literal">IniFilePath</code> 的值（Windows 注册表位置）。
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      当前工作目录（对于 CLI）。
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      web 服务器目录（对于 SAPI 模块）或 PHP 所在目录（Windows 下其它情况）。
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      Windows 目录（<var class="filename">C:\windows</var>
      或 <var class="filename">C:\winnt</var>），或
      <code class="literal">--with-config-file-path</code> 编译时选项指定的位置。
     </span>
    </li>
   </ul>
  </p>
  <p class="para">
   如果存在 <var class="filename">php-SAPI.ini</var>（SAPI 是当前所用的 SAPI
   名称，因此实际文件名为 <var class="filename">php-cli.ini</var> 或
   <var class="filename">php-apache.ini</var> 等），则会用它替代 <var class="filename">php.ini</var>。SAPI
   的名称可以用 <span class="function"><a href="function.php-sapi-name.php" class="function">php_sapi_name()</a></span> 来测定。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    Apache web 服务器在启动时会把目录转到根目录，这将导致 PHP 尝试在根目录下读取
    <var class="filename">php.ini</var>，如果存在的话。
   </p>
  </p></blockquote>
  <p class="simpara">
    可以在如下所示的 <var class="filename">php.ini</var> 配置值中引用环境变量。自 PHP 8.3.0 起，可以指定一个后备值，当引用的变量未定义时使用该值。
  </p>
  <div class="example" id="example-1">
   <p><strong>示例 #1 <var class="filename">php.ini</var> 中的环境变量</strong></p>
    <div class="example-contents">
<div class="inicode"><pre class="inicode">; PHP_MEMORY_LIMIT 来自于环境变量的值
memory_limit = ${PHP_MEMORY_LIMIT}
; 如果 PHP_MAX_EXECUTION_TIME 未定义，将回退到 30
max_execution_time = ${PHP_MAX_EXECUTION_TIME:-30}</pre>
</div>
   </div>

  </div>
  <p class="para">
   由扩展库处理的 <var class="filename">php.ini</var> 指令，其文档分别在各扩展库的页面。<a href="ini.php" class="link">内核配置选项</a>见附录。不过也许不是所有的 PHP
   指令都在手册中有文档说明。要得到自己的 PHP 版本中的配置指令完整列表，请阅读
   <var class="filename">php.ini</var> 文件，其中都有注释。此外，也许从 Git 得到的<a href="https://github.com/php/php-src/blob/master/php.ini-production" class="link external">&raquo;&nbsp;最新版 <var class="filename">php.ini</var></a> 也有帮助。
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>示例 #2 <var class="filename">php.ini</var> 示例</strong></p>
    <div class="example-contents">
<div class="inicode"><pre class="inicode">; any text on a line after an unquoted semicolon (;) is ignored
[php] ; section markers (text within square brackets) are also ignored
; Boolean values can be set to either:
;    true, on, yes
; or false, off, no, none
register_globals = off
track_errors = yes

; you can enclose strings in double-quotes
include_path = &quot;.:/usr/local/lib/php&quot;

; backslashes are treated the same as any other character
include_path = &quot;.;c:\php\lib&quot;</pre>
</div>
    </div>

    
   </div>
  </p>
  <p class="para">
   在 .ini 文件内可能会引用已存在的 .ini
   变量。例如：<code class="literal">open_basedir = ${open_basedir}
   &quot;:/new/dir&quot;</code>。
  </p>
  <div class="sect2" id="configuration.file.scan">
   <h3 class="title">扫描路径配置</h3>

   <p class="para">
    可以通过配置，让 PHP 在读完 <var class="filename">php.ini</var> 后，扫描指定路径中的附加 .ini 配置文件。编译时通过
    <strong class="option configure">--with-config-file-scan-dir</strong>
    参数来指定要扫描的目录。扫描路径也可以通过环境变量
    <var class="varname">PHP_INI_SCAN_DIR</var> 来设置。
   </p>

   <p class="para">
    通过在扫描路径配置中加入特定系统的目录分隔符（Windows、NetWare
    和 RISC OS 下是 <code class="literal">;</code>；其它操作系统下是 <code class="literal">:</code>；该值可以通过
    PHP 常量 <strong><code><a href="dir.constants.php#constant.path-separator">PATH_SEPARATOR</a></code></strong> 获取），还可以设置多个扫描路径。如果
    <var class="varname">PHP_INI_SCAN_DIR</var> 为空，PHP 一样会扫描在编译时指定的
    <strong class="option configure">--with-config-file-scan-dir</strong> 此路径。
   </p>



   <p class="para">
    对于每个目录而言，PHP 会以首字符顺序为优先级，扫描该目录下所有的 <code class="literal">.ini</code> 结尾的配置文件。所有被截入的配置文件，可以通过
    <span class="function"><a href="function.php-ini-scanned-files.php" class="function">php_ini_scanned_files()</a></span> 函数来获取列表，也可以通过 PHP 命令行加入
    <strong class="option unknown">--ini</strong> 参数来查看。
   </p>

   

   <div class="informalexample">
    <div class="example-contents screen">
<div class="cdata"><pre>
以下假设 PHP 配置为 --with-config-file-scan-dir=/etc/php.d
并且目录分隔符为 :

$ php
  PHP 会加载 /etc/php.d/*.ini 全部配置文件。

$ PHP_INI_SCAN_DIR=/usr/local/etc/php.d php
  PHP 会加载 /usr/local/etc/php.d/*.ini 全部配置文件。

$ PHP_INI_SCAN_DIR=:/usr/local/etc/php.d php
  PHP 会加载 /etc/php.d/*.ini 下的全部配置文件，然后加载
  /usr/local/etc/php.d/*.ini 下的全部配置文件。

$ PHP_INI_SCAN_DIR=/usr/local/etc/php.d: php
  PHP 会加载 /usr/local/etc/php.d/*.ini 下的全部配置文件，然后加载
  /etc/php.d/*.ini 下的全部配置文件。
</pre></div>
    </div>
   </div>
  </div>
 </div><?php manual_footer($setup); ?>