PHP 8.3.4 Released!

php.ini 核心指令说明

该列表只包含可以配置 PHP 的核心 php.ini 指令。扩展的指令处理在各个扩展的文档页面分别列出和详细说明;比如,有关 session 指令可以在 sessions 页面找到。

注意:

当未加载 php.ini 时,使用以下列出的默认值;开发和生产环境的 php.ini 值可能会有所不同。

语言选项

语言和杂类配置选项
名字 默认 可修改范围 更新日志
short_open_tag "1" INI_PERDIR  
precision "14" INI_ALL  
serialize_precision "-1" INI_ALL 在 PHP 7.1.0 以前,默认值为 17。
disable_functions "" 仅为 INI_SYSTEM  
disable_classes "" 仅为 php.ini  
exit_on_timeout "" INI_ALL  
expose_php "1" 仅为 php.ini  
hard_timeout "2" INI_SYSTEM 从 PHP 7.1.0 起可用
zend.exception_ignore_args "0" INI_ALL 从 PHP 7.4.0 起可用
zend.multibyte "0" INI_ALL  
zend.script_encoding NULL INI_ALL  
zend.detect_unicode NULL INI_ALL  
zend.signal_check "0" INI_SYSTEM  
zend.assertions "1" 有限制的 INI_ALL  
zend.exception_string_param_max_len "15" INI_ALL 自 PHP 8.0.0 起可用。

这是配置指令的简短说明。

short_open_tag bool

告诉 PHP 是否允许 PHP 开放标签的缩写形式(<? ?>)。如果要 PHP 和 XML 结合使用,可以禁用此选项以便嵌入使用 <?xml ?>。否则还可以通过 PHP 来打印,例如:<?php echo '<?xml version="1.0"?>'; ?>。此外,如果禁用,必须使用 PHP 开放标签的完整形式(<?php ?>)。

注意:

本指令不会影响简写 <?=,因为它始终可用。

precision int
浮点数中显示有效数字的位数。-1 表示将使用增强算法来四舍五入此类数字。
serialize_precision int
序列化浮点数时存储的有效数字的位数。-1 表示将使用增强算法来四舍五入此类数字。
expose_php bool

确定是否向外界公开服务器上安装了 PHP,在 HTTP 标头中包含 PHP 版本号(例如:X-Powered-By: PHP/5.3.7)。

disable_functions string

本指令可用于禁止某些函数。接受逗号分隔的函数名列表作为参数。

此指令仅能禁用 内置函数。 不能影响用户自定义函数

本指令只能设置在 php.ini 中。例如不能将其设置在 httpd.conf 中。

disable_classes string
本指令允许禁用某些类。接受逗号分隔的类名列表作为参数。 本指令必须设置在 php.ini 中。例如不能将其设置在 httpd.conf 中。
zend.assertions int
当设置为 1 时,生成断言代码并执行(开发模式)。当设置为 0 时,将生成断言代码,但运行时会跳过(不执行)。当设置为 -1 时,不生成断言代码,使断言成本为零(生产模式)。

注意:

如果在生产模式下启动进程,则 zend.assertions 不能在运行时修改,因为未生成断言代码。

如果在开发模式下启动进程,则 zend.assertions 不能在运行时设置为 -1

zend.exception_string_param_max_len int
字符串化栈追踪中字符串函数参数的最大长度。必须介于 "0""1000000" 之间。
hard_timeout int

当命中 max_execution_time 中设置的超时的时候,PHP 运行时将会优雅的销毁资源。如果在这时卡住,硬超时将计时设置的秒数。当命中硬超时的时候,PHP 将异常退出。当设置为 0 时,硬超时始终不会激活。

当 PHP 因硬超时而停止时,它看起来像这样:

Fatal error: Maximum execution time of 30+2 seconds exceeded (terminated) in Unknown on line 0

zend.exception_ignore_args bool

从异常产生的栈中排除参数。

zend.multibyte bool

启用多字节编码的源文件解析。启用 zend.multibyte 是使用 SJIS、BIG5 等在多字节字符串数据中包含特殊字符的字符编码所必需的。ISO-8859-1 兼容的编码,如 UTF-8、EUC 等,则不需要这个选项。

启用 zend.multibyte 需要 mbstring 扩展可用。

zend.script_encoding string

除非在脚本顶部出现 declare(encoding=...) 指令,否则将会使用此值。当使用不兼容 ISO-8859-1 的编码时,必须同时使用 zend.multibyte 和 zend.script_encoding。

