該列表只包含核心的 php.ini 配置選項。擴展的配置選項在各個擴展的文檔頁面分別被描述。有關 session 的選項可以在 sessions 頁面找到。
Httpd 選項
名稱 | 默認值 | 可修改范圍 | 更新記錄 |
---|---|---|---|
async_send | "0" | PHP_INI_ALL |
語言選項
名稱 | 默認值 | 可修改范圍 | 更新記錄 |
---|---|---|---|
short_open_tag | "1" | PHP_INI_PERDIR | 在 PHP <= 4.0.0 時是 PHP_INI_ALL。 |
asp_tags | "0" | PHP_INI_PERDIR | 在 PHP <= 4.0.0 時是 PHP_INI_ALL。 |
precision | "14" | PHP_INI_ALL | |
y2k_compliance | "1" | PHP_INI_ALL | |
allow_call_time_pass_reference | "1" | PHP_INI_PERDIR | 在 PHP <= 4.0.0 時是 PHP_INI_ALL。 |
expose_php | "1" | 僅可在 php.ini 中配置。 | |
zend.ze1_compatibility_mode | "0" | PHP_INI_ALL | 從 PHP 5.0.0 起可用。 |
這是配置指令的簡短說明。
- short_open_tag boolean
-
決定是否允許使用 PHP 代碼開始標志的縮寫形式(
<? ?>
)。如果要和 XML 結合使用 PHP,可以禁用此選項以便於嵌入使用<?xml ?>
。否則還可以通過 PHP 來輸出,例如:<?php echo '<?xml version="1.0"'; ?>
。如果禁用了,必須使用 PHP 代碼開始標志的完整形式(<?php ?>
)。Note:
本指令也會影響到縮寫形式
<?=
,它和<? echo
等價。使用此縮寫需要short_open_tag
的值為 On。 -
除了通常的 <?php ?> 標志之外還允許使用 ASP 風格的標志 <% %>。這也包括了輸出變量值的縮寫 <%= $value %>。更多信息見從 HTML 中分離一節。
Note:
ASP 風格標志的支持是 3.0.4 版新加的。
- precision integer
- 浮點數中顯示有效數字的位數。
- y2k_compliance boolean
- 強制 2000 年兼容(在不兼容的瀏覽器中會出問題)。
- allow_call_time_pass_reference boolean
-
在函數調用時參數被按照引用傳遞時是否發出警告。此方法已不被贊成並在 PHP/Zend 未來的版本中很可能不再支持。鼓勵使用的方法是在函數定義中指定哪些參數應該用引用傳遞。鼓勵大家嘗試關閉此選項並確保腳本能夠正常運行,以確保該腳本也能在未來的版本中運行(每次使用此特性都會收到一條警告)。
在函數調用時通過引用傳遞參數是不推薦的,因為它影響到了代碼的整潔。如果函數的參數沒有聲明作為引用傳遞,函數可以通過未寫入文檔的方法修改其參數。要避免其副作用,最好僅在函數聲明時指定那個參數需要通過引用傳遞。
參見引用的解釋。
- expose_php boolean
-
決定是否暴露 PHP 被安裝在服務器上(例如在 Web 服務器的信息頭中加上其簽名)。沒有任何安全上的威脅,只是讓客戶端能夠知道是否在服務器中安裝了 PHP。
- zend.ze1_compatibility_mode boolean
-
啟用 Zend 引擎 1(PHP 4) 兼容模式。這影響到了對象的復制、構造(無屬性的對象會產生 FALSE 或 0)及比較。此模式下,對象將以值傳遞,而不是默認的引用傳遞。
資源限制
名稱 | 默認值 | 可修改范圍 | 更新記錄 |
---|---|---|---|
memory_limit | "8M" | PHP_INI_ALL |
這是配置指令的簡短說明。
- memory_limit integer
-
本指令設定了一個腳本所能夠申請到的最大內存字節數。這有助於防止寫得不好的腳本消耗光服務器上的可用內存。要使用此指令必須在編譯的時候激活。因此 configure 一行中應該包括:--enable-memory-limit。如果不需要任何內存上的限制,必須將其設為 -1。
自 4.3.2 起,當激活了 memory_limit,PHP 函數 memory_get_usage() 便可以使用了。
當使用 integer 時, 其值以字節來衡量。還可以使用在FAQ中描述的速記符。
性能調整
名稱 | 默認值 | 可修改范圍 | 更新記錄 |
---|---|---|---|
realpath_cache_size | "16K" | PHP_INI_SYSTEM | 自 PHP 5.1.0 起可用。 |
realpath_cache_ttl | "120" | PHP_INI_SYSTEM | 自 PHP 5.1.0 起可用。 |
這是配置指令的簡短說明。
數據處理
名稱 | 默認值 | 可修改范圍 | 更新記錄 |
---|---|---|---|
track_vars | "On" | PHP_INI_?? | |
arg_separator.output | "&" | PHP_INI_ALL | 從 PHP 4.0.5 起可用。 |
arg_separator.input | "&" | PHP_INI_PERDIR | 從 PHP 4.0.5 起可用。 |
variables_order | "EGPCS" | PHP_INI_PERDIR | 在 PHP <= 5.0.5 時是 PHP_INI_ALL。 |
auto_globals_jit | "1" | PHP_INI_PERDIR | 從 PHP 5.0.0 起可用。 |
register_globals | "0" | PHP_INI_PERDIR | 在 PHP <= 4.2.3 時是 PHP_INI_ALL。 |
register_argc_argv | "1" | PHP_INI_PERDIR | 在 PHP <= 4.2.3 時是 PHP_INI_ALL。 |
register_long_arrays | "1" | PHP_INI_PERDIR | 從 PHP 5.0.0 起可用。 |
post_max_size | "8M" | PHP_INI_PERDIR | 在 PHP <= 4.2.3 時是 PHP_INI_ALL。從 PHP 4.0.3 起可用。 |
gpc_order | "GPC" | PHP_INI_ALL | |
auto_prepend_file | NULL | PHP_INI_PERDIR | 在 PHP <= 4.2.3 時是 PHP_INI_ALL。 |
auto_append_file | NULL | PHP_INI_PERDIR | 在 PHP <= 4.2.3 時是 PHP_INI_ALL。 |
default_mimetype | "text/html" | PHP_INI_ALL | |
default_charset | "" | PHP_INI_ALL | |
always_populate_raw_post_data | "0" | PHP_INI_PERDIR | 在 PHP <= 4.2.3 時是 PHP_INI_ALL。從 PHP 4.1.0 起可用。 |
allow_webdav_methods | "0" | PHP_INI_PERDIR |
這是配置指令的簡短說明。
- track_vars boolean
-
如果激活,則環境變量,GET,POST,Cookie 和 Server 變量都能夠分別在全局關聯數組中找到:$_ENV,$_GET,$_POST,$_COOKIE 和 $_SERVER。
注意自 PHP 4.0.3 起,
track_vars
總是打開的。 - arg_separator.output string
-
PHP 所產生的 URL 中來分隔參數的分隔符。
- arg_separator.input string
-
PHP 用來將 URL 解析為變量的分隔符列表。
Note:
本指令中的每個字符都會被當成分隔符!
- variables_order string
-
設定 EGPCS(Environment,GET,POST,Cookie,Server)變量解析的順序。默認設定為“EGPCS”。舉例說,將其設為“GP”,會導致 PHP 完全忽略環境變量,cookies 和 server 變量,並用 GET 方法的變量覆蓋 POST 方法的同名變量。
參見 register_globals。
- request_order string
-
This directive describes the order in which PHP registers GET, POST and Cookie variables into the _REQUEST array. Registration is done from left to right, newer values override older values.
If this directive is not set, variables_order is used for $_REQUEST contents.
- auto_globals_jit boolean
-
啟用后,SERVER 和 ENV 變量在他們第一次使用后 (Just In Time) 便被創建,而不是等到腳本開始運行時。如果這些變量沒有在腳本總使用,啟用這個變量會提高服務器性能。
要使此選項有效,PHP 配置選項 register_globals, register_long_arrays, 和 register_argc_argv 必須禁用。
- register_globals boolean
-
決定是否將 EGPCS(Environment,GET,POST,Cookie,Server)變量注冊為全局變量。
PHP » 4.2.0 開始,本選項默認為 off。
相關信息請閱讀安全一章中的使用 register_globals。
請注意
register_globals
不能在運行時設定(ini_set()),盡管如以上說明在主機允許時可以用 .htaccess。一個 .htaccess 項目的例子:php_flag register_globals off
。Note:
register_globals
受 variables_order 選項的影響。 - register_argc_argv boolean
- 決定 PHP 是否定義 argv & argc 變量(可能包含有 GET 信息)。 參見命令行方式。此外,本選項自 PHP 4.0.0 起可用,在此之前總是“On”。
- register_long_arrays boolean
- 設定 PHP 是否注冊已過時的 $HTTP_*_VARS 之類的預定義變量。如果為 On(默認值),則類似 $HTTP_GET_VARS 的 PHP 變量會被注冊。如果不使用,為性能考慮建議關閉此選項,而使用超全局數組例如 $_GET 替代之。 本指令自 PHP 5.0.0 起可用。
- post_max_size integer
- 設定 POST 數據所允許的最大大小。此設定也影響到文件上傳。要上傳大文件,該值必須大於 upload_max_filesize。 如果配置腳本中激活了內存限制,memory_limit 也會影響文件上傳。通常說,memory_limit 應該比 post_max_size 要大。 當使用 integer 時, 其值以字節來衡量。還可以使用在FAQ中描述的速記符。 如果 POST 數據尺寸大於 post_max_size $_POST 和 $_FILES superglobals 便會為空。這可以以多種方式證明,例如,傳遞 $_GET 變量到腳本以處理數據, 也就是 <form action="edit.php?processed=1">, 然后查看 $_GET['processed'] 是否被設置。
- gpc_order string
-
設定 GET/POST/COOKIE 變量解析的順序,默認為“GPC”。舉例說,將其設為“GP”,會導致 PHP 完全忽略 cookie 變量,並用 GET 方法的變量覆蓋 POST 方法的同名變量。
Note:
本選項不能用於 PHP 4。用 variables_order 替代之。
- auto_prepend_file string
-
指定在主文件之前自動解析的文件名。該文件就像調用了 include() 函數一樣被包含進來,因此會使用 include_path。
特殊值 none 禁止了自動前綴。
- auto_append_file string
-
指定在主文件之后自動解析的文件名。該文件就像調用了 include() 函數一樣被包含進來,因此會使用 include_path。
特殊值 none 禁止了自動后綴。
Note: 如果腳本通過 exit() 終止,則自動后綴不會發生。
- default_mimetype string
-
- default_charset string
-
自 4.0b4 起,PHP 總是默認在 HTTP 信息頭 Content-type: 中輸出字符編碼。要禁止發送字符集,將本選項設為空即可。
- always_populate_raw_post_data boolean
-
總是產生 $HTTP_RAW_POST_DATA 變量包含有原始的 POST 數據。否則,此變量僅在碰到未識別 MIME 類型的數據時產生。不過,訪問原始 POST 數據的更好方法是 php://input。$HTTP_RAW_POST_DATA 對於 enctype="multipart/form-data" 表單數據不可用。
- allow_webdav_methods boolean
-
允許在 PHP 腳本中處理 WebDAV 的 HTTP 請求(例如 PROPFIND,PROPPATCH,MOVE,COPY 等)。此選項在 PHP 4.3.2 以后便不存在了。如果要取得這些請求的 POST 數據,也要設定 always_populate_raw_post_data。
參見 magic_quotes_gpc,magic-quotes-runtime 和 magic_quotes_sybase。
路徑和目錄
名稱 | 默認值 | 可修改范圍 | 更新記錄 |
---|---|---|---|
include_path | ".;/path/to/php/pear" | PHP_INI_ALL | |
doc_root | NULL | PHP_INI_SYSTEM | |
user_dir | NULL | PHP_INI_SYSTEM | |
extension_dir | "/path/to/php" | PHP_INI_SYSTEM | |
extension | NULL | 僅限於 php.ini | |
cgi.fix_pathinfo | "1" | PHP_INI_ALL | 從 PHP 4.3.0 起可用 |
cgi.force_redirect | "1" | PHP_INI_ALL | 從 PHP 4.2.0 起可用 |
cgi.redirect_status_env | NULL | PHP_INI_ALL | 從 PHP 4.2.0 起可用 |
fastcgi.impersonate | "0" | PHP_INI_ALL | 從 PHP 4.3.0 起可用 |
cgi.rfc2616_headers | "0" | PHP_INI_ALL | 從 PHP 4.3.0 起可用 |
這是配置指令的簡短說明。
- include_path string
-
指定一組目錄用於 require(),include() 和 fopen_with_path() 函數來尋找文件。格式和系統的 PATH 環境變量類似:一組目錄的列表,在 UNIX 下用冒號分隔,在 Windows 下用分號分隔。
Example #1 Unix include_path
include_path=".:/php/includes"
Example #2 Windows include_path
include_path=".;c:\php\includes"
在包含路徑中使用 . 可以允許相對路徑,它代表當前目錄。
- doc_root string
-
PHP 在服務器上的根目錄。僅在非空時使用。如果 PHP 被配置為安全模式,則此目錄之外的文件一概不被解析。如果 PHP 編譯時沒有指定 FORCE_REDIRECT,並且在任何 web 服務器(除了 IIS)中以 CGI 方式運行 PHP,則應該設定 doc_root。替代方案是使用下面的 cgi.force_redirect 配置選項。
- user_dir string
-
在用戶目錄之下使用 PHP 文件的基本目錄名,例如 public_html。
- extension_dir string
- extension string
-
當 PHP 啟動時所加載的動態連接擴展庫。
- cgi.fix_pathinfo boolean
-
對 CGI 提供了真正的 PATH_INFO/PATH_TRANSLATED 支持。以前 PHP 的行為是將 PATH_TRANSLATED 設為 SCRIPT_FILENAME,而不管 PATH_INFO 是什么。有關 PATH_INFO 的更多信息見 cgi 規格。將此值設為 1 將使 PHP CGI 修正其路徑以遵守規格。設為 0 將使 PHP 的行為和從前一樣。默認為零。用戶應該修正其腳本使用 SCRIPT_FILENAME 而不是 PATH_TRANSLATED。
- cgi.force_redirect boolean
-
在大多數 web 服務器中以 CGI 方式運行 PHP 時很有必要用 cgi.force_redirect 提供安全。PHP 默認其為 On。可以將其關閉,但風險自擔。
Note:
Windows 用戶:可以安全地在 IIS 之下將其關閉,事實上必須這么做。要在 OmniHTTPD 或 Xitami 之下使用也必須將其關閉。
- cgi.redirect_status_env string
-
如果打開了 cgi.force_redirect,並且不是在 Apache 或 Netscape(iPlanet)web 服務器之下運行,可能需要設定一個環境變量名,PHP 將去尋找它來知道可以繼續執行下去。
Note:
設定此變量可能會導致安全問題,首先要知道自己在做什么。
- fastcgi.impersonate string
-
IIS(在基於 WINNT 的操作系統上)中的 FastCGI 支持模仿客戶端安全令牌的能力。這使得 IIS 能夠定義運行時所基於的請求的安全上下文。Apache 中的 mod_fastcgi 不支持此特性(03/17/2002)。如果在 IIS 中運行則設為 1。默認為 0。
- cgi.rfc2616_headers int
-
指定 PHP 在發送 HTTP 響應代碼時使用何種報頭。如果設定為 0,PHP 發送一個 Status: 報頭,Apache 和其它 web server 都支持。如果此選項設定為 1,PHP 將發送 » RFC 2616 兼容的報頭。除非你知道自己在做什么,否則保留其值為 0。
文件上傳
名稱 | 默認值 | 可修改范圍 | 更新記錄 |
---|---|---|---|
file_uploads | "1" | PHP_INI_SYSTEM | 在 PHP <= 4.2.3 時是 PHP_INI_ALL。從 PHP 4.0.3 起可用。 |
upload_tmp_dir | NULL | PHP_INI_SYSTEM | |
upload_max_filesize | "2M" | PHP_INI_PERDIR | 在 PHP <= 4.2.3 時是 PHP_INI_ALL。 |
這是配置指令的簡短說明。
- file_uploads boolean
-
是否允許 HTTP 文件上傳。參見 upload_max_filesize,upload_tmp_dir 和 post_max_size 指令。
當使用 integer 時, 其值以字節來衡量。還可以使用在FAQ中描述的速記符。 - upload_tmp_dir string
-
文件上傳時存放文件的臨時目錄。必須是 PHP 進程所有者用戶可寫的目錄。如果未指定則 PHP 使用系統默認值。
- upload_max_filesize integer
-
所上傳的文件的最大大小。
當使用 integer 時, 其值以字節來衡量。還可以使用在FAQ中描述的速記符。
普通 SQL
名稱 | 默認值 | 可修改范圍 | 更新記錄 |
---|---|---|---|
sql.safe_mode | "0" | PHP_INI_SYSTEM |
這是配置指令的簡短說明。
- sql.safe_mode boolean
-
調試器配置選項
僅 PHP 3 實現了一個默認的調試器。更多信息請參考PHP 的調試。


