skip to Main Content

We use a typical nginx and php-fpm setup for a WordPress site running on Amazon Linux 2.

We recently noticed that:

  • PHP error log output was being sent to /var/log/nginx/error_log
    even though /etc/php-fpm.d/www.conf contains php_admin_value[error_log] = /var/log/php-fpm/www-error.log and php_admin_flag[log_errors] = on
  • It turned out that /var/log/php-fpm was not writable because user = nginx and group = nginx in /etc/php-fpm.d/www.conf and /var/log/php-fpm is owned by apache:root
  • After we changed the permission, PHP error log is written to /var/log/php-fpm/www-error.log

Now we have 2 questions.

  • Is this expected behavior? When the php-fpm log file/directory is not writable, it sends logs to nginx log? We searched the documentation that explains how that is possible but couldn’t find any.
  • While the permission was misconfigured, some page of the WordPress didn’t work correctly. Can the error log settings affect PHP’s behavior?

Unfortunately, the WordPress problem was occurring only on the production website, so we can’t investigate the problem by trial and error. We need to make it clear theoretically.

2

Answers


  1. Is this expected behavior? When the php-fpm log file/directory is not writable, it sends logs to nginx log? We searched the documentation that explains how that is possible but couldn’t find any.

    In Nginx by default when a fastcgi application sends an error message, nginx sends that error message to its own error log. I guess PHP has a fallback behavior where if it cannot write to the error log file, it complains to the fastcgi server (in this case, nginx) instead of the log. Sounds reasonable to me

    While the permission was misconfigured, some page of the WordPress didn’t work correctly. Can the error log settings affect PHP’s behavior?

    It shouldn’t.. I can imagine code written like:

    if(false === error_log($error, 4)){
    // do something special because error_log failed..
    }
    

    though, but I’ve never seen that in the wild (and i’ve been doing PHP since 2006)

    Login or Signup to reply.
    1. Is this expected behavior? When the php-fpm log file/directory is not writable, it sends logs to nginx log? We searched the documentation that explains how that is possible but couldn’t find any.

    No, it is not the expected behavior for PHP-FPM to send its error logs to the Nginx log file when the specified log file or directory is not writable. By default, PHP-FPM should log its errors to the location specified in the php_admin_value[error_log] directive in the www.conf file (which in your case has been set to /var/log/php-fpm/www-error.log).

    However, the behavior you observed could be a result of misconfiguration or a fallback mechanism in the particular setup you have. If PHP-FPM encounters an issue with writing to the specified log file or directory, it may fall back to sending the error logs to the Nginx error log instead.

    1. While the permission was misconfigured, some page of the WordPress didn’t work correctly. Can the error log settings affect PHP’s behavior?

    Not at all! Logging has nothing to with page rendering process (except, of course, when incorrect logging settings cause the content of the error message to be displayed in the output). ‌But if your pages had some template rendering issues, that has nothing to do with logging misconfiguration.

    In cases like this, you may also consider switching the PHP handler and/or PHP version to see if the problem resolves.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search