Reputation: 41
Title pretty much says it all. I've been tearing my hair out trying to get this working all day. I'm in the process of creating a PHP-based login system and I need to do some debugging. The most useful thing to me right now would be the ability to write debugging messages to a file at certain points throughout a PHP program. Based on the documentation, it looks like this is what error_log()
is supposed to do, but despite everything I've tried, I have had absolutely no success. Full list of everything I've tried below:
Added the following to /etc/php/7.0/apache2/php.ini
error_reporting = E_ALL
display_errors = On
log_errors = On
Additionally, tried setting error_log
to locations within /usr/
, /var/www/http/
, and /home/
Used ini_set()
and error_reporting()
to set all of those variables, including error_log
from within a PHP file
Manually creating the files that are supposed to be written to, and setting their owning user and group to www-data
and their permissions to 777
Last but not least, reinstalling libapache2-mod-php7.0
and php7.0
, to no avail
Basically everything short of using my laptop to break the 3rd story window of my office building immediately prior to jumping to my prospective death
I really can't find anthing else to try on Google, so I figured I'd ask the experts, and here I am. If anyone can provide any suggestions, it would be greatly appreciated.
Upvotes: 4
Views: 2093
Reputation: 20286
I guess the logs are written to sys logs because in error_log() you didn't provide the destination.
Try the following code
error_log("An error occured", 3, "/var/tmp/my-errors.log");
Be sure this file can be read by php either fpm or www-data depending on your configuration you can create it before with touch and add permissions manually with chmod
3 means that destination is a file
If you use apache then check in httpd.conf or any other place(v where it may be present the location of ErrorLog
ErrorLog "/var/log/apache2"
Then check if this file has following user group with ls -la
ll
etc.
-rwxrwxr-x 1 www-data www-data
Something like this should appear.
The other option is to set following in proper php.ini (CLI and apache have different php.ini files)
error_log = /var/log/phperrors.log
then
touch /var/log/phperrors.log
chown www-data: /var/log/phperrors.log
chmod +rw /var/log/phperrors.log
There are no miracles but if it still doesn't work you can write and register your own error handler with set_error_handler()
you can find examples how to do it in php manual. It's more like hack but it will work for sure. If it won't then it means that errors are not triggered at all then you should look if you edit the correct php.ini or use ini_set() before error is triggered.
Upvotes: 2