如下:

出现问题的原因:

查看问题描述以及资料,发现是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. Error from server (ServiceUnavailable): the server is currently unable to handle the request

    grep image /root/kubernetes-metrics-server/kubernetes-metrics-server/metrics-server-deployment.yaml ...

  2. mybatis insert into 返回id

    <insert id="saveComplaint" useGeneratedKeys="true" parameterType="com.fo ...

  3. Prism框架的Regions使用

    Prism框架的Regions,可以把用户控件.窗体等附加到主窗体指定的控件中. [实战1] 1.新建Prism Blank App(WPF) 项目:Demo0810 Views文件夹处,鼠标右键—— ...

  4. xml配置文件 操作

    public class ConfigFile { protected readonly string configBasePath = "Root/Config"; /// &l ...

  5. 《剑指offer》算法题第六天

    今日题目: 顺时针打印矩阵 包含min函数的栈 栈的压入.弹出序列 从上到下打印二叉树 二叉树搜索树的后序遍历序列 二叉树中和为某一值的路径 今天的题目都比较简单,下面一一介绍: 1. 顺时针打印矩阵 ...

  6. java输出乱码专题

    https://blog.csdn.net/liaoYu1887/article/details/82714727(其他) @Controller public class ItemCatContro ...

  7. elastic search&logstash&kibana 学习历程(一)es基础环境的搭建

    elastic search 6.1.x 常用框架: 1.Lucene Apache下面的一个开源项目,高性能的.可扩展的工具库,提供搜索的基本架构: 如果开发人员需用使用的话,需用自己进行开发,成本 ...

  8. Paint the Digits

    C - Paint the Digits 思路:这道题就只需要利用单调栈,将整个数组扫一遍,求得的最后的栈内元素(要求全部小于非栈内元素)的颜色为1,其余为2 那么怎么实现呢?求最后的栈内元素(要求全 ...

  9. template模板循环嵌套循环

    template嵌套循环写法:在第一次循环里面需要循环的地方再写个循环,把要循环的数据对象改为第一层的循环对象别名 //template模板循环嵌套循环 <script id="ban ...

  10. Java官方操纵byte数组的方式

    java官方提供了一种操作字节数组的方法——内存流(字节数组流)ByteArrayInputStream.ByteArrayOutputStream ByteArrayOutputStream——by ...