: This article mainly introduces how to configure nginxphp-fpm to output php error logs. if you are interested in PHP tutorials, refer to it. This article introduces how to configure php-fpm to output php error logs on the nginx server. if you are interested, refer to it and hope to help you.
Nginx is only a web server. Therefore, nginx access logs only record access pages and do not contain php error logs.
Nginx sends php requests to the php-fpm fastcgi process for processing. the default php-fpm will only output the error message of php-fpm, the php errorlog cannot be found in the php-fpm errors log.
Cause:
In the configuration file php-fpm.conf of php-fpm, the default is to close the error output of the worker process and redirect them directly to/dev/null, therefore, we cannot see php error logs in nginx error log and php-fpm errorlog.
Solution:
1. add if the configuration in the php-fpm.conf is not modified
Sample code:
Catch_workers_output = yes
Error_log = log/error_log
2. modify the configuration in php. ini. If no configuration exists, add
Sample code:
Log_errors = On
Error_log = "/usr/local/lnmp/php/var/log/error_log"
Error_reporting = E_ALL &~ E_NOTICE
3. restart php-fpm,
When PHP executes an error, the error log is in "/usr/local/lnmp/php/var/log/error_log ".
Note:
1. the php_admin_value [error_log] parameter in the php-fpm.conf will overwrite the error_log parameter in php. ini
Make sure that the final error_log file you see in phpinfo () has the write permission and does not set the php_admin_value [error_log] parameter. Otherwise, the error log will be output to the php-fpm error log.
2. the php. ini location cannot be found. use php phpinfo () to view the result.
3. how to modify PHP error logs not to be output to the page or screen
Modify php. ini
Sample code:
Display_errors = off // no error message is displayed (not output to the page or screen)
Log_errors = on // record error information (saved to the log file)
Error_reporting = E_ALL // capture all error messages
Error_log = // Set the log file name
Modify the above configurations in the program
Sample code:
Ini_set ("display_errors", 0)
Ini_set ("error_reporting", E_ALL); // The value seems to be a PHP constant.
Ini_set ("error_log "," <日志文件名> ")
Ini_set ("log_errors", 1 );
4. how to output php error logs to nginx error logs
In PHP 5.3.8 and earlier versions, PHP running through FastCGI will first be written to the PHP errorlog when an error occurs during user access.
If PHP errorlog cannot be written, the error content will be returned to the FastCGI interface, and then nginx records the error returned to nginx errorlog after receiving the FastCGI error.
In PHP 5.3.9 and later versions, if an error occurs, PHP only attempts to write it to the PHP errorlog. if it fails, it will not return to FastCGI, the error log is output to the php-fpm error log.
If you want to output the php error log to the nginx error log, you must use a version earlier than php5.3.8, and the php error_log in the configuration file cannot be written to the php worker process.
The above describes how to configure nginx php-fpm to output php error logs, including some content. if you are interested in the PHP Tutorial.