一、开发环境:
Linux CentOS 6.7
PHP 5.6.15
nginx 1.10.1
二、问题描述
项目访问的时候报如下错误:
Warning
: require(): open_basedir restriction in effect. File(/data/www/basic/vendor/autoload.php) is not within the allowed path(s): (/data/www/basic/web/:/tmp/:/proc/) in
/data/www/basic/web/index.php
on line
5
Warning
: require(/data/www/basic/vendor/autoload.php): failed to open stream: Operation not permitted in
/data/www/basic/web/index.php
on line
5
Fatal error
: require(): Failed opening required '/data/www/basic/web/../vendor/autoload.php' (include_path='.:/php/includes') in
/data/www/basic/web/index.php
on line
5
三、问题解决
1、nginx错误日志显示,访问脚本不在 open_basedir的限定目录里面,配置open_basedir 一般会在php.ini 或 nginx 配置文件里面。
2、首先检测php.ini 我发现并没有配置 open_basedir 。
3、然后检测nginx配置,在nginx配置文件 nginx.conf 添加
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
4、在nginx项目配置文件中添加
set $basedir "open_basedir=
$document_root
:/tmp/:/proc/:/php/includes/:/home";
set $basedir "open_basedir=
/data/
www/blog:/tmp/:/proc/:/php/includes/:/home";
配置完之后重启nginx即可