关于open_basedir restriction in effect 错误的解决

in PHP with 0 comment

关于open_basedir restriction in effect 错误的解决

2018/11/27 00:14:35 [error] 30212#0: *11 FastCGI sent in stderr: "PHP message: PHP Warning:  require(): open_basedir restriction in effect. File(/home/wwwroot/laravel-shop/vendor/autoload.php) is not within the allowed path(s): (/home/wwwroot/laravel-shop/public/:/tmp/:/proc/) in /home/wwwroot/laravel-shop/public/index.php on line 24
PHP message: PHP Warning:  require(/home/wwwroot/laravel-shop/vendor/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/laravel-shop/public/index.php on line 24
PHP message: PHP Fatal error:  require(): Failed opening required '/home/wwwroot/laravel-shop/public/../vendor/autoload.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/laravel-shop/public/index.php on line 24" while reading response header from upstream, client: 101.91.60.106, server: www.pltrue.xyz, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.sock:", host: "www.pltrue.xyz", referrer: "

上线部署的时候发现了一个这样的错误问题,

我来进行一次错误定位

首先页面报的是 500 错误,那联想到的肯定是服务器错误

打开 nginx.conf 或者 你域名的相关nginx.conf的配置文件

查看是否添加 error_log

如果没有 设置

error_log /home/wwwlogs/new_surest_error.log

重启nginx

service nginx reload

再次访问报 500 错误,打开我们的错误日志文件位置 error_log /home/wwwlogs/new_surest_error.log

查看到错误为

2018/11/27 00:14:35 [error] 30212#0: *11 FastCGI sent in stderr: "PHP message: PHP Warning:  require(): open_basedir restriction in effect. File(/home/wwwroot/laravel-shop/vendor/autoload.php) is not within the allowed path(s): (/home/wwwroot/laravel-shop/public/:/tmp/:/proc/) in /home/wwwroot/laravel-shop/public/index.php on line 24
PHP message: PHP Warning:  require(/home/wwwroot/laravel-shop/vendor/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/laravel-shop/public/index.php on line 24
PHP message: PHP Fatal error:  require(): Failed opening required '/home/wwwroot/laravel-shop/public/../vendor/autoload.php'

提取关键字 open_basedir

打开php.ini 或则百度 得知

; open_basedir, if set, limits all file operations to the defined directory
; and below.  This directive makes most sense if used in a per-directory
; or per-virtualhost web server configuration file.
; http://php.net/open-basedir

翻译意思差不多,如果设置了open_basedir,则将所有文件操作限制到定义的目录,
意思就是说,当你的访问目录是 /home/wwwroot/host/public/ 下的话 你不能引用或者使用  /home/wwwroot/storage的文件,不能跨目录访问

of course ,我们定义的是public目录,所以需要适当修改

打开fastcigi.conf

或者 查看 conf 地址: locate fastcgi.conf

按照如下修改即可

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";  

# /home/wwwroot/ 即能跨目录访问的地方 ,我们的项目即是这个地址
fastcgi_param PHP_ADMIN_VALUE "open_basedir=/home/wwwroot/:/tmp/:/proc/";

重启php-fpm

lnmp restart 
Comments are closed.