在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. 11.python3标准库--使用进程、线程和协程提供并发性

    ''' python提供了一些复杂的工具用于管理使用进程和线程的并发操作. 通过应用这些计数,使用这些模块并发地运行作业的各个部分,即便是一些相当简单的程序也可以更快的运行 subprocess提供了 ...

  2. NGUI优化之Drawcall

    今天在运行之前的程序时,无意中发现一个简单的menu菜单页面drawcall居然达到接近30了,这个数值感觉太高了. 后网上查询关于降低drawcall的方法,发现主要有以下几点: 1.少用Panel ...

  3. html清屏 meta http-equiv="refresh" content="3">

    <meta http-equiv="refresh" content="3"> 什么意思? <meta http-equiv="re ...

  4. struct中长度为0的数组用途与原理

    前言 在标准C和C++中,长度为0的数组是被禁止使用的.不过在GNUC中,存在一个非常奇怪的用法,那就是长度为0的数组,比如Array[0]; 很多人可能觉得不可思议,长度为0的数组是没有什么意义的, ...

  5. csu 1329 一行盒子(链表操作)

    1329: 一行盒子 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 693  Solved: 134 [Submit][Status][Web Boa ...

  6. 教你如何更改android应用的包名

    Android 源码自带了很多应用程序,想改个包名方便修改?很简单,两步搞定,以packages/apps/Settings为例: 1.打开AndroidManifest.xml,把 <mani ...

  7. day5 常用模块json和pickle

    json 和 pickle json和pickle是用于字符串序列化和反序列化的过程,我们在存储和使用的时候,经常把列表存入文件,读取的时候我们还想以列表的形式读取.就需要使用json和pickle. ...

  8. 第 18 章 Django 入门

    当今的网站实际上都是富应用程序(rich application),就像成熟的桌面应用程序一样.Python提供了一组开发Web应用程序的卓越工具.在本章中,我们将学习如何使用Django(http: ...

  9. HTML5 Canvas游戏开发(一)基础知识

    一.绘制基本图形 在每次用canvas画布时,都有几步是“套路” 1.在HTML中创建Canvas画布: <canvas id="mycanvas" width=" ...

  10. java.lang.ClassCastException: android.widget.ImageButton异常处理

    在调程序时总是出现异常关闭的现象,log显示: 03-26 07:58:09.528: E/AndroidRuntime(398): Caused by: java.lang.ClassCastExc ...