文本字符串将从 zend.script_encoding 直译为 mbstring.internal_encoding,就像调用了 mb_convert_encoding() 一样。

zend.detect_unicode bool

检查 BOM(Byte Order Mark,即字节顺序标记)并查看文件是否包含有效的多字节字符。此检测可以在处理 __halt_compiler() 执行。仅在 Zend 多字节模式下使用。

zend.signal_check bool

在关闭时检查替换的信号处理程序。

exit_on_timeout bool

这是 Apache1 mod_php-only 指令,如果 PHP 执行超时,会强制 Apache 子程序退出。这样的超时会导致 Apache1 内部的 longjmp() 调用,从而使一些扩展处于不一致的状态。通过终止进程,将会清除任何未完成的锁或内存。

资源限制

资源限制
名字 默认 可修改范围 更新日志
memory_limit "128M" INI_ALL  

这是配置指令的简短说明。

memory_limit int

设置了允许脚本分配的最大内存量,以字节为单位。这有助于防止写得不好的脚本吃掉服务器上所有可用的内存。请注意,如果不需要内存限制,请将此指令设置为 -1

当使用 int 时, 其值以字节来衡量。还可以使用在 FAQ 中描述的速记符。

请参阅:max_execution_time

性能调整

性能调整
名字 默认 可修改范围 更新日志
realpath_cache_size "4M" INI_SYSTEM PPHP 7.0.16 和 7.1.2 之前,默认值为 "16K"
realpath_cache_ttl "120" INI_SYSTEM  

注意:

启用 open_basedir 将会 禁用 realpath 缓存。

这是配置指令的简短说明。

realpath_cache_size int

设定 PHP 使用的 realpath 缓存的大小。在 PHP 打开很多文件的系统中,这个值应该增加,以优化执行文件操作的数量。

这里的大小表示存储的路径字符串的总字节数,加上与缓存条目相关的数据大小。这意味着,为了在缓存中存储更长的路径,缓存大小必须更大。这个值不直接控制可以缓存的不同路径的数量。

缓存输入数据所需的大小取决于操作系统。

realpath_cache_ttl int

缓存指定文件或目录的真实路径信息的持续时间(以秒为单位)。对于很少改变文件的系统,可以考虑增加该值。

数据处理

数据处理配置选项
名字 默认 可修改范围 更新日志
arg_separator.output "&" INI_ALL  
arg_separator.input "&" INI_PERDIR  
variables_order "EGPCS" INI_PERDIR  
request_order "" INI_PERDIR  
auto_globals_jit "1" INI_PERDIR  
register_argc_argv "1" INI_PERDIR  
enable_post_data_reading "1" INI_PERDIR  
post_max_size "8M" INI_PERDIR  
auto_prepend_file NULL INI_PERDIR  
auto_append_file NULL INI_PERDIR  
default_mimetype "text/html" INI_ALL  
default_charset "UTF-8" INI_ALL  
input_encoding "" INI_ALL  
output_encoding "" INI_ALL  
internal_encoding "" INI_ALL  

这是配置指令的简短说明。

arg_separator.output string

在 PHP 生成的 URL 中用来分隔参数的分隔符。

arg_separator.input string

PHP 用于将输入的 URL 解析为变量的分隔符列表。

注意:

本指令中的每一个字符都被视为分隔符!

variables_order string

设置 EGPCS(Environment、Get、Post、Cookie 和 Server)变量解析的顺序。例如,如果 variables_order 设置为 "SP",然后 PHP 将创建 superglobals $_SERVER$_POST,但不会创建 $_ENV$_GET$_COOKIE。设置为 "" 意味着不会设置 superglobals

警告

在 CGI 和 FastCGI SAPI 中,$_SERVER 也包含环境的值;S 始终等同于 ES,而不关心 E 在该指令中的位置。

注意:

$_REQUEST 的内容和顺序也受到此指令的影响。

request_order string

该指令描述了 PHP 将 GET、POST 和 Cookie 变量注册到 _REQUEST 数组中的顺序。注册是从左到右完成的,新值覆盖旧值。

如果未设置此指令,则 variables_order 用于 $_REQUEST 内容。

请注意,出于安全考虑,默认分发的 php.ini 文件不包含 cookie 的 'C'

auto_globals_jit bool

启用后,SERVER、REQUEST 和 ENV 变量在首次使用时(即时)创建,而不是在脚本启动时创建。如果这些变量未在脚本中使用,启用此指令将提高性能。

警告

