配置檔(PHP 3 中是 php3.ini,自 PHP 4
起是 php.ini)在 PHP 啟動時被讀取。對於伺服器模組版本的 PHP,僅在 web
伺服器啟動時讀取一次。對於
CGI 和 CLI 版本,每次呼叫都會讀取。
php.ini 的搜尋路徑如下(按順序):
SAPI 模組所特殊的位置(Apache 2 中的 PHPIniDir
指令,CGI 和 CLI 中的 -c
指令行選項,NSAPI 中的
php_ini 參數,THTTPD 中的
PHP_INI_PATH 環境變量)
HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath(Windows 註冊表位置)
PHPRC 環境變量
現用的工作目錄(對於 CLI)
web 伺服器目錄(對於 SAPI 模組)或 PHP 所在目錄(Windows 下其它情況)
Windows 目錄(C:\windows
或 C:\winnt),或
--with-config-file-path 編譯時選項特殊的位置
若果存在 php-SAPI.ini(SAPI 是現用的所用的 SAPI
名稱,因此實際檔案名為 php-cli.ini 或
php-apache.ini 等),則會用它替代 php.ini。SAPI
的名稱可以用 php_sapi_name() 來測定。
注:
Apache web 伺服器在啟動時會把目錄轉到根目錄,這將導致 PHP 嘗試在根目錄下讀取
php.ini,若果存在的話。
由增加庫處理的 php.ini 指令,其文件分別在各增加庫的頁面。內核配置選項見附錄。不過也許不是所有的 PHP
指令都在手冊中有文件說明。要得到自己的 PHP 版本中的配置指令完整清單,請閱讀
php.ini 檔案,其中都有注解。此外,也許從 CVS 得到的最新版 php.ini 也有說明。
例子 9-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"。