Error logging to a file beside the php script in error doesnt work
Hi there, banging my head a bit here about creating an error file besides the php scripts that generated the errors.
For now i have error logged in files at the path /home/myuser/logs, but i can't seem to fin how to make it work with error_log. I have access to whm and cpanel and the php.ini (in whm) is using error_log = error_log as it's default. Where else could i look to change values or see if it's not overwritten?
Edit: I must add that i have a lot of sub-domains set up and use CGI for multi-php setup
-
Hey there! I would create a local PHP Info page (https://support.cpanel.net/hc/en-us/articles/360052760494-How-to-use-a-PHPInfo-file-for-troubleshooting-PHP-issues) and see what the error_log value is there, as that will show the actual loaded value of PHP for that specific domain/subdomain on the webserver.
0 -
Thanks for the fast answer! indeed the error_log path is set to a direct path for the subdomain
/home/user/logs/subdomain.php.error.log
Is there a place i can modify the value?, ther must be an overwrite somewhere since the global ini directive in whm user error_log
0 -
There sure is - there's a few different options presented here, depending on your configuration: https://support.cpanel.net/hc/en-us/articles/360050860534-How-do-I-set-the-PHP-error-log-location
0 -
Great, found the place (PHP-FPM INI Settings) , but is says : Path relative to: /home/user/logs under the textfiled, doest it mean i cannot have error_log file directly beside the script that cause it?
0 -
With PHP-FPM, no, there isn't a way to get it in a different area. The way PHP-FPM handles data is through pools, and those pools run as the cPanel user, and that's the area they will log their data too.
0 -
Ah bummer, thanks for the answer though.
0 -
Sure thing!
0 -
(coulds and mights included quite a bit below as I haven't tested these myself but do recall doing something like this back in PHP5 days...)
You could add at the start of your PHP files:
ini_set("log_errors", 1);
ini_set("error_log", "/home/user/logs/subdomain.php.error.log");
which will set the error_log location for that script.
You might be able to set "error_log=/home/user/logs/subdomain.php.error.log" in a .user.ini file to set things on a directory level, but this isn't something I've tried.
Alternatively, you could change the php-fpm settings to include an auto_prepend_file setting such as:
php_value[auto_prepend_file]=/home/user/logger.php
(which will force PHP to include that file every time it is run) and create /home/user/logger.php to set the error_log location based on the request_uri. However, this isn't something for the faint hearted/inexperienced PHP devleoper.
See also https://stackoverflow.com/questions/18711422/error-log-in-the-same-directory-as-included-files , https://maxchadwick.xyz/blog/setting-a-php-value-in-php-fpm and https://stackoverflow.com/questions/14107845/new-relic-wordpress-ignore-wp-cron-php all of which might help point you in the right direction
0 -
well, that is great info there, thanks a bunch!
0
Please sign in to leave a comment.
Comments
9 comments