This is essentially the same as these questions:
https://stackoverflow.com/questions/8677493/php-fpm-doesnt-write-to-error-log
BUT the answers there don't seem to be working on Ubuntu 16.04 with PHP 7.
/etc/php/7.0/fpm/pool.d/www.conf:
catch_workers_output = yes
php_flag[display_errors] = on
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
/var/log/fpm-php.www.log
exists and is owned by www-data
.
/etc/php/7.0/fpm/php.ini:
log_errors = On
Nginx Virtual Host's Server block
access_log /var/log/myapp/access.log;
error_log /var/log/myapp/error.log error;
/var/log/myapp/access.log exists and is owned by www-data
.
But when an error occurs, I don't get an error in any of the specified log files, and can't find it in any other place either.
I went through all of the suggestions on the other question but didn't find any answer that worked. I'm assuming something has changed since those answer were posted. Any suggestions?
The comment above by the_nuts helped solve it for me. The directory and file didn't exist.
To diagnose, I added:
to the top of my code (a WordPress plugin). This outputted:
In terminal I used ls to learn the file and directory were missing, i.e.
outputted
To fix: I changed directory to /usr/local/etc, created the directory, the file and then set the owner to www-data:www-data
If the file and directory do exist, run
and if owner is root:
run
to give the web server ownership and write access