[Consolidate PHP Basics] nginx php-fpm outputs the php Error Log, nginxphp-fpm

Source: Internet
Author: User

[Consolidate PHP Basics] nginx php-fpm outputs the php Error Log, nginxphp-fpm

Address of this Article

Original article address

Sharing outline:

1. Overview

2. solution (solve the problem that php-fpm does not record php error logs in nginx)

 

1. Overview  

Nginx is 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.

The reason is that in the php-fpm configuration file php-fpm.conf, the default is to close the error output of the worker process, directly redirect them to/dev/null, therefore, we cannot see php error logs in nginx error log and php-fpm errorlog.

Debugging is very painful. Solution to the problem that php-fpm does not record php error logs in nginx

 

2. solution (php-fpm under nginx does not record php error logs)  

2.1) [modify the configuration in the php-fpm.conf]

Add if no
Catch_workers_output = yes
Error_log = log/error_log

2.2) modify the configuration in php. ini

Add if no
Log_errors = On
Error_log = "/usr/local/lnmp/php/var/log/error_log"
Error_reporting = E_ALL &~ E_NOTICE

2.3) Restart php-fpm
When PHP executes an error, the error log is in "/usr/local/lnmp/php/var/log/error_log ".

 

2.4) Please note

A) [parameter priority]

The php_admin_value [error_log] parameter in the php-fpm.conf overwrites 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.

B) [php. ini location]

The php. ini location cannot be found. Use php phpinfo () to view the result.

C) [Do Not Display errors]

How to modify PHP Error Log not to output to page or screen
Modify php. ini
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
Ini_set ("display_errors", 0)
Ini_set ("error_reporting", E_ALL); // The value seems to be a PHP constant.
Ini_set ("error_log", "<Log File Name> ")
Ini_set ("log_errors", 1 );

D) [incorrect calendar output]

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.

 

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.