PHP open_basedir restriction in effect 错误解决 以及`.user.ini` 的使用
目录
PHP open_basedir restriction in effect 错误解决 以及.user.ini 的使用
首先说明是怎么导致这个问题的 :
由于php配置的open-basedir参数为默认,或者配置错误导致的。
可以配置的地方
-
nginx + php 环境
可配置文件影响站点配置的nginx配置均可,其中一些说法有可以修改
fastcgi_param或fastcgi.conf,在文件中加入:
fastcgi_param PHP_ADMIN_VALUE "open_basedir=/site_root_path/:/tmp/:/proc/";其中
/site_root_path为站点的绝对路径,后面有/。 -
apache + php 环境
.haccess加入下面代码php_admin_value open_basedir "open_basedir=/site_root_path/:/tmp/:/proc/" -
在项目根目录创建
.user.ini文件文末详解
什么是.user.ini?
自 PHP 5.3.0 起,PHP 支持基于每个目录的 .htaccess 风格的 INI 文件。此类文件仅被 CGI/FastCGI SAPI 处理。此功能使得 PECL 的 htscanner 扩展作废。如果使用 Apache,则用 .htaccess 文件有同样效果。
关于open-basedir参数
将PHP可以访问的文件限制为指定的目录树,包括文件本身。这个指令是不是由安全模式打开或者关闭的影响。
Limit the files that can be accessed by PHP to the specified directory-tree, including the file itself. This directive is NOT affected by whether Safe Mode is turned On or Off.
open-basedir参数可以在.user.ini中配置
PHP_INI_* 模式的定义
| 模式 | 含义 |
|---|---|
| PHP_INI_USER | 可在用户脚本(例如 ini_set())或 Windows 注册表(自 PHP 5.3 起)以及 .user.ini 中设定 |
| PHP_INI_PERDIR | 可在 php.ini,.htaccess 或 httpd.conf 中设定 |
| PHP_INI_SYSTEM | 可在 php.ini 或 httpd.conf 中设定 |
| PHP_INI_ALL | 可在任何地方设定 |
如何解决?
笔者是nginx+php环境因此采用.user.ini,内容如下:
open_basedir=/home/wwwroot/alumni-link/:/tmp/:/proc/
项目根路径

浙公网安备 33010602011771号