©
Ce document utilise Manuel du site Web PHP chinois Libérer
配置文件(php.ini)在 PHP 启动时被读取。对于服务器模块版本的 PHP,仅在 web 服务器启动时读取一次。对于 CGI 和 CLI 版本,每次调用都会读取。
php.ini 的搜索路径如下(按顺序):
如果存在 php-SAPI.ini(SAPI 是当前所用的 SAPI 名称,因此实际文件名为 php-cli.ini 或 php-apache.ini 等),则会用它替代 php.ini。SAPI 的名称可以用 php_sapi_name() 来测定。
Note:
Apache web 服务器在启动时会把目录转到根目录,这将导致 PHP 尝试在根目录下读取 php.ini,如果存在的话。
Note:
在 php.ini 中可以使用环境变量。
由扩展库处理的 php.ini 指令,其文档分别在各扩展库的页面。内核配置选项见附录。不过也许不是所有的 PHP 指令都在手册中有文档说明。要得到自己的 PHP 版本中的配置指令完整列表,请阅读 php.ini 文件,其中都有注释。此外,也许从 Git 得到的» 最新版 php.ini 也有帮助。
Example #1 php.ini 例子
; 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 = ".:/usr/local/lib/php"; backslashes are treated the same as any other character include_path = ".;c:\php\lib"
自 PHP 5.1.0 起,有可能在 .ini 文件内引用已存在的 .ini 变量。例如:open_basedir = ${open_basedir} ":/new/dir"。
[#1] edgardoboj at hotmail dot com [2015-07-14 12:48:09]
If you have multiple installations of PHP, and "php --ini" keeps loading the same configuration file for every version instead of the configuration file on the installation path, it might be worthy to check the windows registry.
I found a key on "HEKY_LOCAL_MACHINE\SOFTEARE\Wow6432Node\PHP\IniFilePath" that override any installation, which cause "php --ini" to crash stating a version mismatch with the extensions being loaded.
Deleting the key "HEKY_LOCAL_MACHINE\SOFTEARE\Wow6432Node\PHP" solved the problem.
I guess the key was created with a windows installer for IIS on FastCGI, but just guessing.
For the record, some of the errors thrown are:
"The procedure entry point php_sys_stat could not be located in the dynamic link library php5.dll. "
"The procedure entry point php_checkuid could not be located in the dynamic link library php5.dll. "
Hope someone with such a mess will find this useful.
[#2] Nacho Esviza - ignacio at esviza dot com [2014-08-25 04:06:10]
This solution works for me when I needed to force two diferent versions of PHP on a Windows Server 2012 r2 & IIS:
For one application, map *.php extension to a CgiModule adding the "-c" option to the executable path, like this: "C:\php53\php-cgi.exe -c C:\php53\php.ini"
For the other application, map *.php extension to a CgiModule adding the "-c" option to the executable path, like this: "C:\php54\php-cgi.exe -c C:\php54\php.ini"
I think that way is the cleanest, because there is no need to work with PATH variable or Registry or Windows directory.
Note: for some reason, this didn't work on FastCGI module, related to the way that IIS set the executable tab not allowing command line options.
[#3] pajoye at php dot net [2014-08-06 12:04:49]
Also a nice feature is the ability to use PHP's contants:
For example:
extension_dir=""PHP_MAJOR_VERSION"."PHP_MINOR_VERSION"/ext"
[#4] emil at ncube dot ca [2013-11-04 23:19:58]
Note that the CLI version of PHP does not appear to take into account any php.ini configuration file. As such, something like a max_execution_time limit setting you may think is being applied is actually not being used, and instead defaulting to 0 (which is unlimited).
[#5] Greg Robson [2013-06-04 11:18:47]
If you are on Windows and the
php --ini
command is showing the path you do not want, check the PATH environment variable.
The command line was looking for php.ini in the folder where it found php.exe. In my case this meant it was looking in
c:\Program Files (x86)\php\5.2.6
and not
c:\PHP\5.4.7
Might easily be overlooked when adding new versions to your computer.