介绍:
记录一次thinkphp项目源码从虚拟机搬到宝塔面板遇到的错误, 设置网站好路径后, 打开页面提示错误
Warning: require(): open_basedir restriction in effect. File(/www/wwwroot/t.wuzhij.com/thinkphp/base.php) is not within the allowed path(s): (/www/wwwroot/t.wuzhij.com/public/:/tmp/) in /www/wwwroot/t.wuzhij.com/public/index.php on line 16
Warning: require(/www/wwwroot/t.wuzhij.com/thinkphp/base.php): failed to open stream: Permission denied in /www/wwwroot/t.wuzhij.com/public/index.php on line 16
Fatal error: require(): Failed opening required '/www/wwwroot/t.wuzhij.com/public/../thinkphp/base.php' (include_path='.:/www/server/php/72/lib/php') in /www/wwwroot/t.wuzhij.com/public/index.php on line 16
下面介绍修复方法:
1. 第1个错误, 是nginx的配置文件配置了open_basedir ,在宝塔面板的网站域名配置页→网站目录中, 关闭防跨站攻击就能解决
2. 关闭后会出现下面的2个错误, 提示表示系统无法访问或打开指定的文件 `/www/wwwroot/t.wuzhij.com/thinkphp/base.php`,通常是因为权限设置不正确。可以通过 SSH 登录您的服务器,并运行以下命令来更改权限:
cd /www/wwwroot/域名根目录
find thinkphp -type d -exec chmod 755 {} \;
find thinkphp -type f -exec chmod 644 {} \;
ls -l /www/wwwroot/域名根目录/thinkphp/
chown -R www:www /www/wwwroot/域名根目录/thinkphp/
输入完, 再次访问网站就恢复正常了。
📌 小提示:
修改thinkphp目录路径
/www/wwwroot/域名根目录/thinkphp 修改成自己的网站路径。(命令用的手机termius应用)
命令参考:
正常访问: