Warning: require(): open_basedir restriction in effect 错误解决方法

NMP 1.4或更高版本如果不想用防跨目录或者修改.user.ini的防跨目录的目录还需要将 /usr/local/nginx/conf/fastcgi.conf 里面的fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/"; 在该行行前添加 # 或删除改行,需要重启nginx。


出现此类问题一般为open_basedir的问题(open_basedir的值来设置限制访问的目录或删除来移除防跨目录的设置。)

 

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

Warning: require(/home/wwwroot/xlboo.com/bootstrap.php): failed to open stream: Operation not permitted in /home/wwwroot/xlboo.com/public/index.php on line 7

Fatal error: require(): Failed opening required '/home/wwwroot/xlboo.com/public/../bootstrap.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/xlboo.com/public/index.php on line 7

 

 

方法一

删除user.ini

去权后删除即可

chattr -i .user.ini

此方法限制于当前的站点解决

php.ini的说明:https://lnmp.org/faq/lnmp-vhost-add-howto.html#user.ini


方法二

编辑

vim /usr/local/nginx/conf/fastcgi.conf


删除或注释掉这一行(*注释的话前面加“#”号即可)

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

此方法限制于所有的LNMP站点解决

 

 

方法三

编辑user.ini

chattr -i .user.ini

vimuser.ini

open_basedir=/home/wwwroot/xlboo.com/:/tmp/:/proc/

改为

open_basedir=/home/wwwroot/xlboo.com/public/ :/tmp/:/proc/

然后

chattr +i .user.ini

最后重启PHP或者Nginx

重启PHP

/etc/init.d/php-fpm restart

重启Nginx

service nginx restart