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.
php.ini
Theerror_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
Theerror_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.
nginx.conf
The
Syntax: </ th>
error_log
file </ code> (
level </ code>];
Default: error_log logs/error.log error;
Context: main
,http
,stream
,server
,location
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 afile
that will store the log. The special valuestderr
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 buffersize
, and is generally used for debugging (1.7.11).
The second parameter determines thelevel
of logging, and can be one of the following:debug
,info
,notice
,warn
,error
,crit
,alert
, oremerg
. 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 levelerror
will causeerror
,crit
,alert
, andemerg
messages to be logged. If this parameter is omitted thenerror
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.
<?php
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: 127.0.0.1, server: _, request: “GET /error.php HTTP/1.1”, upstream: “fastcgi:// 127.0.0.9000 “, host: “127.0.0.1”
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 PHPenv[HOSTNAME] = $HOSTNAME 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
Conclusion:
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:
- Mac: Where is php.ini Location
- Error during session start; please check your PHP and/or webserver log file and configure your PHP
- PHP file download, download failed, nginx open() nginx / fastcgi_ temp/2/10/0000000102“ failed (13: Permission denied)
- [PHP] Solve the limitation of uploading files in nginx php 413 Request Entity Too Large
- PHP large file upload error 413: request entity too large [How to Solve]
- How to Hide index.php
- [PHP] Solve the 500 error problem-nginx and fpm have no error logs
- PHP error in Windows: class’ mysqli ‘not found
- PHP: The Difference between \Throwable, \Error and \Exception
- [Solved] PHP -v Error: error while loading shared libraries: libonig.so.5:cannot open share directory
- Laravel-admin php artisan admin:install error reporting problem solution
- Configure: error: Cannot find libz error appears when brew installs php70
- [Solved] PHP Error: Warning: file_get_contents(): Failed to enable crypto
- Mac PHP Fatal error: Class ‘Memcache’ not found
- PHP php-config is not installed error in ubuntu 16 [How to Solve]
- PHP: How to parse MHT file into HTML
- HTML + PHP inline execute JavaScript Error [How to Solve]
- [PHP]json_encode Chinese JSON_UNESCAPED_UNICODE returns null in php5.3
- PHP use __Sleep() and __wakeup() method serializes the object
- PHP solves the problem that composer exceeds the memory size Allowed memory size