4

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.

7
  • aren't they sent to system logs instead? do you use third argument of error_log which is $destination? Commented Mar 6, 2018 at 23:15
  • 1
    I'd double check what user & group is php running as. PHP might not have permissions to update the file. Commented Mar 6, 2018 at 23:17
  • error_log another question Commented Mar 6, 2018 at 23:19
  • @Robert we looked all around /var/logs and couldn't find anything. and we did use the third argument of error_log. Commented Mar 6, 2018 at 23:22
  • create any file with php script and see what user created that file with "LS" then check if this user has rights to write/create log files in the directory given by you Commented Mar 6, 2018 at 23:23

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

My mistake, this was the one thing I forgot to add to the initial question. We have tried this as well, but the results were the same.

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.