lnmp环境 open_basedir restriction in effect 错误解决

在Linux CentOS 6.7上使用PHP 5.6.15和nginx 1.10.1的开发环境中,遇到open_basedir restriction in effect错误。错误发生在尝试require()文件时。解决方案包括检查php.ini文件中open_basedir的设置,并在nginx配置文件中添加相应的SCRIPT_FILENAME和open_basedir设置,重启nginx服务后问题得到解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、开发环境:

Linux  CentOS 6.7
PHP 5.6.15 
nginx 1.10.1

二、问题描述

项目访问的时候报如下错误:

Warning : require(): open_basedir restriction in effect. File(/data/www/basic/vendor/autoload.php) is not within the allowed path(s): (/data/www/basic/web/:/tmp/:/proc/) in  /data/www/basic/web/index.php  on line  5

Warning : require(/data/www/basic/vendor/autoload.php): failed to open stream: Operation not permitted in  /data/www/basic/web/index.php  on line  5

Fatal error : require(): Failed opening required '/data/www/basic/web/../vendor/autoload.php' (include_path='.:/php/includes') in  /data/www/basic/web/index.php  on line  5


三、问题解决

1、nginx错误日志显示,访问脚本不在 open_basedir的限定目录里面,配置open_basedir 一般会在php.ini 或 nginx 配置文件里面。


2、首先检测php.ini 我发现并没有配置 open_basedir 。


3、然后检测nginx配置,在nginx配置文件 nginx.conf 添加

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

4、在nginx项目配置文件中添加
set $basedir "open_basedir= $document_root :/tmp/:/proc/:/php/includes/:/home";

$document_root 为网站目录,例如,网站目录 /data/ www /blog,应该配置成如下:
set $basedir "open_basedir= /data/ www/blog:/tmp/:/proc/:/php/includes/:/home";

配置完之后重启nginx即可



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值