1

I am trying to log all the errors but for some reason I cannot get it to work! If I turn on display_errors in my .htaccess then errors pop up here and there. But instead of having them on display, I want them to be put in a log that I can read so that my users do not see the errors.

I have added these to my .htaccess file:

php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag log_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value docref_root 0
php_value docref_ext 0
php_value error_log /path/to/errors.txt
php_value error_reporting 32767
php_value log_errors_max_len 2048

Yet errors.log is still empty! Ive tried restarting apache, whole server, nothing. Any help would be greatly appreciated.

PHP Version - 5.4.39-0+deb7u2

2
  • Are you sure the "/path/to/errors.txt" is writeable by the user running apache, e.g. user apache? Commented May 21, 2015 at 10:40
  • @Jobst exactly what the problem was! Thank to you and The Humble Rat for pointing this out, and thank for Humble Rat for such a detailed response Commented May 21, 2015 at 13:13

2 Answers 2

4

First please check using phpinfo() if your default settings is being overwritten by your htaccess. The phpinfo will show you the local and master values.

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

1 Comment

Hiya, thanks for this, checked all of the values and yes they are being overwritten as expected
2

It is most likely a permissions issue as to why the errors are not logging. Here is the snippet I use:

ini_set("error_reporting", -1);
ini_set("log_errors", 1);
ini_set("error_log", "/var/www/site/php-error.log");

I assume you are using a Linux distribution, therefore once you have the code in your page, using the command line create the file:

touch /var/www/site/php-error.log
chmod 644 /var/www/site/php-error.log

Then for Ubuntu/Debian do the following:

chown www-data:www-data /var/www/site/php-error.log

Or for Centos/Red Hat:

chown apache:apache /var/www/site/php-error.log

You should then see the errors being logged. If this fails then check the error log by viewing it realtime and then refreshing the page. To view the log in realtime do the following:

For Ubunut/Debian:

tail -f /var/log/apache2/error

For Centos/Red Hat

tail -f /var/log/httpd/error

2 Comments

Damn permissions!! I forgot to check them DOH! Thanks for this, its now working perfectly!
@DarylGoode happens to the best of us. Glad I could help. Good luck!

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.