How to configure nginxphp-fpm to output php error logs

Source: Internet
Author: User
Tags php error log
: 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.

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: info-contact@alibabacloud.com 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.