open_basedir restriction in effect 错误解决方案

Lnmp部署时发生 Unknown: open_basedir restriction in effect 错误解决方案

Posted on 2017-11-07 17:25:34 in Nginx, PHP   阅读(6315)

日志报错信息

2017/11/06 15:39:54 [error] 398#0: *4 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: open_basedir restriction in effect. File(/home/wwwroot/chenyanjin.tk/myBlog/public/index.php) is not within the allowed path(s): (/home/wwwroot/default/:/tmp/:/proc/) in Unknown on line 0 PHP message: PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0 Unable to open primary script: /home/wwwroot/chenyanjin.tk/myBlog/public/index.php (Operation not permitted)" while reading response header from upstream, client: 124.205.124.218, server: chenyanjin.tk, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.sock:", host: "www.chenyanjin.tk"

错误解决及分析

经过简单百度 google 后, 发现是 open_basedir 配置需要更改。修改为部署网站的目录或者父目录,如当前错误,我的网站文件在 /home/wwwroot/chenyanjin.tk
原来为open_basedir=/home/wwwroot/default/:/tmp/:/proc/
修改为 open_basedir=/home/wwwroot/:/tmp/:/proc/

两种解决方案

  1. 修改 php.ini 的 open_basedir
  2. 修改 nginx 的 conf/fastcgi.conf 的 open_basedir

参考链接