在编译期间检查 SERVER、REQUEST 和 ENV 变量的使用,因此通过可变变量使用它们将不会使其初始化。

register_argc_argv bool
告诉 PHP 是否声明 argv & argc 变量(将包含 GET 信息)。 另请参阅命令行
enable_post_data_reading bool
禁用这个选项会导致不会填充 $_POST$_FILES。读取 postdata 的唯一方法是通过 php://input 流封装协议。这对于代理请求或以高效内存的方式处理 POST 数据很有用。
post_max_size int
设置允许 post 数据的最大大小。此设置也会影响文件上传。要上传大文件,此值必须大于 upload_max_filesize 一般来说,memory_limit 应该大于 post_max_size 当使用 int 时, 其值以字节来衡量。还可以使用在 FAQ 中描述的速记符。 如果 post 数据的大小大于 post_max_size,则 $_POST$_FILES 超全局变量为空。这可以通过多种方式进行跟踪,例如通过将 $_GET 变量传递给处理数据的脚本,即 <form action="edit.php?processed=1">,然后检查是否设置了 $_GET['processed']

注意:

PHP 允许使用字节值的快捷方式,包括 K(千)、M(兆)和 G(千兆)。如果使用其中任何一个,PHP 将自动进行转换。注意不要超过 32 位有符号整数限制(如果使用的是 32 位版本),因为这会导致脚本失败。

post_max_size 变更日志
版本 说明
5.3.4 post_max_size = 0 will not disable the limit when the content type is application/x-www-form-urlencoded or is not registered with PHP.
5.3.2 , 5.2.12 Allow unlimited post size by setting post_max_size to 0.

auto_prepend_file string

指定在主文件之前自动解析的文件名。included 该文件像是用 require 函数调用的一样,因此使用了 include_path

特殊值 none 禁用 auto-prepending。

auto_append_file string

指定在主文件之后自动解析的文件名。included 该文件像是用 require 函数调用的一样,因此使用了 include_path

特殊值 none 禁用 auto-prepending。

注意: 如果脚本以 exit() 终止,则不会发生 auto-append。

default_mimetype string

默认情况下,PHP 将使用 Content-Type 标头输出媒体类型。只需将其设置为空即可禁用。

PHP 内置默认媒体类型设置为 text/html。

default_charset string

“UTF-8”是默认值,如果省略 encoding 参数,它的值将用作 htmlentities()html_entity_decode()htmlspecialchars() 的默认字符编码。 如果未设置 iconv.input_encodingiconv.output_encodingiconv.internal_encoding 配置选项,则 default_charset 的值也将用于设置 iconv 函数的默认字符集,如果 mbstring.http_input mbstring.http_output mbstring.internal_encoding 配置选项未设置,则也可用于 mbstring 函数。

如果标头未通过调用 header() 覆盖,则所有版本的 PHP 都将使用此值作为 PHP 发送的默认 Content-Type 报头中的字符集。

不推荐设置 default_charset 为空字符串。

input_encoding string

此设置用于多字节模块,例如 mbstring 和 iconv。 默认为空。

output_encoding string

此设置用于多字节模块,例如 mbstring 和 iconv。 默认为空。

internal_encoding string

此设置用于多字节模块,例如 mbstring 和 iconv。 默认为空。 如果为空,则使用 default_charset

路径和目录

路径和目录配置项
名字 默认 可修改范围 更新日志
include_path ".;/path/to/php/pear" INI_ALL  
open_basedir NULL INI_ALL  
doc_root NULL INI_SYSTEM  
user_dir NULL INI_SYSTEM  
user_ini.cache_ttl "300" INI_SYSTEM  
user_ini.filename ".user.ini" INI_SYSTEM  
extension_dir "/path/to/php" INI_SYSTEM  
extension NULL php.ini only  
zend_extension NULL php.ini only  
cgi.check_shebang_line "1" INI_SYSTEM  
cgi.discard_path "0" INI_SYSTEM  
cgi.fix_pathinfo "1" INI_SYSTEM  
cgi.force_redirect "1" INI_SYSTEM  
cgi.nph "0" INI_SYSTEM  
cgi.redirect_status_env NULL INI_SYSTEM  
cgi.rfc2616_headers "0" INI_ALL  
fastcgi.impersonate "0" INI_SYSTEM  
fastcgi.logging "1" INI_SYSTEM  

这是配置指令的简短说明。

include_path string

指定 requireincludefopen()file()readfile()file_get_contents() 函数在其中查找文件的目录列表,格式类似于系统的 PATH 环境变量:目录列表,在 Unix 中使用冒号分隔,在 Windows 中使用分号分隔。

