How to tell php-fpm to send php error log to the nginx error log?

Howard asked:

When I am using apache/mod_php, the PHP error will appear in the apache’s error log.

Now, I am using php-fpm with nginx via fcgi, is it possible to have the PHP error log in the nginx error log as well?

So far the only solution is to use external file as defined in the php.ini

error_log = /tmp/php_errors.log

But I want them in the nginx error log for the ease of maintenance.

My answer:


You need to make two changes:

  1. Unset PHP’s error_log directive in php.ini. This will cause it to log to standard error, which nginx will then log to its own error log.
  2. Set catch_workers_output = yes in your php-fpm configuration php-fpm.conf, to ensure that the FPM SAPI doesn’t discard standard error.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.