如下:

出现问题的原因:

查看问题描述以及资料,发现是php open_basedir 配置的问题,PHP不能引入其授权目录上级及其以上的文件;

一般情况下是不会出现这种问题的,之所以出现这个问题绝大多数情况是由于服务器的原因,为了安全才做了这样的限制!

解决方法:

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

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

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

一、php.ini 修改方法

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

打开 php.ini 搜索 open_basedir,把

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

修改为

  1. 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 文件

  1. apache
  2. ├─vhost
  3. ├─www.thinkphp.cn.conf
  4. ├─......
  5. ├─httpd.conf

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

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

修改为

  1. 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 一键安装包配置那么多半就是直接修改 fastcgi.conf 文件

  1. nginx
  2. ├─conf
  3. ├─vhost
  4. ├─www.thinkphp.cn.conf
  5. ├─nginx.conf
  6. ├─fastcgi.conf
  7. ├─......
  8. ├─nginx.conf

打开  fastcgi.conf 文件 搜索 open_basedir,把

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

修改为

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

然后重新启动 Nginx 即可生效

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

注意:上面我们修改的时候用的是绝对地址,但是也可以这样直接去找网站根目录(如果你这样配置,你一定要懂不同项目有不同根目录的原理,否则也是行不通的。):

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

上面这行代码拿thinkphp来讲,如果你根目录是public,那么$document_root就会指到public;

依然会生成错误的配置如下:

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

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

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

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

修改为

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

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

由于有很多的朋友用的是“宝塔面板”或“LNMP/LAMP“一键安装包的,设置方法可以看评论!

open_basedir restriction in effect,解决php引入文件权限问题 解决方法的更多相关文章

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

    一.前言 今天在Ubuntu安装了lnmp环境,运行项目的时候出现了,引入500的错误 二.查看错误 再项目文件入口添加,代码显示错误内容,查看到一下错误 ini_set('display_error ...

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

    1.配置了虚拟域名 vim /usr/local/nginx/conf/vhost/siemens.conf server { listen 80; #listen [::]:80 default_s ...

  3. 使用宝塔配置laravel站点时,遇到open_basedir restriction in effect. 原因与解决方法

    今天一位朋友在linux服务器部署thinkphp5的时候PHP报了这个错误,如下: Warning: require(): open_basedir restriction in effect. F ...

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

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

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

    在linux服务器部署thinkphp5的时候PHP报了这个错误, 如下: Warning: require(): open_basedir restriction in effect. File(/ ...

  6. 解决 php 报错 open_basedir restriction in effect或者nginx提示No input file specified怎么办

    解决 php 报错 open_basedir restriction in effect或者nginx提示No input file specified怎么办 问题是出现在了PHP.INI上面了 ,原 ...

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

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

  8. PHPExcel中open_basedir restriction in effect的解决方法

    用PHPExcel做导出execl的时候发现在本地没有问题,但是把网站传到租用的服务器的时候就报错,具体如下: Warning: realpath() [function.realpath]: ope ...

  9. open_basedir restriction in effect. File() is not within the allowed path(s)

    目前发现eaccelerator安装之后如果php.ini中设置open_basedir将导致open_basedir的一些报错(open_basedir restriction in effect. ...

随机推荐

  1. Java之ExceptionHelper工具类

    import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.e ...

  2. 01- ES6、jquery源码、node、webpack

    1.课程介绍 小马哥blog:https://www.cnblogs.com/majj/ 前端学习路径:https://www.processon.com/view/link/5d3a5947e4b0 ...

  3. java常见问题 ——运行报错1

    错误1 打印乱码 相关代码 response.getWriter().print(tbItem.toString()); response.setContentType("text/html ...

  4. JavaWeb-SpringSecurity记住我功能

    系列博文 项目已上传至guthub 传送门 JavaWeb-SpringSecurity初认识 传送门 JavaWeb-SpringSecurity在数据库中查询登陆用户 传送门 JavaWeb-Sp ...

  5. JVM-GC算法(三)-分代收集算法

    对象分类 上次已经说过,分代收集算法是针对对象的不同特性,而使用合适的算法,这里面并没有实际上的新算法产生.与其说分代收集算法是第四个算法,不如说它是对前三个算法的实际应用.  首先我们来探讨一下对象 ...

  6. UFLDL(Unsupervised Feature Learning and Deep Learning)

    UFLDL(Unsupervised Feature Learning and Deep Learning)Tutorial 是由 Stanford 大学的 Andrew Ng 教授及其团队编写的一套 ...

  7. 极光推送报错time_to_live value should be a non-negative integertime_to_live value should be a non-negative integer

    文件中修改

  8. cp复制命令详解

    linux复制指定目录下的全部文件到另一个目录中复制指定目录下的全部文件到另一个目录中文件及目录的复制是经常要用到的.linux下进行复制的命令为cp.假设复制源目录 为 dir1 ,目标目录为dir ...

  9. 理解MVC/MVP/MVVM的区别

    转载至[http://www.ruanyifeng.com/blog/2015/02/mvcmvp_mvvm.html] MVC 所有的通信都是单向的. M(Model)V(View)C(Contro ...

  10. struts2数据处理的几种方式

    package com.loaderman.c_data; import java.util.Map; import javax.servlet.ServletContext; import com. ...