require(): open_basedir restriction in effect. 解决方法

在linux服务器部署thinkphp5的时候PHP报了这个错误,

如下:

Warning: require(): open_basedir restriction in effect. File(/www/wwwroot/zhuyuyun/thinkphp/start.php) is not within the allowed path(s): (/www/wwwroot/zhuyuyun/public/:/tmp/:/proc/) in /www/wwwroot/zhuyuyun/public/index.php on line 20
Warning: require(/www/wwwroot/zhuyuyun/thinkphp/start.php): failed to open stream: Operation not permitted in /www/wwwroot/zhuyuyun/public/index.php on line 20
Fatal error: require(): Failed opening required ‘/www/wwwroot/zhuyuyun/public/../thinkphp/start.php‘ (include_path=‘.:/www/server/php/56/lib/php‘) in /www/wwwroot/zhuyuyun/public/index.php on line 20

解决方法:

我首先要申明的是,下面的方法适合所有报“PHP报:require(): open_basedir restriction in effect”错误的项目,并不仅仅只是适合thinkphp5的人。只要你的PHP报此错误都可以得到解决。

如果把ThinkPHP5部署在了LAMP/LNMP环境上很有可能出现白屏的情况,这个时候需要开启 php 错误提示来判断是否是因为设置了open_basedir选项出错。

打开 php.ini 搜索 display_errors,把 Off 修改为 On就开启了 php 错误提示,这时再访问之前白屏的页面就会出现错误信息。如果错误信息如下那么很有可能就是因为open_basedir的问题。

一、php.ini 修改方法

把权限作用域由入口文件目录修改为框架根目录

打开 php.ini 搜索 open_basedir,把

open_basedir = "/home/wwwroot/tp5/public/:/tmp/:/var/tmp/:/proc/"

修改为

open_basedir = "/home/wwwroot/tp5/:/tmp/:/var/tmp/:/proc/"

注意:

如果你的 php.ini 文件的 open_basedir 设置选项是被注释的或者为 none,那么你需要通过 Apache 或者 Nginx 来修改> php.ini 文件通常是在 /usr/local/php/etc 目录中,当然了这取决于你 LAMP 环境配置。

二、Apache 修改方法

Apache 需要修改 httpd.conf 或者同目录下的 vhost 目录下 你的域名.conf 文件,如果你的生成环境是 LAMP 一键安装包配置那么多半就是直接修改 你的域名.conf 文件

apache
├─vhost
    ├─www.thinkphp.cn.conf
    ├─......
├─httpd.conf

打开 你的域名.conf 文件 搜索 open_basedir,把

php_admin_value open_basedir "/home/wwwroot/www.thinkphp.cn/public/:/tmp/:/var/tmp/:/proc/"

修改为

php_admin_value open_basedir "/home/wwwroot/www.thinkphp.cn/:/tmp/:/var/tmp/:/proc/"

然后重新启动 apache 即可生效

> 域名.conf 文件通常是在 /usr/local/apache/conf 目录中,当然了这取决于你 LAMP 环境配置

三、Nginx/Tengine 修改方法

Nginx 需要修改 nginx.conf 或者 conf/vhost 目录下 你的域名.conf 文件,如果你的生成环境是 LNMP/LTMP 一键安装包配置那么多半就是直接修改 你的域名.conf 文件

nginx
├─conf
    ├─vhost
        ├─www.thinkphp.cn.conf
    ├─nginx.conf
    ├─......
├─nginx.conf

打开 你的域名.conf 文件 搜索 open_basedir,把

fastcgi_param  PHP_VALUE  "open_basedir=/home/wwwroot/www.thinkphp.cn/public/:/tmp/:/proc/";

修改为

fastcgi_param  PHP_VALUE  "open_basedir=/home/wwwroot/www.thinkphp.cn/:/tmp/:/proc/";

然后重新启动 Nginx 即可生效

> 域名.conf 文件通常是在 /usr/local/nginx/conf/vhost 目录中,当然了这取决于你 LNMP/LTMP 环境配置

四、fpm/fastcgi user.ini 修改方法

打开 项目根目录下找到 user.ini 文件,搜索 open_basedir,把

