nginx與apache不一樣,在apache中可以直接指定php的錯誤日志,那樣在php執行中的錯誤信息就直接輸入到php的錯誤日志中,可以方便查詢。
在nginx中事情就變成了這樣:nginx只對頁面的訪問做access記錄日志。不會有php的error log 信息。nginx把對php的請求發給php-fpm fastcgi進程來處理,默認的php-fpm只會輸出php-fpm的錯誤信息,在php-fpm的errors log里也看不到php的errorlog。
原因是php-fpm的配置文件php-fpm.conf中默認是關閉worker進程的錯誤輸出,直接把他們重定向到/dev/null,所以我們在nginx的error log 和php-fpm的errorlog都看不到php的錯誤日志。
所以我們要進行如下的設置就能查看到nginx下php-fpm不記錄php錯誤日志的方法:
1,修改php-fpm.conf中的配置,如果沒有請增加:
[global]
; Note: the default prefix is /usr/local/php/var
error_log = log/php_error_log
[www]
catch_workers_output = yes
2.修改php.ini中配置,沒有則增加:
log_errors = On
error_log = "/usr/local/php/var/log/error_log"
error_reporting=E_ALL&~E_NOTICE
3.重啟php-fpm
當PHP執行錯誤時就能看到錯誤日志在”/usr/local/lnmp/php/var/log/php_error_log”中了
如果出現:
[root@localhost etc]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm [17-Apr-2014 18:40:52] ERROR: [/usr/local/php/etc/php-fpm.conf:5] unknown entry 'catch_workers_
[17-Apr-2014 18:40:52] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
[17-Apr-2014 18:40:52] ERROR: FPM initialization failed
failed
那請在第一步的時候,認真將配置寫入相對應的組中,不然就出現上面的:
最后看看效果: