php版本是 7.1.18
tp5.1.16 本地環境運行正常
目前在centos 7.0的虛擬機上成功安裝了以上軟件。
訪問500錯誤
1、加上錯誤日志,看一下錯誤信息
在/usr/local/nginx/conf/yourdomain.com.conf
文件中的 access_log 下面加上一段代碼,文件名隨意
error_log /home/wwwlogs/yourdomain.com_error.log notice;
訪問一遍你的域名地址,重現一下錯誤,然后我們來看錯誤日志~如果沒有文件,可能是沒有寫權限,手動創建后重試
錯誤類似於下面這樣
[error] 31194#0: *21 FastCGI sent in stderr: "PHP message: PHP Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/yourdomain.com/tp5/thinkphp/base.php) is not within the allowed path(s): (/home/wwwroot/yourdomain.com/tp5/public/:/tmp/:/proc/) in /home/wwwroot/yourdomain.com/tp5/public/index.php on line 16 PHP message: PHP Warning: require(/home/wwwroot/yourdomain.com/tp5/thinkphp/base.php): failed to open stream: Operation not permitted in /home/wwwroot/yourdomain.com/tp5/public/index.php on line 16 PHP message: PHP Fatal error: require(): Failed opening required '/home/wwwroot/yourdomain.com/tp5/public/../thinkphp/base.php'
看了一眼就盯上這個open_basedir
玩意,它是用來設置防跨目錄的,記得在文檔上看到過,原文如下:
在 Thinkphp、codeigniter、Laravel 等框架下,網站目錄一般是在 public 下,但是 public 下的程序要跨目錄調用 public 上級目錄下的文件
因為 LNMP 默認是不允許跨目錄訪問的,所以都是必須要將防跨目錄訪問的設置去掉,所以有時候這些框架類的程序提示 500 錯誤也可能是這個問題引起的
OK,因為安裝的是 1.5 版本的,所以直接使用lnmp1.5/tools/
目錄下的./remove_open_basedir_restriction.sh
進行移除
其他版本具體操作如下:
LNMP 1.4 上如果不想用防跨目錄或者修改.user.ini
的防跨目錄的目錄還需要將/usr/local/nginx/conf/fastcgi.conf
里面的fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
在該行行前添加 # 或刪除改行,需要重啟 Nginx
LNMP 1.4 上就可以直接使用lnmp1.4/tools/
目錄下的./remove_open_basedir_restriction.sh
進行移除
平滑重載一下 Nginx 服務,訪問頁面看到了熟悉的 ThinkPHP 初始頁面,搞定正常可以訪問