在查找要包含的文件时,PHP 会分别考虑 include 路径中的每个条目。它将检查第一个路径,如果没有找到它,则检查下一个路径,直到找到包含的文件或返回 E_WARNINGE_ERROR。可以在运行时使用 set_include_path() 修改或设置 include 路径。

示例 #1 Unix include_path

include_path=".:/php/includes"

示例 #2 Windows include_path

include_path=".;c:\php\includes"

在 include 路径中使用 . 允许相对 includes,因为其表示当前目录。但是,显式使用 include './file' 比让 PHP 始终检查当前目录中的每个 include 更有效。

注意:

ENV 变量也可以在 .ini 文件中访问。因此,可以使用 ${LOGIN}${USER} 引用 home 目录。

服务器 API 之间的环境变量可能会有所不同,因为这些环境可能不同。

示例 #3 Unix include_path 使用 ${USER} env 变量

include_path = ".:${USER}/pear/php"

open_basedir string

将 PHP 可以访问的文件限制在指定的目录树中,包括文件本身。

当脚本尝试访问文件系统时,例如使用 includefopen() 时,将检查文件的位置。当文件位于指定的目录树之外时,PHP 将拒绝访问它。所有符号链接都已解析,因此无法通过符号链接避免此限制。如果文件不存在,则符号链接无法解析,文件名将与(已解析的)open_basedir 进行比较。

open_basedir 不仅可以影响文件系统函数;例如,如果 MySQL 配置为使用 mysqlnd 驱动程序,则 LOAD DATA INFILE 将受到 open_basedir 的影响。PHP 的许多扩展功能都以这种方式使用 open_basedir

特殊值 . 表示脚本的工作目录将用作基础目录。然而,这有点危险,因为脚本的工作目录可以很容易地用 chdir() 更改。

httpd.conf 中,open_basedir 可以被关闭(例如对于某些虚拟主机)。就像以相同方式使用“php_admin_value open_basedir none”的其它任何配置指令。

在 Windows 中,用分号分隔目录。在所有其它系统上,用冒号分隔目录。现在 Apache 模块将自动继承来自父目录的 open_basedir 路径。

open_basedir 指定的限制是目录名称,而不是前缀。

默认设置是允许打开所有文件。

注意:

open_basedir 可以在运行时限制更多。这意味着如果在 php.ini 中将 open_basedir 设置为 /www/,则脚本可以在运行时使用 ini_set() 将配置限制到 /www/tmp/。当列出多个目录时,无论操作系统如何,都可以使用 PATH_SEPARATOR 常量作为分隔符。

注意:

使用 open_basedir 会将 realpath_cache_size 设置为 0,从而禁用 realpath 缓存。

警告

open_basedir 只是额外的安全保障,并不全面,因此在需要安全性时并不能依赖它。

doc_root string

PHP 在服务器上的“根目录”。仅在非空时使用。如果 PHP 未使用 FORCE_REDIRECT 编译,并且在任何 Web 服务器(IIS 除外)下将 PHP 作为 CGI 运行,则设置 doc_root。另一种方法是使用下面的 cgi.force_redirect 配置。

user_ini.cache_ttl int

user_ini.filename string

user_dir string

用户 home 目录中用于 PHP 文件的基本目录名,例如 public_html

extension_dir string

PHP 寻找可动态加载扩展的目录。建议指定绝对路径。参阅 enable_dldl()

extension string

PHP 启动时要加载的动态可加载扩展。

zend_extension string

PHP 启动时要加载的动态可加载 Zend 扩展名(例如 XDebug)。

cgi.check_shebang_line bool

控制 CGI PHP 是否检查以 #!(shebang)在运行脚本的顶部。如果脚本支持作为独立脚本和通过 PHP CGI 运行,则可能需要此行。如果此指令打开,CGI 模式下的 PHP 将跳过此行并忽略其内容。

cgi.discard_path bool

如果启用,PHP CGI 二进制文件可以安全地放置在 web 树之外,用户将无法绕过 .htaccess 安全性。

cgi.fix_pathinfo bool

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 bool

cgi.force_redirect 是在大多数 Web 服务器下提供将 PHP 作为 CGI 运行的安全性所必需的。如果未定义,PHP 默认开启。也可以关闭它自行承担风险

注意:

Windows 用户:使用 IIS 时必须关闭此选项。对于 OmniHTTPD 或 Xitami,同样适用。

cgi.nph bool

