example #2 says "[php] ; section markers (text within square brackets) are also ignored" - yet if you remove these 'section markers' everything breaks, - which means they're *not* ignored.
配置文件(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"。
example #2 says "[php] ; section markers (text within square brackets) are also ignored" - yet if you remove these 'section markers' everything breaks, - which means they're *not* ignored.
in php.ini you can reference to an existing directive or an environment variable using the syntax ${varname}.
Here are some examples.
sys_temp_dir = "${WINDIR}"
--- ${WINDIR} will be replaced by $_ENV['WINDIR'] at runtime
--- you can set environment variables by Apache and use them in php.ini
--- FcgidInitialEnv AUTHOR "WUXIANCHENG"
--- error_log = "${AUTHOR}.log"
error_log = "${sys_temp_dir}"
--- ${sys_temp_dir} will be replace by the value of sys_temp_dir
Also you can use PHP constants in php.ini, but DONT'T wrap them in ${} or "".
error_log = "/data/"PHP_VERSION"/"
--- it works like this php code:
$error_log = "/data/" . PHP_VERSION . "/";
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.
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.
Also a nice feature is the ability to use PHP's contants:
For example:
extension_dir=""PHP_MAJOR_VERSION"."PHP_MINOR_VERSION"/ext"