require(): open_basedir restriction in effect

LNMP环境安装Laravel,在nginx.conf将root指向项目的public目录的时候(如:root /home/wwwroot/laravel/public),浏览器运行报500错误,错误信息为:
Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/laravel/vendor/autoload.php) is not within the allowed path(s): (/home/wwwroot/laravel/public/:/tmp/:/proc/:/home/wwwroot/laravel/public/) in /home/wwwroot/laravel/public/index.php on line 24

Warning: require(/home/wwwroot/laravel/vendor/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/laravel/public/index.php on line 24

Fatal error: require(): Failed opening required '/home/wwwroot/laravel/public/../vendor/autoload.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/laravel/public/index.php on line 24

1、查找php.ini 发现“open_basedir”为注释状态
2、查看nginx下的fastcgi.conf ,发现“fastcgi_param”参数如下
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
这里的$document_root 就是 nginx中定义的root的目录
3、修改nginx下的fastcgi.conf,在后面追加上项目的根目录,如下:
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/:/home/wwwroot/laravel/";
4、重启lnmp ,错误消失。

猜你喜欢

转载自blog.51cto.com/falconfei/2406180