Nginx php-fpm output PHP error log

Source: Internet
Author: User
Tags php error php error log phpinfo

Nginx is a Web server, so the Nginx access log only to access the page records, there will be no PHP error log information.

Nginx to the PHP request to the PHP-FPM fastcgi process to handle, the default PHP-FPM will only output PHP-FPM error message, in PHP-FPM errors log also can not see the errorlog of PHP.

The reason is that the PHP-FPM profile php-fpm.conf The default is to turn off the worker process error output and redirect them directly to/dev/null, so we're in Nginx error log And PHP-FPM's errorlog don't see PHP error logs.

1. To solve the Nginx php-fpm does not log php error logging method:

1. Modify the php-fpm.conf in the configuration does not increase
Catch_workers_output = yes (this I add in the configuration file restart PHP-FPM error, so do not add, do not know why)
Error_log = Log/error_log

2. Modify the configuration in the php.ini, no increase
Log_errors = On
Error_log = "/usr/local/lnmp/php/var/log/error_log"

3. Restart PHP-FPM,
When PHP executes the error, it can see the error log in "/usr/local/lnmp/php/var/log/error_log".

Note the problem:

The Php_admin_value[error_log] parameter in 1.php-fpm.conf overrides the Error_log parameter in php.ini, so make sure that the final phpinfo file you see in Error_log () has writable permissions and the Php_admin_value[error_log] parameter is not set, otherwise the error log is output to the PHP-FPM error log.

The red font led me to error: I was in accordance with the above are configured, but the/var/log/is not generated error_log, and finally manually touch Error_log file, give writable permission on the good, remember the past made such a mistake, do not write down is not. Met and forgot.

2. Unable to find php.ini location, use PHP's phpinfo () results to view.

2. How to modify the PHP error log is not output to the page or screen
Modify PHP.ini
Display_errors = off//does not display error message (not output to page or on screen)
Log_errors = ON//Record error message (saved to log file)
error_reporting = E_all//captures all error messages
Error_log =//Set log file name

Modify the above configuration in the program
Ini_set ("Display_errors", 0)
Ini_set ("error_reporting", E_all); This value seems to be a PHP constant.
Ini_set ("Error_log", "< log file name >")
Ini_set ("Log_errors", 1);

3. How to output the error log of PHP to nginx error log
In PHP 5.3.8 and previous versions, PHP running through fastcgi, errors during user access, will first be written to PHP errorlog
If the PHP errorlog cannot be written, the error content will be returned to the FastCGI interface, and Nginx will be recorded in the Nginx errorlog after receiving the FASTCGI error return.
In PHP 5.3.9 and later versions, after an error, PHP only attempts to write to PHP errorlog, if the failure will not return to fastcgi, the error log will be output to PHP-FPM error log.
Therefore, if you want to output the PHP error log to the Nginx error log, you need to use the previous version of php5.3.8, and the configuration file PHP error_log for the PHP worker process is not writable.

Nginx php-fpm output PHP error log

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.