4

I'm using PHP-FPM with NGINX and I cannot get error log to work correctly with PHP-FPM.

This is my php.ini, the relevant part:

error_reporting = 'E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE'
error_log = /var/www/logs/php-scripts.error.log
log_errors = 'On'
display_errors = 'Off'
display_startup_errors = 'Off'
html_errors =  'Off'

open_basedir = /var/www/html/:/var/www/.tmp/:/var/www/logs/
upload_tmp_dir = /var/www/.tmp

Relevant fragments of www-pool.comf (config loaded by PHP-FPM master process):

listen = 9000
user = www-data
group = www-data
request_slowlog_timeout = 10
slowlog = /var/log/php-fpm/$pool.slow.log
chdir = /var/www/html
access.log = /var/log/php-fpm/$pool.access.log
catch_workers_output = Yes

/var/www/logs/ is writable by www-data - the user PHP-FPM and the web server is running as.

Now if I do this in index.php:

error_log('Some error');

The error message finds its way to /var/www/logs/php-scripts.error.log without problems. However when I try to trigger the error like so:

trigger_error('Some error', E_USER_WARNING);

The error is not recorded in the log file. Also, when I launch intentionally broken PHP script, I get a 500 Internal Server Error on the screen, but nothing is logged to the PHP error log whatsoever, e.g.:

// index.php
<?php
echo 'Trigger error'

Notice the missing ; above - that should report an error in the error log, I'm only getting 500 Internal Server Error and no output in the log.

Will you ba able to assist? Thanks.

1 Answer 1

1

Remove the quotes from error_reporting, and the other settings as well, your php.ini should look like this:

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE
error_log = /var/www/logs/php-scripts.error.log
log_errors = On
display_errors = Off
display_startup_errors = Off
html_errors =  Off

open_basedir = /var/www/html/:/var/www/.tmp/:/var/www/logs/
upload_tmp_dir = /var/www/.tmp
Sign up to request clarification or add additional context in comments.

2 Comments

That was it. However, for reference, double quotes are allowed, from docs: "; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php"" Thanks
Yes, although that's usually only done for file paths or other text strings. By convention, the error_reporting values and On/Off are usually left without quotes :)

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.