在使用宝塔面板的服务器中修改open_basedir配置

服务器配置

阿里云学生主机,Centos 7.2 64位,安装了宝塔面板5.8.7,nginx1.12+php5.6+mysql5.5

遇到的问题

做了一个下载网站,使用阿里云CDN进行下载加速。
自己的服务器上有两个站点,主站A和CDN回源站点B
主站A在服务器上的web根目录为/www/wwwroot/A/
回源站点B的web根目录为/www/wwwroot/B/

主站A使用php5开发,当有文件上传时,经过安全验证的文件要移动到站点B的data目录中。
使用php中的函数move_uploaded_file()移动上传的文件到B/data/目录中时报错,信息如下:

move_uploaded_file(): open_basedir restriction in effect. 
File(/www/wwwroot/B/data/xxxxxxxx.txt) is not within the allowed path(s): 
(/www/wwwroot/A/:/tmp/:/proc/)

解决方法

/www/wwwroot/B/data/添加到站点A的open_basedir设置中即可。
无奈不知道open_basedir在哪里设置的

执行grep -r "open_basedir" /etc/ 搜索无果
又执行grep -r "open_basedir" /www/

查找到的部分内容如下:

/www/wwwroot/A/.user.ini:open_basedir=/www/wwwroot/A/:/tmp/:/proc/
/www/wwwroot/B/.user.ini:open_basedir=/www/wwwroot/B/:/tmp/:/proc/

原来配置文件是隐藏文件.user.ini
打开A的.user.ini
改成 user.ini:open_basedir=/www/wwwroot/A/:/tmp/:/proc/:/www/wwwroot/B/data/
保存,重启nginx。

你可能感兴趣的:(在使用宝塔面板的服务器中修改open_basedir配置)