關於NGINX下開啟PHP-FPM 輸出PHP錯誤日志的設置(已解決)


最近在本地搭建的LNMP的開發環境。為了開發的時候不影響前端的正常開發就屏蔽的PHP里面php.ini中的一些錯誤提示。但是這樣一來,就影響到了后端開發的一些問題比如不能及時調試開發中的一些問題。

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中的配置,如果沒有請增加:

?
001
002
003
004
005
[global]
; Note: the default prefix is /usr/local/php/var
error_log = log /php_error_log
[www]
catch_workers_output = yes

2.修改php.ini中配置,沒有則增加

?
001
002
003
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”中了

如果出現:
?
001
002
003
004
005
006
[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

那請在第一步的時候,認真將配置寫入相對應的組中,不然就出現上面的:ERROR: [/usr/local/php/etc/php-fpm.conf:5] unknown entry ‘catch_workers_output’

最后看看效果:

php-fpm

 

error

 

轉載自:http://www.pooy.net/nginx-open-php-fpm-error-log.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM