php报错open_basedir restriction in effect问题和TP5的think-log-viewer

php报错open_basedir restriction in effect问题和TP5的think-log-viewer

小天
2021-08-25 / 0 评论 / 1,130 阅读 / 搜一下 / 正在检测是否收录...

首先说一下think-log-viewer:基于 Thinkphp5 开发的日志浏览组件,该组件提供了一键浏览当前项目日志的功能;然后在使用的时候发现一个问题,本地windows部署系统没有问题,线上linux系统部署报错如下:

[2] ErrorException in Log.php line 40
fopen(): open_basedir restriction in effect. File(/opt/rasp_php72/logs/alarm/alarm.log.2020-08-14) is not within the allowed path(s): (/www/wwwroot/www.xtboke.com/:/tmp/:/proc/)

经过研究,发现是.user.ini文件的问题,一般在根目录,我在用宝塔建站时候,勾选了防跨站攻击(open_basedir)。

解决办法:在.user.ini文件后面追加 :/opt/rasp_php72/logs/,然后重启PHP即可。

扩展:
1.FTP里可能看不到这个文件,需要在SSH远程登陆里修改。

2.ssh方式修改.user.ini权限问题,可用chattr -i .user.ini解除权限。

3.检查logs目录权限,如果没有权限的话,执行 chmod 777 /opt/rasp_php72/logs 增加权限。

8

评论 (0)

打卡
取消