PHP Error Logging

Log errors to a file, and prevent showing them to the user. Make sure that the file exists and youre able to write to it.

# display no errs to user
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
# log to file
php_flag log_errors on
php_value error_log /location/to/php_error.log


  1. User Avatar
    Permalink to comment#

    this is really interesting thank you

  2. User Avatar
    Permalink to comment#

    Where does this code go? .htaccess, a php file?

  3. User Avatar
    Permalink to comment#

    Too bad it won’t work on a lot of web servers because of the restrictive AllowOverride setting :(

  4. User Avatar
    Permalink to comment#

    You can’t set flags in .htaccess if PHP is installed as CGI, only if is installed as Apache Module. Check before with phpinfo();


  5. User Avatar
    Permalink to comment#

    This will remove it from my original var log, cant we log at both place?

  6. User Avatar

    Just try it for my wp blog and it’s working. This easier mylife to find some errors. Awesome.

  7. User Avatar
    Permalink to comment#

    Thank you for unshared, a very useful

  8. User Avatar
    Translation Agency
    Permalink to comment#

    If it does not work on many browsers i suppose it can be made possible by adding in some code just like the way we make the browsers be able to read the html5 code for even the ones which do not support.

  9. User Avatar
    Jonathan Acosta
    Permalink to comment#

    The path at the end of the snippet is absolute on the file system or relative to the DocumentRoot?

Leave a Comment

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.