nginx.conf php-fpm.conf and php.ini Error among the three_ Differences and relations between log instructions

The error_log directive is found in the configuration file nginx.conf of Nginx, the configuration file PHp-fPM, and php.ini. This article attempts to briefly explain the differences and associations between these three configurations.

The error_log </ code> string
Sets the file to which script errors will be logged. This file must be writable by the Web server user. If the special value syslog is set, an error message is sent to the system logger. On Unix and similar systems, syslog(3) is used, while on Windows NT-class systems it is event logging. System logging is not supported on Windows 95. See: syslog(). If this configuration is not set, an error message is sent to the SAPI error logger. For example, an error appears in an Apache error log or is sent to Stderr in the CLI.

PHP – FPM. Conf
The error_log </ code> string
Location of the error log. Default: #INSTALL_PREFIX#/log/ php-pm. log. If set to "syslog", the log will not be written to the local file, but will be sent to syslogd.


Syntax: </ th>

error_log file </ code> ( level </ code>];

error_log logs/error.log error;
Context: mainhttpmailstreamserverlocation

Configures logging. Several logs can be specified on the same level (1.5.2). If on the main configuration level writing a log to a file is not explicitly defined, the default file will be used.
The first parameter defines a file that will store the log. The special value stderr selects the standard error file. Logging to syslog can be configured by specifying the “syslog:” prefix. Logging to a cyclic memory buffer can be configured by specifying the “memory:” prefix and buffer size, and is generally used for debugging (1.7.11).
The second parameter determines the level of logging, and can be one of the following: debuginfonoticewarnerrorcritalert, or emerg. Log levels above are listed in the order of increasing severity. Setting a certain log level will cause all messages of the specified and more severe log levels to be logged. For example, the default level error will cause errorcritalert, and emerg messages to be logged. If this parameter is omitted then error is used.

From the above documentation, it is initially clear that error_log has a higher priority in php.ini, so let’s experiment with these combinations of configurations in turn.
The test reports errors using the following simple php code.

throw new Exception('foobar');

The configuration values of each error_log are as follows:

Nginx: error_log/var/log/nginx/error log.
Php-fpm: error_log = /var/log/php-fpm/error.log
Php.ini: error_log = /var/log/ PHP /error.log

1. When three values are configured at the same time, the PHP error log will be written to the file specified by the error_log in php.ini

[21-Apr-2019 22:19:13 Asia/Shanghai] PHP Fatal error: Uncaught Exception: Foobar in/usr/share/nginx/HTML/error. PHP: 5
the Stack trace: # 0 {main}

thrown in/usr/share/nginx/HTML/error. PHP on line 5

But what if the error_log specifies a file that does not have writable permissions, would it be logged into the error_log file of nginx or PHP-FPM?The answer is no, and the error message is lost because it cannot be written.
2. Do not configure the error_log in php.ini, and configure the error_log in nginx.conf and PHp-fPm.conf. At this time, the error log will be written to the error_log file of Nginx

2019/04/21 22:33:04 [Error] 2031#0: *102 FastCGI sent in stderr: “PHP message: PHP Fatal error: Uncaught Exception: Foobar in/usr/share/nginx/HTML/error. PHP: 5
the Stack trace: # 0 {main}

thrown in/usr/share/nginx/HTML/error. PHP on line 5 “while reading the response headers from upstream, the client:, server: _, request: “GET /error.php HTTP/1.1”, upstream: “fastcgi:// “, host: “”

3. Since nginx error_log does not support shutdown, it is impossible to compare the priority of error_log between Nginx. conf and PHP-fpm. In fact, the error_log in PHP-fpm conf is not used to record PHP error messages, but to record some runtime information of the PHP-FPM process itself.
4. Although error_log in PHP-fPm.conf does not record PHP error information, php_value/php_flag or php_admin_value/ php_ADMIN_flag configuration can be used to override the configuration in PHp.ini:

You can also pass additional environment variables to a run pool, or update PHP configuration values. This can be done in the process pool configuration file with the following configuration parameters:
Example #1 passes environment variables to the runtime pool and sets the configuration values for PHP

       env[PATH] = /usr/local/bin:/usr/bin:/bin
       env[TMP] = /tmp
       env[TMPDIR] = /tmp
       env[TEMP] = /tmp

       php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f [email protected]
       php_flag[display_errors] = off
       php_admin_value[error_log] = /var/log/fpm-php.www.log
       php_admin_flag[log_errors] = on
       php_admin_value[memory_limit] = 32M

PHP configuration values are passed
Php_value or
Php_flag is set and overrides previous values. Please note that
Disable_functions or
The value defined in DISABle_classes in php.ini is not overridden, but the new setting is appended to the original value.
Values defined using php_ADMIN_value or php_ADMIN_flag cannot be overridden by ini_set() in PHP code.

For example, if you configure php_admin_value[error_log] in PHp-fpm.conf = /var/log/php-fpm/www-error.log, and configure error_log in php.ini, you will find that the PHP error message will be written into the /var/log/php-fpm/www-error.log file
Error_log Priority: PHp_value [error_log]/php_admin_value[error_log] in PHP-pm.conf
Greater than PHP ini the error_log
The error_log is greater than the nginx. Conf
The error_log in PHP-pm.conf has nothing to do with logging an error message when PHP is running.
The easiest way to get PHP error logging is to look at the phpInfo () message and see the value of the error_log. If there is a value, the error logging is recorded where the value is specified, and if there is no error logging, it is recorded in nginx’s error_log.

Some frameworks use set_exception_handler and set_error_handler, as well as register_shutdown_function to reset the exception handling and error reporting, and may write the error log to another place, so in a development environment, temporarily open display_errors. This is the fastest way to locate errors.
That’s all

Read More: