安装 lnmp 后 发现怎么都运行不了 laravel 一直显示500 状态码,都给了 stoage 目录权限了 。于是查看nginx 错误日志。

Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/default/1211/bootstrap/autoload.php) is not within the allowed path(s): (/home/wwwroot/default/1211/public/:/tmp/:/proc/) in /home/wwwroot/default/1211/public/index.php on line 22

Warning: require(/home/wwwroot/default/1211/bootstrap/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/default/1211/public/index.php on line 22

Fatal error: require(): Failed opening required '/home/wwwroot/default/1211/public/../bootstrap/autoload.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/default/1211/public/index.php on line 22

错误日志显示,访问脚本不在 open_basedir的限定目录里面,配置open_basedir 一般会在php.ini 或 nginx 配置文件里面 首先检测php.ini 我发现并没有配置 open_basedir

然后检测nginx配置,去到 nginx 根目录,运行

grep -rn open_basedir ./

发现 fastcgi.conf 中配置了open_basedir $document_root指向的是网站跟目录。 我注释掉这一行

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

重启 nginx/lnmp 服务

lnmp restart