1

I've encountered a strange behaviour. I'm running NGINX with PHP-FPM.

When I enable the PHP error log in php.ini:

error_log = /var/www/logs/php-scripts.error.log
log_errors = on

the error log is written to as expected:

...
[15-Feb-2017 19:35:28 Etc/UTC] PHP Parse error:  syntax error, unexpected end of file, expecting ',' or ';' in /var/www/html/index.php on line 7

However, at the same time the error log configured in my NGINX vhost is not written to at all (this is the NGINX configuration fragment):

server {
  listen 80;
  server_name  vhost.com;

  access_log   /var/log/nginx/access.log main;
  error_log    /var/log/nginx/error.log; <- this is always empty
}

Now to my surprise, when I disable the error log in php.ini:

; error_log = /var/www/logs/php-scripts.error.log <-- commented out
log_errors = on

the NGINX error log is written to:

...
2017/02/16 12:01:44 [error] 13#13: *27 FastCGI sent in stderr: "PHP message: PHP Parse error:  syntax error, unexpected end of file, expecting ',' or ';' in /var/www/html/index.php on line 7" while reading response header from upstream, client: 172.19.0.2, server: domain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://172.19.0.3:9000", host: "domain.com:8080"

I do not understand this behavior at all. What's the source of this interference between the two logging systems? Why can't I have the error log enabled in php.ini and at the same time have NGINX's error log being written to? At the moment it's either one or another. Is it possible to overcome this issue?

1 Answer 1

2

PHP reports errors to a logfile, syslog(3) or stderr, depending on if and how error_log is set. See this document for details.

nginx will log messages it receives over the FastCGI stderr stream.

So, it's not really strange behaviour.

Sign up to request clarification or add additional context in comments.

1 Comment

If I understand correctly, the point is that if I redirect PHP errors to a file, the errors are not emitted to stderr so, consequently, nginx will not have any stream to read from and its error log will be empty..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.