kghbln Thank you very much you really help me with this mate ! I just start my Hosting Company and i need to protect server from web shells like: c100.php and many other but i also need phpmyadmin , Wordpress and many other script to install for my customers but with base_dir on that isn't possible, this is really help me , now i know i can allow specific multiple directories and restrict-protect everything else !
Thank you
Adding multiple directories to open_basedir:
open_basedir = "/var/www/htdocs/:/var/www/tmp/" adds both paths /var/www/htdocs/ and /var/www/tmp/. Do not forget the trailing slash, otherwise the last directory will be considered as a prefix (< 5.3.4).
On Windows you use ; as the seperator.
If you need to use a path in your include_path that has a space in it - I found that I could make it work (in windows anyway) by setting a path like this
L:\Information Technology\Resources\lib\
in the include path like this listed below
include_path = ".;L:\Information" " Technology\Resources\lib\"
Note that there is no way to disable eval() work by using disable_functions directive, because eval() is a language construct and not a function.
Many people advise to disable such potentially-insecure functions like system(), exec(), passthru(), eval() and so on in php.ini when not running in safe mode, but eval() would still work even it listed in disable_functions.
This is a possible solution for a problem which seems to be a php-ini-problem but is not.
If a $_POST is used with large fields e.g. textarea's with more than 120kb characters php returns a blank screen, even if the max_post_size is 8M.
This problem may be caused by an apache-module SecFilter.
Adding the following lines to the .htaccess solves the problem.
SecFilterEngine Off
SecFilterScanPOST Off
I know this is not a php-issue, but i'm still posting it here since it looks like it is a php-problem and I did not find any sites or forums offering this solution.
Amusingly, the include_path logically includes the current directory of the running file as the last entry all the time anyways, so part of the business about shoving "." into the include_path is spurious -- it's "there" on the end all the time, at least in the 5.2.12 source (see main/fopen_wrappers.c around line 503).
This one had me goin' for a while.
For 'short_open_tag',
though it is marked as PHP_INI_ALL in changable column,
you should note the CHANGE_LOG column also:
PHP_INI_ALL in PHP <= 4.0.0.
PHP_INI_PERDIR in PHP < 5.3.0
So as of 4.0, it will not work if you wanna use
ini_set('short_open_tag') to change it's value on the fly.
Note that on some Unix systems (i.e. PHP 5.1.6 on Centos 5.2) include_path in php.ini should NOT be quoted.
For example, instead of
include_path='.:/usr/share/php'
use
include_path=.:/usr/share/php
Using quotes does not cause any error message, but all of your require_once() directives will fail (indicating that file could not be opened) - unless full path to target file is provided.
When display_errors is off, PHP will send an HTTP 500 result header on a fatal error. This is usefull when working with AJAX applications.
A handy trick to pick up parse errors in test_file.php if you can't set display_errors in php.ini or use .htaccess:
<?php
error_reporting (E_ALL);
ini_set ('display_errors', true);
include('./test_file.php');
?>
"post_max_size"
"[..]This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. <form action="edit.php?processed=1">, and then checking if $_GET['processed'] is set."
using PHP 4.4.8 it seems that only the $_POST array will be empty in case of the file is largen than post_max_size.
so above mentioned method does not work in my case.
i need to use $_POST['processed'] instead of $_GET['processed']
If you are having trouble getting the auto_prepend_file to work with the command line interface make sure that you have set it in the cli specific php.ini and that the read permission is set correctly for that php.ini file.
If you want to display the upload limit without knowing the server configuration, this may be useful:
<?php
function let_to_num($v){ //This function transforms the php.ini notation for numbers (like '2M') to an integer (2*1024*1024 in this case)
$l = substr($v, -1);
$ret = substr($v, 0, -1);
switch(strtoupper($l)){
case 'P':
$ret *= 1024;
case 'T':
$ret *= 1024;
case 'G':
$ret *= 1024;
case 'M':
$ret *= 1024;
case 'K':
$ret *= 1024;
break;
}
return $ret;
}
$max_upload_size = min(let_to_num(ini_get('post_max_size')), let_to_num(ini_get('upload_max_filesize')));
echo "Maximum upload file size is ".($max_upload_size/(1024*1024))."MB.";
?>
Do note however that this limit is not completely reliable; there are other factors which need to be taken into account, such as any other $_POST data and their size, the memory limit, and the script time limit. This does, however, give some rough limit, and helps you avoid "Doh!" problems where you can't figure out why your file won't upload. :)
While the manual says that the file specified by auto_prepend_file is included as if it were called by include(), in fact the file is included as if it were called by require().
In other words, if PHP cannot find the file that you specify with auto_prepend_file, it will throw a fatal error.
register_long_arrays has a very odd behavior (at least in PHP 5.2):
With register_long_arrays=Off the $GLOBALS array will not contain [_SERVER] and [_REQUEST]. They are accessible as superglobals ($_SERVER, $_REQUEST), but they disappear from the $GLOBALS array!
to make sure that all requests use SSL you can use this in a file that is set for auto_prepend_file. This ensures that all requests are SSL
<?php
if(empty($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on' )
header("Location: https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}") and exit();
?>
I wish the documentation was more clear as to whether the arg_separator.output character is automatically encoded when PHP outputs it. In other words, is "&" valid or do I need to specify the encoded character "&"? It would make sense to specify only "&" and hope that it is encoded as needed. That way the value could be read by other functions and encoded only when output to HTML, rather than having to test whether it is already encoded and decode it when necessary (for header redirection for example)
"If the size of post data is greater than post_max_size..."
It seems that a more elegant way is comparison between post_max_size and $_SERVER['CONTENT_LENGTH']. Please note that the latter includes not only size of uploaded file plus post data but also multipart sequences. Leo
Starting with PHP 4.4.0 (at least PHP version 4.3.10 did have old, documented behaviour) interpretation of value of "session.save_path" did change in conjunction with "save_mode" and "open_basedir" enabled.
Documented ( http://de.php.net/manual/en/ref.session.php#ini.session.save-path ):
Values of "session.save_path" should or may be **without** ending slash.
For instance:
<?php
// Valid only *before* PHP 4.4.0:
ini_set( "session.save_path", "/var/httpd/kunde/phptmp" );
?> will mean:
The directory "/var/httpd/kunde/phptmp/" will be used to write data and therefore must be writable by the web server.
Starting with PHP 4.4.0 the server complains that "/var/httpd/kunde/" is not writable.
Solution: Add an ending slash in call of ini_set (or probably whereever you set "session.save_path"), e.g.:
<?php
// Note the slash on ".....phptmp/":
ini_set( "session.save_path", "/var/httpd/kunde/phptmp/" );
?>
Hope, that does help someone.
Warning, if you change upload_max_filesize, please note that both post_max_size and memory_limit directives may have to change too.
I did a little experimentation on the behaviour of auto_prepend_file as the order of access wasn't clear to me from the documentation.
1. Apache checks to see if the target file exists.
2. The prepend file is called
3. The target file is called
This means that you can use auto_prepend_file to change the target file before you access it however you can't generate new files.
Please be mindful, that if you plan on re-configuring / recompiling to add --enable-memory-limit support, you may need to run a 'make clean' before you run 'make'. Otherwise, you may end up with a phpinfo() that shows up with --enable-memory-limit as a configure parameter, but the memory_get_usage() function will still force a fatal error.