在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

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

  1. LNMP - Warning: require(): open_basedir restriction in effect错误解决方法

    LNMP 1.4或更高版本如果不想用防跨目录或者修改.user.ini的防跨目录的目录还需要将 /usr/local/nginx/conf/fastcgi.conf 里面的fastcgi_param ...

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

    如下: 出现问题的原因: 查看问题描述以及资料,发现是php open_basedir 配置的问题,PHP不能引入其授权目录上级及其以上的文件: 一般情况下是不会出现这种问题的,之所以出现这个问题绝大 ...

  3. php 环境require(): open_basedir restriction in effect 错误

    php 环境require(): open_basedir restriction in effect 错误 错误日志显示,访问脚本不在 open_basedir的限定目录里面 解决方法打开fastc ...

  4. 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 ...

  5. 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 ...

  6. require(): open_basedir restriction in effect. File

    新安装的 lnmp 环境,将项目放上报 require(): open_basedir restriction in effect. File 的错误! 错误日志显示,访问脚本不在 open_base ...

  7. php错误提示 open_basedir restriction in effect 解决

    <VirtualHost *:80> DocumentRoot "D:/www/4w_raaaa_com_2017" ServerName www.raaaa.com: ...

  8. require(): open_basedir restriction in effect. File(/www/wwwroot/xcx/zerg/thinkphp/start.php) is not within the allowed path(s): (/www/wwwroot/xcx/zerg/public/:/tmp/:/proc/) in /www/wwwroot/xcx/zerg/p

    解决方法: 在如下文件增加一项(如图所示) 在如下文件增加一项(如图所示): #php文件采用fastcgi解析并设置参数    location ~ \.php {        try_files ...

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

    最近配置开发用的lnmp环境,环境配置完成后,爆500错误,查看nginx错误日志 open_basedir 将 PHP 所能打开的文件限制在指定的目录树,包括文件本身 错误日志显示,访问脚本不在 o ...

随机推荐

  1. C# Selenium with PhantomJSDriver get image width and height (获取图片的长和高)

    //get image width and height var image=driver.FindElement(By.ClassName("it-Header_authorImage&q ...

  2. LINUX内核中的机制OOM

    [概念] LINUX内核中有一个机制叫做OOM killer(Out Of Memery killer) 该机制监控内存占用过大,尤其是瞬间消耗大量内存的进程, 为了防止内存被耗尽,所以OOM kil ...

  3. Redis安装和客户端cli常见操作

    安装Redis $ wget http://download.redis.io/releases/redis-4.0.6.tar.gz $ tar xzf redis-4.0.6.tar.gz $ c ...

  4. nginx配置--event模块

    在nginx的配置中,event模块可以进行以下配置: 设置网络连接的序列化. 在Nginx服务器的多进程下,有可能出现惊群(Thundering herd problem)问题,指的是当某一个时刻只 ...

  5. Adding Completion to (interactive)

      Adding Completion to (interactive) Author: Tubo Question: Is there any way to add my own completio ...

  6. 某PCBA企业应用易普优APS实现高级计划排程案例

    一.项目介绍 1.生产计划现状 某PCBA企业(以下简称A企业)的产品生产是典型的多品种.小批量.多变化的生产模式.其中产品种类有1000多种,主流的200多种,每个月数百个生产订单,分解到工序以后的 ...

  7. mysql函数积累

    group_concat(),手册上说明:该函数返回带有来自一个组的连接的非NULL值的字符串结果.比较抽象,难以理解. 通俗点理解,其实是这样的:group_concat()会计算哪些行属于同一组, ...

  8. 《java虚拟机》----类加载机制

    No1: 实现语言无关性的基础仍然是虚拟机和字节码存储格式,虚拟机只与Class文件这种特定的二进制文件格式所关联,并不关心Class的来源是何种语言. No2: Class文件是一组以8位字节为基础 ...

  9. 洛谷P2243 电路维修 [最短路]

    题目传送门 电路维修 题目背景 Elf 是来自Gliese 星球的少女,由于偶然的原因漂流到了地球上.在她无依无靠的时候,善良的运输队员Mark 和James 收留了她.Elf 很感谢Mark和Jam ...

  10. BZOJ1878 [SDOI2009] HH的项链 [莫队,卡常]

    BZOJ传送门,洛谷传送门 HH的项链 Description HH有一串由各种漂亮的贝壳组成的项链.HH相信不同的贝壳会带来好运,所以每次散步 完后,他都会随意取出一 段贝壳,思考它们所表达的含义. ...