ThinkPHP 5 部署在了LAMP/LNMP 环境上很有可能出现 Error 500 的情况,这个时候需要开启 php 错误提示来判断是否是因为设置了open_basedir 选项出错。
开启错误提示:
打开 php.ini 搜索 display_errors,把 Off 修改为 On 就开启了 php 错误提示 。
lnmp 的 php.ini 位置在/usr/local/php/etc/php.ini
再次访问首页显示错误提示
Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/spider.guofeng.io/public/../thinkphp/start.php) is not within the allowed path(s): (/home/wwwroot/spider.guofeng.io/public/:/tmp/:/proc/) in /home/wwwroot/spider.guofeng.io/public/index.php on line 17 Warning: require(/home/wwwroot/spider.guofeng.io/public/../thinkphp/start.php): failed to open stream: Operation not permitted in /home/wwwroot/spider.guofeng.io/public/index.php on line 17 Fatal error: require(): Failed opening required '/home/wwwroot/spider.guofeng.io/public/../thinkphp/start.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/spider.guofeng.io/public/index.php on line 17
解决方案
首先尝试通过修改 php.ini 解决
把权限作用域由入口文件目录修改为框架根目录
打开 php.ini 搜索 open_basedir,
如有,把
open_basedir = "/home/wwwroot/xx/public/:/tmp/:/var/tmp/:/proc/"
修改为
open_basedir = "/home/wwwroot/xx/:/tmp/:/var/tmp/:/proc/"
如果你的 php.ini 文件的 open_basedir 设置选项是被注释的或者为 none,那么你需要尝试通过 Apache 或者 Nginx 来修改。
LAMP(Apache)修改方案
Apache 需要修改 httpd.conf 或者同目录下的 vhost 目录下 xx.conf 文件,如果你的生成环境是 LAMP 一键安装包配置,那么多半就是直接修改 你的域名 .conf 文件
打开 你的域名.conf文件 搜索 open_basedir,把
php_admin_value open_basedir "/home/wwwroot/www.thinkphp.cn/public/:/tmp/:/var/tmp/:/proc/"
修改为
php_admin_value open_basedir "/home/wwwroot/www.thinkphp.cn/:/tmp/:/var/tmp/:/proc/"
然后重新启动 apache 即可生效
域名.conf 文件通常是在 /usr/local/apache/conf
目录中,当然了这取决于你 LAMP 环境配置
LNMP(Nginx) 修改方法
Nginx 需要修改 nginx.conf 或者 conf/vhost 目录下 你的域名 .conf 文件,如果你的生成环境是 LNMP/LTMP 一键安装包配置那么多半就是直接修改 你的域名 .conf 文件
打开 你的域名.conf 文件 搜索 open_basedir,把
fastcgi_param PHP_VALUE "open_basedir=/home/wwwroot/www.thinkphp.cn/public/:/tmp/:/proc/";
修改为
fastcgi_param PHP_VALUE "open_basedir=/home/wwwroot/www.thinkphp.cn/:/tmp/:/proc/";
然后重新启动 Nginx 即可生效
域名 .conf 文件通常是在 /usr/local/nginx/conf/vhost
目录中,当然了这取决于你 LNMP/LTMP 环境配置
fpm/fastcgi user.ini 修改方法
打开 项目根目录下找到 .user.ini 文件,搜索 open_basedir , 把
open_basedir=/home/wwwroot/www.thinkphp.cn/public/:/tmp/:/proc/
修改为
open_basedir=/home/wwwroot/www.thinkphp.cn/:/tmp/:/proc/
然后重新启动 web 服务器 即可生效 (文件如无法修改使用 chattr -i .user.ini)
如果错误还存在,查看 /usr/local/nginx/conf 目录下是否存在 fastcgi.conf
打开该文件查找 open_basedir,如果则先注释掉。
再次打开网站首页,可以显示了。