open_basedir=/home/wwwroot/www.thinkphp.cn/public/:/tmp/:/proc/

修改为

open_basedir=/home/wwwroot/www.thinkphp.cn/:/tmp/:/proc/

然后重新启动 web 服务器 即可生效

总结:

一定要仔细读此篇文章,否则你会选错适合你的方法。

一定要根据自己的服务器环境来选择你的修改方法。

原文链接:https://www.fujieace.com/php/open_basedir.html

原文地址:https://www.cnblogs.com/blibli/p/8657736.html

时间: 2025-01-11 21:39:27

require(): open_basedir restriction in effect. 解决方法的相关文章

宝塔面板出现“require(): open_basedir restriction in effect. ”的解决方法

https://www.fujieace.com/php/open_basedir.html 宝塔面板出现“require(): open_basedir restriction in effect. ”的解决方法 宝塔面板出现“require(): open_basedir restriction in effect. ”的解决方法 1.只需要在相应的网站目录,勾选掉防跨站攻击(open_basedir)即可! 2.必须重启Php 原文地址:https://www.cnblogs.com/zx

open_basedir restriction in effect,解决php引入文件权限问题 解决方法

如下: Warning: require(): open_basedir restriction in effect. File(/www/wwwroot/zhuyuyun/thinkphp/start.php) is not within the allowed path(s): (/www/wwwroot/zhuyuyun/public/:/tmp/:/proc/) in /www/wwwroot/zhuyuyun/public/index.php on line 20 Warning: r

thinkPHP5配置nginx环境无法打开(require(): open_basedir restriction in effect. File(/mnt/hgfs/root/tp5/thinkphp/start.php) is not within the allowed path(s)

今天想把玩一下tp5,结果怎么都无法访问,每次都是报500错误,我把错误提示都打开看到下面的错误 require(): open_basedir restriction in effect. File(/mnt/hgfs/root/tp5/thinkphp/start.php) is not within the allowed path(s): (/mnt/hgfs/root/tp5/public/:/tmp/:/proc/) 1,我是php7 ,php.ini里面的open_basedir

Warning: require(): open_basedir restriction in effect. File(/www/wwwroot/../thinkphp/start.php) is not within the allowed path(s):

Warning: require(): open_basedir restriction in effect. File(/www/wwwroot//../thinkphp/start.php) is not within the allowed path(s): 目录的问题 thinkphp 请设置首页访问的目录是 public 原文地址:https://www.cnblogs.com/baker95935/p/9041030.html

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/

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

出现问题的原因:php open_basedir 配置的问题,PHP不能引入其授权目录上级及其以上的文件,之所以出现这个问题绝大多数情况是由于服务器的权限限制问题. 1.对于windows和linux解决方式基本都一样的,只是路径书写问题需要注意 2.可以尝试项目根目录下找到 user.ini 文件,直接删除掉看是否能够解决 3.nginx解决方案: nginx.conf 或者 conf/vhost 目录下 你的域名.conf 文件或fastcgi.conf或vhost.conf,搜索 open

lnmp 环境require(): open_basedir restriction in effect 错误

最近配置开发用的lnmp环境,环境配置完成后,爆500错误,查看nginx错误日志 open_basedir 将 PHP 所能打开的文件限制在指定的目录树,包括文件本身 错误日志显示,访问脚本不在 open_basedir的限定目录里面,配置open_basedir 一般会在php.ini 或 nginx 配置文件里面 首先检测php.ini 我发现并没有配置 open_basedir 然后检测nginx配置 发现 fastcgi.conf 中配置了open_basedir $document_

lnmp错误提示 open_basedir restriction in effect 解决

/usr/local/nginx/conf/fastcgi.conf 修改如下:即修改open_basedir的内容,修改好后重启lnmp 原文地址:http://blog.51cto.com/itafei/2094854

宝塔部署项目报Warning: require(): open_basedir restriction in effect的解决方案

关闭防跨站攻击(open_basedir)即可! 把钩打掉,记得重启一下php服务哦~即可! 原文地址:https://www.cnblogs.com/apolloren/p/12237284.html