关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

ThinkPHP 显示 Failed opening required ‘/home/wwwroot/xxxxxx/public/../thinkphp/start.php’

发布时间:2022/11/16 15:36:13
香港云服务器

今天在添加一个基于 ThinkPHP5 的网站程序时,访问首页时遇到了一个错误:

Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/xxxxxx/thinkphp/start.php) is not within the allowed path(s): (/home/wwwroot/xxxxxx/public/:/tmp/:/proc/) in /home/wwwroot/xxxxxx/public/index.php on line 17

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

Fatal error: require(): Failed opening required ‘/home/wwwroot/xxxxxx/public/../thinkphp/start.php’ (include_path=’.:/usr/local/php/lib/php’) in /home/wwwroot/xxxxxx/public/index.php on line 17

开发环境:

  1. PHP 版本:PHP7
  2. 安装方式:LNMP 一键包:Linux 一键安装 Nginx + MySQL + PHP 环境

问题原因:open_basedir 里没有包含到 public 这个路径。

解决办法:在 /usr/local/nginx/conf/ 目录在找到 fastcgi.conf,关于 open_basedir 默认的配置应该是:

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";

修改成:

fastcgi_param PHP_ADMIN_VALUE "open_basedir=/home/wwwroot/:/tmp/:/proc/";

之后重启 LNMP,再访问网站就没有这个问题了,最后记得将 PHP 调试模式关闭