需要說明的是,環境配置成功後,網站已經可以訪問了,由於我的根目錄直接指定到public的,因此,public下的其它txt文档,ico圖標都可以訪問,我也新建了一個phpinfo.php文档,同樣也可以訪問。只有訪問index.php的時候才出現“http error 500";
500:服務器内部錯誤,原因也很多!
一、首先我先檢查環境
php和nginx都是啓動正常,而且php和nginx日志都沒有報任何的錯誤;從而說明不是php和nginx的原因;
二、重新修改nginx.conf根目錄位置:
記住,這裡修改時,一定不要把根目錄定到public下,因爲有時候直接定到public也有一些問題,具體爲什麽我也不知道;經驗吧!
server{ listen 80 default_server; #listen [::]:80 default_server ipv6only=on; server_name _; index index.html index.htm index.php; root /home/wwwroot/www.test.com; ...... }
注意:一定要重啓nginx;
三、php.ini 開啓錯誤調試
由於我的日志不報任何錯誤,而且打開index.php也不報任何錯誤,只報500,這怎麽能行?不知道錯誤又如何解決問題呢?
打開php.ini,在合適位置添加“display_errors:On”
display_errors:On ; display_errors ; Default Value: On ; Development Value: On ; Production Value: Off
注意:一定要重啓php,php.ini配置才會生效。
四、再次訪問index.php出現:
“scandir() has been disabled for security reasons”;
解決“scandir() has been disabled for security reasons”方法:
出現這個問題,那是因爲php禁用了scandir()這個函數,我們只需要不禁用它即可。
可以通過查看phpinfo(),確認scandir()函數是否被禁用?
禁用scandir()
1、打開php.ini,一般默認位置是在/usr/local/php/etc/php.ini
2、找到“disable_functions”,並刪除後面的“scandir”;
scandir
3、保存並退出,重啓php-fpm即可!
五、測試訪問index.php
再次去訪問“http://www.wk139.cn/tp5/public/index.php”已經成功!