Home  >  Article  >  Backend Development  >  nginx php-fpm output php error log

nginx php-fpm output php error log

angryTom
angryTomforward
2019-10-15 16:16:183556browse

nginx php-fpm output php error log

nginx is a web server, so the access log of nginx only records the accessed pages, and there will be no error log information of php.

nginx sends the request for php to the php-fpm fastcgi process for processing. The default php-fpm will only output the error message of php-fpm, and php cannot be seen in the errors log of php-fpm. The reason for the errorlog

is that the php-fpm configuration file php-fpm.conf defaults to turning off the error output of the worker process and redirecting them directly to /dev/null, so we use nginx’s error log and The error log of php-fpm cannot be seen in the error log of php.

Debugging is very painful. Ways to solve the problem that php-fpm does not record php error logs under nginx:

1. Modify the configuration in php-fpm.conf and add

catch_workers_output = yes
error_log = log/error_log

2. Modify the configuration in php.ini, if not, add

log_errors = On
error_log = "/usr/local/lnmp/php/var/log/error_log"
error_reporting=E_ALL&~E_NOTICE

3. Restart php-fpm
You can see it when PHP execution errors The error log is in "/usr/local/lnmp/php/var/log/error_log"

Please note:

1. php-fpm.conf The php_admin_value[error_log] parameter in php.ini will override the error_log parameter in php.ini
So make sure the final error_log file you see in phpinfo() has writable permissions and does not set the php_admin_value[error_log] parameter, otherwise the error log will Output to the error log of php-fpm.

2. The location of php.ini cannot be found, use php's phpinfo() to view the results

3. How to modify the PHP error log not to be output to the page or screen
Modify php.ini

display_errors = off //不显示错误信息(不输出到页面或屏幕上)
log_errors = on //记录错误信息(保存到日志文件中)
error_reporting = E_ALL //捕获所有错误信息
error_log = //设置日志文件名

Modify the above configuration in the program

ini_set("display_errors",0)
ini_set("error_reporting",E_ALL); //这个值好像是个PHP的常量
ini_set("error_log","<日志文件名>")
ini_set("log_errors",1);

4. How to output the php error log to the nginx error log
In PHP 5.3.8 and earlier versions, when PHP runs through FastCGI and an error occurs during user access, it will first be written to PHP's errorlog.
If PHP's errorlog cannot be written, the error content will be returned. Give the FastCGI interface, and then nginx records it in the nginx errorlog after receiving the error return from FastCGI
In PHP 5.3.9 and later versions, PHP only tries to write to the PHP errorlog after an error occurs. If it fails, There will no longer be a return to FastCGI, the error log will be output to the error log of php-fpm.
So if you want to output the php error log to the nginx error log, you need to use a version before php5.3.8, and the error_log of php in the configuration file is not writable by the php worker process.

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of nginx php-fpm output php error log. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete