章 4. 运行时配置

配置文件

当 PHP 启动时会读取配置文件(在 PHP 3 中称为 php3.ini,在 PHP 4 中简化为 php.ini)。对于服务器模块版本的 PHP 仅在 web 服务器启动时读取一次。对于 CGICLI 版本,每次调用都会读取。

php.ini 的默认位置是在编译时决定的(见常见问题 - 安装),但是对于 CGICLI 版本可以通过命令行开关 -c 来改变,见 PHP 的命令行方式一章。也可以用环境变量 PHPRC 来设定寻找 php.ini 文件的其它路径。

注: Apache 服务器在启动时将目录更改到根目录,致使 PHP 会尝试在根目录下读取 php.ini,如果存在的话。

The php.ini directives handled by extensions are documented respectively on the pages of the extensions themselfs. The list of the core directives is available in the appendix. Probably not all the PHP directives are documented in the manual though. For a completel list of directives available in your PHP version, please read your well commented php.ini file. Alternatively, you may find the the latest php.ini from CVS helpful too.

例子 4-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"