首页 » php » thinkphp 5.0 lnmp环境下 Warning: require(): open_basedir restriction in effect. File 报错处理

thinkphp 5.0 lnmp环境下 Warning: require(): open_basedir restriction in effect. File 报错处理

 

默认的TP 是把index.php 放在public目录下的;

所以nginx的vhost配置文件得做如下修改:

[root@localhost lnmp1.4]# vim /usr/local/nginx/conf/vhost/xxx.abczn.com.conf

#注意红色部分

server
{
listen 80;
#listen [::]:80;
server_name xxx.abczn.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/xxx.abczn.com/public;

include other.conf;
#error_page 404 /404.html;

# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*.php$ { deny all; }

include enable-php-pathinfo.conf;

location ~ /
{
try_files $uri $uri/ /index.php?s=$uri&$args;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*.(js|css)?$
{
expires 12h;
}

location ~ /.well-known {
allow all;
}

location ~ /.
{
deny all;
}
error_log /home/wwwlogs/xxx.abczn.com.error.log;
access_log off;
}

 

不出意外的话,访问页面会提示
Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/xxx.abczn.com/thinkphp/start.php) is not within the allowed path(s): (/home/wwwroot/xxx.abczn.com/public/:/tmp/:/proc/) in /home/wwwroot/xxx.abczn.com/public/index.php on line 18

Warning: require(/home/wwwroot/xxx.abczn.com/thinkphp/start.php): failed to open stream: Operation not permitted in /home/wwwroot/xxx.abczn.com/public/index.php on line 18

Fatal error: require(): Failed opening required '/home/wwwroot/xxx.abczn.com/public/../thinkphp/start.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/xxx.abczn.com/public/index.php on line 18

 

 

这个时候需要在php.ini下面添加如下内容

;注:红色部分替换成你对应的域名和目录

[HOST=xxx.abczn.com]
open_basedir=/home/wwwroot/
xxx.abczn.com:/tmp/:/proc/
[PATH=/home/wwwroot/
xxx.abczn.com]
open_basedir=/home/wwwroot/
xxx.abczn.com:/tmp/:/proc/

 

欢迎大家加入我们的QQ群:307469859

原文链接:thinkphp 5.0 lnmp环境下 Warning: require(): open_basedir restriction in effect. File 报错处理,转载请注明来源!

0