如果启用了 cgi.nph,对每个请求始终强制 cgi 发送 Status: 200。

cgi.redirect_status_env string

如果打开了 cgi.force_redirect,并且没有在 Apache 或 Netscape (iPlanet) Web 服务器下运行,可能需要设置一个环境变量名称,PHP 将查找该名称以了解是否可以继续执行。

注意:

设置此变量可能会导致安全问题,首先要知道自己在做什么

cgi.rfc2616_headers int

告诉 PHP 在发送 HTTP 响应代码时使用什么样的标头类型。如果设置为 0,PHP 将发送 Apache 和其他 Web 服务器支持的 » RFC 3875 "Status:" 标头。当此选项设置为 1 时,PHP 将发送 » RFC 2616 兼容标头。

如果启用此选项,并且在 CGI 环境(例如 PHP-FPM)中运行 PHP,则不应使用标准的 RFC 2616 样式的 HTTP 状态响应标头,而应使用其等效的 RFC 3875,例如不该使用 header("HTTP/1.0 404 Not found"); 应该使用 header("Status: 404 Not Found");

除非知道自己在做什么,否则请将其设置为 0。

fastcgi.impersonate string

IIS 下的 FastCGI(在基于 WINNT 的操作系统上)支持模拟调用客户端的安全令牌的能力。这允许 IIS 定义请求在其下运行的安全上下文。Apache 下的 mod_fastcgi 目前不支持此功能(2002-03-17)。如果在 IIS 下运行,则设置为 1。默认为 0。

fastcgi.logging bool

使用 FastCGI 时打开 SAPI 日志记录。默认是启用日志记录。

文件上传

文件上传配置项
名字 默认 可修改范围 更新日志
file_uploads "1" INI_SYSTEM  
upload_tmp_dir NULL INI_SYSTEM  
max_input_nesting_level 64 INI_PERDIR  
max_input_vars 1000 INI_PERDIR  
upload_max_filesize "2M" INI_PERDIR  
max_file_uploads 20 INI_PERDIR  

这是配置指令的简短说明。

file_uploads bool

是否允许 HTTP 文件上传。参阅 upload_max_filesizeupload_tmp_dirpost_max_size 指令。

upload_tmp_dir string

上传文件时用来存放文件的临时目录。必须允许运行 PHP 的任何用户写入。如果未指定,PHP 将使用系统默认值。

如果此处指定的目录不可写,PHP 回退到系统默认临时目录。如果打开 open_basedir,然后允许系统临时目录才可以成功上传。

upload_max_filesize int

上传文件的最大大小。

post_max_size 必须大于此值。

当使用 int 时, 其值以字节来衡量。还可以使用在 FAQ 中描述的速记符。
max_file_uploads int

允许同时上传的最大文件数。提交时留空的上传字段不计入此限制。

常规 SQL

常规 SQL 配置项
名字 默认 可修改范围 更新日志
sql.safe_mode "0" INI_SYSTEM 自 PHP 7.2.0 起移除

这是配置指令的简短说明。

sql.safe_mode bool

If turned on, database connection functions that specify default values will use those values in place of any user-supplied arguments. For details on the default values, see the documentation for the relevant connection functions.

警告

此功能自 PHP 7.2.0 起移除

Windows 专用

Windows 专用配置选项
名字 默认 可修改范围 更新日志
windows.show_crt_warning "0" INI_ALL  

这是配置指令的简短说明。

windows.show_crt_warning bool

该指令在启用时显示 Windows CRT 警告。

add a note

User Contributed Notes 9 notes

up
10
luisdev
4 years ago
https://haydenjames.io/understanding-php-memory_limit/ explains the memory_limit setting nicely.
up
4
Simone Pellegatta
3 years ago
Be careful while using auto_prepend_file.

When the custom exception handler, set by set_exception_handler(), handles an uncaught exception, it interrupts the execution of every script.

If the script with the unhandled exception has been automatically prepended or included by an automatically prepended script, however, the main script will continue running anyway.

This could cause several issues: when we think that throwing an exception would automatically interrupt the current application, a whole chunk of code is going to run anyway.
up
4
diamondeagle at webmail dot co dot za
4 years ago
Note regarding the upload_tmp_dir setting and UNC Paths:

When using PHP on Windows OS and IIS FastCGI, if you need to use a UNC path to a folder on a network drive for the upload_tmp_dir setting then you must use three \ characters at the front of the UNC path.

