r/PHPhelp • u/chiqui3d • Mar 23 '21
I can't understand the PHP error system.
I am using the docker image php:7.4-fpm. I have managed to configure php-fpm even though most of the options I do not understand them.. Here is the configuration:
[global]
error_log = /var/log/php-fpm.log
daemonize = no
log_level = notice
log_limit = 8192
[www]
listen = 9000
clear_env = no
catch_workers_output = yes
decorate_workers_output = no
.....
....I actually changed the configuration so that I send it to a file (/var/log/php-fpm.log) instead of sending it stdeer and stdout. So far so good.
Now I'm going with the PHP configuration, this is my configuration
php.ini
error_reporting = E_ALL
display_errors = On
log_errors = On ;
; error_log = /var/log/php-errors.logI have commented the error_log directive to know the behavior of this system, obviating the Syslog type because I don't want to go into that. I want to know what happens when you do not put anything in error_log, the documentation says that it is
errors are sent to the SAPI error loggerNo idea what that is, but I searched with this explanation. https://stackoverflow.com/a/23286225/2046442,
In summary it says that it sends it to the parent system of the logs such as Apache or Nginx in my case, well that only see errors on the screen, how can I do to see it in Nginx or send it to another system like Monolog?
Nginx configuration
server{error_log /var/log/nginx/web_error.log;
access_log /var/log/nginx/web_access.log;
}
None of these files contain the PHP errors that I am causing.I do NOT know if you can help me to orient in the right path.
2
u/ArlinnKordd Mar 23 '21 edited Mar 23 '21
No idea if this is helpful since sysadmin is not my ballpark at all, but if you're trying to find the destination I've seen errors (on Apache) go to such places as
/var/log/php-fpm/www-error.log
/var/log/httpd/<documentrootfolder>/error_log/
/var/log/httpd/default/ssl_error_log/
I just grab them with cat -n and | tail -50. Others may know more or r/sysadmin may be able to help better
1
u/chiqui3d Mar 23 '21
Thank you very much. I have done the search:
find . -name \*.log -ls | sort -r -n -k7Both in the nginx container and in the PHP container and I can't find anything about the PHP errors, it must be something in the configuration that I'm missing.
1
u/ArlinnKordd Mar 23 '21
That is very odd. What does the config say? I think it's supposed to be listed under
php_admin_value[error_log]Is this helpful?
0
Mar 23 '21
[deleted]
1
u/chiqui3d Mar 23 '21
Your configuration is fine, but I'm not looking to have a log file configured error_log, I want to see the behaviour when you have nothing set, as I said above that according to PHP sends it to the parent system ior SAPI Error Loggin, and I want to see the behaviour of the last one in order to understand it.
1
u/albo87 Mar 23 '21
The configs looks good to me. Check the permissions of the log file. You can create it if it doesn't exists.
6
u/HolyGonzo Mar 23 '21
It's not going to go to Nginx because you're using PHP-FPM. The PHP-FPM process is the one that is running the script (Nginx simply tells PHP-FPM what script is being requested).
So if you don't specify the error_log in your php.ini file and you trigger an error, it'll bubble up to PHP-FPM's error logging, and at that point, it's completely up to FPM to determine where and how to log it. The snippet you have at the top seems like it should be recording errors into /var/log/php-fpm.log (you need to restart FPM after any config changes).
Although in all honesty, I think letting errors bubble up into parent logs is a bad idea. That just means you're mixing different kinds of logs together, and that can lead to confusion. It's better to specify error_log in your php.ini file and point it to a separate file so your PHP script errors are kept separate.
I'll note that there's a dozen different ways to configure logging, and since configurations can be split up into multiple files / pieces, it's going to be hard to know 100% for sure if there isn't something else overriding error handling or changing the handling of STDERR.