使用宝塔配置laravel站点时,遇到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
或者报如下类似:
Warning: include_once(): open_basedir restriction in effect. File(../../staticpayb/WxPay.Config) is not within the allowed path(s):
出现问题的原因:
查看问题描述以及资料,发现是php open_basedir 配置的问题,PHP不能引入其授权目录上级及其以上的文件;
一般情况下是不会出现这种问题的,之所以出现这个问题绝大多数情况是由于服务器的原因,为了安全才做了这样的限制!
解决方法:
我首先要申明的是,下面的方法适合所有类似PHP报“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 一键安装包配置那么多半就是直接修改 你的域名.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 环境配置
注意:上面我们修改的时候用的是绝对地址,但是也可以这样直接去找网站根目录(如果你这样配置,你一定要懂不同项目有不同根目录的原理,否则也是行不通的。):
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 服务器 即可生效!
宝塔面板出现“open_basedir restriction in effect. ”的解决方法
1、只需要在相应的网站目录,勾选掉防跨站攻击(open_basedir)即可!
2、必须重启PHP;
使用宝塔配置laravel站点时,遇到open_basedir restriction in effect. 原因与解决方法的更多相关文章
- 宝塔部署时,出现“open_basedir restriction in effect”错误
下面是错误代码: Warning: require(): open_basedir restriction in effect. Warning: require(XXXXXXXXXXX): fail ...
- tcp连接时,BROKEN PIPE错误的原因以及解决方法
问题: 写了一个server和一个client,UNIX套接字的,server不断接收消息并打印出来,client是一个交互程序,输入一个消息回车发送,接着又可以输入消息.出问题了:当server监听 ...
- apt-get update 更新 ubuntu时出现Hash sum mismatch的原因及解决方法
$ sudo apt-get update ...... Hit http://mirrors.163.com trusty/main Sources ...
- java写文件时,输出不完整的原因以及解决方法
在java的IO体系中,写文件通常会用到下面语句 BufferedWriter bo=new BufferedWriter(new FileWriter("sql语句.txt")) ...
- java写文件时,输出不完整的原因以及解决方法close()或flush()
在java的IO体系中,写文件通常会用到下面语句 BufferedWriter bw=new BufferedWriter(new FileWriter("sql语句.txt")) ...
- 鼠标聚焦到Text输入框时,按回车键刷新页面原因及解决方法
前提 一个form中只有一个输入框,当输入框获取焦点后,点击回车,导致整个页面都刷新,问题解决办法. 1.处理form 在form中添加事件 <form onsubmit="retu ...
- 鼠标聚焦到Input输入框时,按回车键刷新页面原因及解决方法
参考地址:http://blog.csdn.net/xuezhongsong/article/details/6859037 方式1:全局控制回车,13-回车键,27-ESC,113-F2 docum ...
- libevent在windows下用visual studio编译时出现error C2894错误的原因与解决方法
libevent是一个使用很广泛的网络库,今天想了解下它.于是去git clone了一份源码,用vs2005的命令行:nmake -f makefile.nmake编译之,顺利编译通过,生成三个静态库 ...
- lnmp环境运行laravel open_basedir restriction in effect 问题
环境配置:centos 7 : php 7.1.5 Warning: require(): open_basedir restriction in effect. File(/home/wwwroot ...
随机推荐
- JUC 并发编程--09, 阻塞队列: DelayQueue, PriorityBlockingQueue ,SynchronousQueue, 定时任务线程池: ScheduledThreadPoolExecutor
先看DelayQueue 这个是用优先级队列实现的无界限的延迟队列,直接上代码: /** * 这个是 {@link DelayQueue} 延时队列 的验证使用类 */ class MyDelayed ...
- 简单测试 APISIX2.6 网关
Apache APISIX是一个动态的.实时的.高性能的 API 网关.它提供丰富的流量管理功能,例如负载均衡.动态上游服务.金丝雀发布.断路.身份验证.可观察性等.您可以使用 Apache APIS ...
- Linkerd 2.10(Step by Step)—4. 如何配置外部 Prometheus 实例
Linkerd 2.10 系列 快速上手 Linkerd v2 Service Mesh(服务网格) 腾讯云 K8S 集群实战 Service Mesh-Linkerd2 & Traefik2 ...
- sentinel (史上最全+入门教程)
文章很长,建议收藏起来,慢慢读! 高并发 发烧友社群:疯狂创客圈 为小伙伴奉上以下珍贵的学习资源: 疯狂创客圈 经典图书 : 极致经典 < Java 高并发 三部曲 > 面试必备 + 大厂 ...
- Java将字符串反转的7种方法
/方法1 递归方法 public static String reverse1(String s) { int length = s.length(); if(length <= 1){ ret ...
- 详解apollo的设计与使用
简介 apollo 是一款由携程团队开发的配置中心,可以实现配置的集中管理.分环境管理.即时生效等等.在这篇博客中,我们可以了解到: 为什么使用配置中心 如何设计一个配置中心 apollo 是如何设计 ...
- 「10.28」Dove 打扑克(链表)·Cicada 与排序(概率)·Cicada 拿衣服(各种数据结构)
A. Dove 打扑克 考场思考半天线段树树状数组,没有什么想法 打完暴力后突然想到此题用链表实现会很快. 因为只有$n$堆,所以设最多有$x$个不同的堆数,那么$x\times (x-1)/2==n ...
- 手写Spring Config,最终一战,来瞅瞅撒!
上一篇说到了手写Spring AOP,来进行功能的增强,下面本篇内容主要是手写Spring Config.通过配置的方式来使用Spring 前面内容链接: 我自横刀向天笑,手写Spring IOC容器 ...
- springboot bean的循环依赖实现 源码分析
springboot bean的循环依赖实现 源码分析 本文基于springboot版本2.5.1 <parent> <groupId>org.springframework. ...
- 从谭浩强的《C语言程序设计》到《电容应用分析精粹》
不记得具体从什么时候开始(反正很多年前的事了)的,不少人都陆续批评过谭浩强的<C语言程序设计>,各方面都有扒过.例如,与实践脱节,很多例子在不同编译器上运行是错误的,代码风格糟糕等等方面. ...