Windows and PHP use the first slash as an escape character, so if you only use two slashes then it passes a UNC path with just one backslash. That is not valid for UNC paths and you many experience problems when uploading files, such as errors saying that "PHP is missing a temporary folder".

Correct:
upload_tmp_dir = "\\\path\to\your\folder"

Incorrect:
upload_tmp_dir = "\\path\to\your\folder"
up
0
juliohenrique at msn dot com
17 days ago
PHP does not capture the file size when the upload_max_filesize directive is set to less than the file size. For example, I want to send a message to the user that the file has exceeded the allowed upload size for a certain application, however, the upload_max_filesize directive does not allow it. If I don't want to allow uploading files larger than 2MB, but the upload_max_filesize directive is set to 10M, if the user sends a 15MB file the message is not displayed because $_FILES['arquivo']['size'] comes equal to 0. To display the message I must increase the upload_max_filesize, however, this represents a security flaw. Also, how much should I increase the upload_max_filesize to, to infinity?
I don't know the size of the file the user will upload.
Example:
$file = $_FILES['file'];
switch ($file){
case ($file['size'] > (2097152)):
echo "<p style='color: #f00;'>This file exceeds the size of 2MB!</p>";
break;
In the case where upload_max_filesize is set to, for example, 10M, if the user uploads a 15M file, PHP does nothing (does not display the message) because $arquivo['size'] comes as int(0).
With 'if else' the same thing happens.
Maybe I don't know how to code, but I've tried in several ways.
up
0
fernandobasso dot br at gmail dot com
7 years ago
This might help in case someone happens to maintain old applications with a charset other than utf-8.

According to the docs, you can override the default charset if you use `header()`.

Suppose php.ini sets the default_charset to "UTF-8", but you need a legacy charset, like ISO-8859-1.

Still,

<?php header('Content-Type: text/html; Charset=ISO-8859-1'); ?>

would not override the charset, just add it as well and the result
was a response header like (note the two charsets):

Content-Type:"text/html; Charset=ISO-8859-1;charset=UTF-8"

I found it strange the default one as `charset` with a lowercase `c`
as opposed to my custom charset with an uppercase `C`.

What solved was to _override_ the charset using all lowercase letters
as well for the word “charset”:

<?php header('content-type: text/html; charset=ISO-8859-1'); ?>

Then, the double charset from the response headers disappeared, and only the single, custom charset remained.
up
0
leo at korfu dot cz
17 years ago
"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
up
-2
dougal at gunters dot org
8 years ago
It appears that if you use both the 'include_path' directives and 'open_basedir', that file searches will hit the include path *first*, before local files. But if 'open_basedir' is not in use, then local files are found first. For example, suppose you have code in '/var/www/myfile.php' which does:

<?php
require_once('config.php');
?>

Further, assume that there is a local file '/var/www/config.php', and there is also a file '/var/local/php/config.php'.

Next, if your php.ini has:

include_path = /var/local/php/

Normally, this would look for '/var/www/config.php' first, and if not found, then it would try '/var/local/php/config.php'.

But if you also have this in php.ini:

open_basedir = /var/www/:/var/local/php/

Then the require would reverse the order of the search, and load '/var/local/php/config.php', even when the local 'config.php' file exists.

Furthermore, if include_path contains directories not in open_basedir, you can end up with a fatal error. For example, change the directive to:

open_basedir = /var/www/:/var/local/includes/php/

Now the require will first find '/var/local/php/config.php' from the include_path, try to include it, but be unable to because of the open_basedir restrictions.
up
-2
Anton Bannikov
3 years ago
I had a problem with 'open_basedir =' string in php.ini. This string was writtren in VirtualHost Directory directive of Apache2 and successfully rewrote the same php.ini setting! It happened with VestaCP, but I think, it's a common way. Goog luck!
up
-2
andre dot wetter at myelco dot ch
2 years ago
If you use Microsoft IIS Windows and want to use open_basedir restrictions with multiple dirs you have to set them into single quotes in the main config xml file of IIS (C:\Windows\System32\inetsrv\config\applicationHost.config). Works fine in IIS 10.

Multiple files with single quotes and ; for windows:
"C:\php\php-cgi.exe|-d open_basedir='C:\Windows\Temp\;D:\mywebsite1\'"

Only one dir works fine without single quotes:
"C:\php\php-cgi.exe|-d open_basedir=D:\mywebsite1\"

In my main config xml file of IIS there are 2 nodes to set per website and the definitions have to be equal:
configuration\Location\system.webServer\handlers\add
configuration\system.webServer\fastCgi
To Top