nginx / php-fpm error logging
I'm trying to figure out where the PHP errors are going in my setup. I'm running nginx as the reverse proxy to PHP-FPM, but I'm not seeing the various E_NOTICE or E_WARNING messages my app is producing. The only reason I know they're happening is failed responses and NewRelic catching stack traces.
Here's the logging config:
nginx.conf
proxy_intercept_errors on;
fastcgi_intercept_errors on;
php.ini
error_reporting = E_ALL
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = On
error_log = syslog
php-fpm.conf
[global]
error_log = /var/log/php-fpm/fpm-error.log
[www]
access.log = /var/log/php-fpm/access.log
access.format = "%t \"%m %r%Q%q\" %s %{mili}dms %{kilo}Mkb %C%%"
catch_workers_output = yes
php_flag[display_errors] = on
php_admin_flag[log_errors] = true
rsyslog.conf
:syslogtag, contains, "php" /var/log/php-fpm/error.log
I've configured PHP to log to syslog, however FPM has no syslog function so it's logging to a file. I don't really care where the errors end up, just that they end up somewhere.
Any clues on how I might get this to work?
Solution 1:
Your php-fpm.conf file is not set up to send errors to syslog. See below for an example of how to do this.
; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written
; in a local file.
; Note: the default prefix is /var
; Default Value: log/php-fpm.log
error_log = syslog
; syslog_facility is used to specify what type of program is logging the
; message. This lets syslogd specify that messages from different facilities
; will be handled differently.
; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
; Default Value: daemon
;syslog.facility = daemon
; syslog_ident is prepended to every message. If you have multiple FPM
; instances running on the same server, you can change the default value
; which must suit common needs.
; Default Value: php-fpm
;syslog.ident = php-fpm
; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
;log_level = notice
Solution 2:
Are you sure about your assumption for the rsyslog.conf? That is, are you sure all such syslog messages are tagged with lower-case "php"?
Try setting syslog.facility to something like local2 (or local1, or local7) and replacing your rsyslog.conf config-line accordingly:
local2.* /var/log/php-fpm/error.log
Solution 3:
When you're using php-fpm, it appears to override the php.ini
settings.
The logging most likely needs to be configured in .../www.conf
.
I uncommented these lines in order to grab the PHP logs.
php_admin_value[error_log] = /var/log/php-errors.log
php_admin_flag[log_errors] = on
The webserver user and group can also be found in this file under lines similar to this (may differ between unix socket & proxy configuration).
listen.owner = www-data
listen.group = www-data
Then it's just a matter of creating the file and configuring it properly.
touch /var/log/php-errors.log
chmod 644 /var/log/php-errors.log
chgrp www-data /var/log/php-errors.log
chown www-data /var/log/php-errors.log
I believe the log level is still used from php-fpm.conf
so you may also need to check this.
log_level = error