PHP message: PHP Warning: require(): open_basedir restriction in effect.

整合 PHP环境
阅读数: 1117 2020年03月31日

larvel 部署好代码,一直 500 ,查看 nginx error 的时候,发现

020/03/31 10:52:40 [error] 27692#0: *79 FastCGI sent in stderr: "PHP message: PHP Warning:  require(): open_basedir restriction in effect...


一、先了解上面是 open_basedir
参考文章:https://www.jianshu.com/p/a862ce3d13fb《php下open_basedir的配置》
php的配置项open_basedir限制了require()访问的路径。
  open_basedir 将php所能打开的文件限制在指定的目录树中,包括文件本身。当程序要使用例如fopen()或file_get_contents()打开一个文件时,这个文件的位置将会被检查。当文件在指定的目录树之外,程序将拒绝打开。
  在linux系统中,open_basedir主要在php.ini和fastcgi.conf文件中配置,
  php.ini中配置如下:

open_basedir="指定目录";
  fastcgi.conf中配置如下:

fastcgi_param PHP_VALUE "open_basedir=指定目录";
  在windows下,主要在php.ini和apache的http.conf文件中配置,http.conf中配置如下:

php_admin_value open_basedir "指定目录"。
用open_basedir指定的限制实际上是前缀,不是目录名。 也就是说 open_basedir=/home/fdipzone 也会允许访问/home/fdipzone_abc,如果要将访问限制为目录,请使用斜线结束路径名,例如:open_basedir=”/home/fdipzone/”。如果要设置多个目录,window使用分号“;”分隔目录,linux使用冒号“:”分隔目录。
使用open_basedir可以限制程序可操作的目录和文件,提高系统安全性。但会影响I/O性能导致系统执行变慢,因此需要根据具体需求,在安全与性能上做平衡。

二、如何修改
1、尝试加目录,失败。

2、最简单方法:注释掉 open_basedir 的配置,然后重启 php-fpm 和 nginx 即可生效。

# vim /usr/local/nginx/conf/fastcgi.conf
# fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";

/etc/init.d/nginx restart
/etc/init.d/php-fpm restart

【成功】

参考资料
https://www.jianshu.com/p/a862ce3d13fb《php下open_basedir的配置》
phpriji.cn | 网站地图 | 沪ICP备17015433号-1