open_basedir restriction in effect,解决php引入文件权限问题 解决方法
如下:
出现问题的原因:
查看问题描述以及资料,发现是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,把
- 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 一键安装包配置那么多半就是直接修改 fastcgi.conf 文件
- nginx
- ├─conf
- ├─vhost
- ├─www.thinkphp.cn.conf
- ├─nginx.conf
- ├─fastcgi.conf
- ├─......
- ├─nginx.conf
打开 fastcgi.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 即可生效
fastcgi.conf 文件通常是在 /usr/local/nginx/conf/ 目录中,当然了这取决于你 LNMP/LTMP 环境配置
注意:上面我们修改的时候用的是绝对地址,但是也可以这样直接去找网站根目录(如果你这样配置,你一定要懂不同项目有不同根目录的原理,否则也是行不通的。):
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
上面这行代码拿thinkphp来讲,如果你根目录是public,那么$document_root就会指到public;
依然会生成错误的配置如下:
- fastcgi_param PHP_VALUE "open_basedir=/home/wwwroot/www.thinkphp.cn/public/:/tmp/:/proc/";
四、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 服务器 即可生效!
由于有很多的朋友用的是“宝塔面板”或“LNMP/LAMP“一键安装包的,设置方法可以看评论!
open_basedir restriction in effect,解决php引入文件权限问题 解决方法的更多相关文章
- open_basedir restriction in effect,解决php引入文件权限问题
一.前言 今天在Ubuntu安装了lnmp环境,运行项目的时候出现了,引入500的错误 二.查看错误 再项目文件入口添加,代码显示错误内容,查看到一下错误 ini_set('display_error ...
- open_basedir restriction in effect,解决php引入文件权限问题 lnmp
1.配置了虚拟域名 vim /usr/local/nginx/conf/vhost/siemens.conf server { listen 80; #listen [::]:80 default_s ...
- 使用宝塔配置laravel站点时,遇到open_basedir restriction in effect. 原因与解决方法
今天一位朋友在linux服务器部署thinkphp5的时候PHP报了这个错误,如下: Warning: require(): open_basedir restriction in effect. F ...
- php错误提示 open_basedir restriction in effect 解决
<VirtualHost *:80> DocumentRoot "D:/www/4w_raaaa_com_2017" ServerName www.raaaa.com: ...
- require(): open_basedir restriction in effect. 解决方法
在linux服务器部署thinkphp5的时候PHP报了这个错误, 如下: Warning: require(): open_basedir restriction in effect. File(/ ...
- 解决 php 报错 open_basedir restriction in effect或者nginx提示No input file specified怎么办
解决 php 报错 open_basedir restriction in effect或者nginx提示No input file specified怎么办 问题是出现在了PHP.INI上面了 ,原 ...
- LNMP - Warning: require(): open_basedir restriction in effect错误解决方法
LNMP 1.4或更高版本如果不想用防跨目录或者修改.user.ini的防跨目录的目录还需要将 /usr/local/nginx/conf/fastcgi.conf 里面的fastcgi_param ...
- PHPExcel中open_basedir restriction in effect的解决方法
用PHPExcel做导出execl的时候发现在本地没有问题,但是把网站传到租用的服务器的时候就报错,具体如下: Warning: realpath() [function.realpath]: ope ...
- 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. ...
随机推荐
- Mac常用设置备忘
1.显示隐藏文件 1>命令行方式 显示:defaults write com.apple.finder AppleShowAllFiles -bool true 隐藏:defaults writ ...
- gitlab断电
断电重启以后 会出现2019-06-26_05:47:42.71382 HINT: If you're sure there are no old server processes still run ...
- jsp模糊查询
模板 查询之前: 查询之后: jsp的<script>: $(".inp2").click(function(){ var s=$(".inp"). ...
- 第十一章 前端开发-JavaScript
第十一章 前端开发-JavaScript 11.3.1 js引入方式 行内样式 <p id="" class="" style="" ...
- ant-design-vue 报错 ReferenceError: h is not defined
使用表格,在配置 columns时用到了 customRender,然后就报错了 <script> import FileName from '@/views/admin/document ...
- Python身份运算符
运算符 描述 实例 is is 是判断两个标识符是不是引用自一个对象 x is y, 类似 id(x) == id(y) , 如果引用的是同一个对象则返回 True,否则返回 False is not ...
- hive连接hbase
使用hive连接hbase 前提说明:一个hive表指向一个hbase表,一对一,不能多对一 建立外部表 CREATE EXTERNAL TABLE test_hbase( key string, m ...
- (四)C语言之函数
- 黑马在线教育项目---15-16、datatables插件
黑马在线教育项目---15-16.datatables插件 一.总结 一句话总结: datatables插件也比较好用,引入好插件的js和css后,核心代码也就是插件的初始化,如果要修改配置可以百度 ...
- VS Code 调试 Golang 出现 Failed to continue: Check the debug console for details
VS Code断点调试Golang时候,弹出提示:Failed to continue: Check the debug console for details 点击Open launch.json, ...