Turn off error reporting on your production site

On a production site, you would most likely want to hide all possible PHP errors, warnings and notices from your users for both usability, presentational and security purposes.

For development and debugging purposes, you would want to turn on error_reporting and display all error messages so that you can debug your code and ensure that it is working as intended. You have to remember that there are different types of PHP errors. Fatal errors literally cease the execution of the script while warnings and notices simply notify you of the possibility of errors or bad programming practice in general.

In this article, I’ll use WordPress as an example. I’ll show you how to turn off error_reporting on your WordPress production site so that users won’t have to look at ugly errors/warnings on your pages. Even though I’ll be using WordPress as an example, this method can be applied to any other type of platform.

Start off by opening up your “wp-config.php” file in any type of text editor. Just after the PHP opening tag, put the following two lines of code.

@ini_set('display_errors', 0);

The first line will tell PHP the level of error_reporting you want to set. Have a look at the PHP error_reporting manual for more details and information n the different levels you are able to set.

The second line executes the ini_set function which modifies the PHP configuration value “display_errors” and sets it to 0 (which turns it off). “display_errors” tells PHP whether or not errors should be displayed on the page. You can set it to 1 to display all errors. The reason for the “@” sign before the ini_set function is to silence a warning on the function. On some servers, especially shared hosting accounts, the PHP configuration cannot be modified unfortunately. It depends on your hosting account and provider.

And that’s it. All PHP errors, warnings and notices should now be hidden on your WordPress website. Remember to check for errors, warnings and notices on a development installation. You can then set error_reporting to E_ALL to display all errors.

  • http://www.taylanaktepe.com taylan

    I usually used this “error_reporting(0);” I dont think add this,
    “@ini_set(‘display_errors’, 0);” thank you.

  • http://tribulant.com Antonie Potgieter


    Its a pleasure. I’m glad you found it useful.

  • http://www.firefly-shop.org Firefly

    Great, thanks just what I was looking for, tried error_reporting(E_ERROR | E_PARSE); but it did not work, yours works on 2.7.3 Beta 3 as well.


  • http://mrthe.name/ mr.The

    Why is “display_errors”?
    error_reporting already turned off all error reporting.

  • http://www.techgremlin.com Ben

    I am assuming it depends on your web host, mine needed the display errors command before it stopped showing them.

  • http://www.homesaleschinohills.com David Hood

    PHP configuration cannot be modified fue to the due to the provider right?

  • http://www.sigmawebtechnologies.com Larry Levenson

    Thanks, Antonie! Nice, succinct article about turning off error messages on production sites. I’m implementing it now.

  • Pingback: turn off wordpress php error reporting « Difficiles Nugae Labs

  • http://www.mcbuzz.com/ Mark McLaren

    Thank you for providing a quick fix for a vexing problem. I can’t believe I hadn’t seen this fix before!

    Note: For any PHP hacks out there like myself, at first when I copied and pasted into wp-config.php the two lines of code you offer above, it did not work. The reason was that there are angled (aka “smart”) single quotation marks around ‘display_errors’. I changed these to straight single quotes (like this: ‘display_errors’) and it worked like a charm.

  • http://technobabbl.es/ Voyagerfan5761

    Something in this WordPress installation is converting the quotes in the code sample to “smart quotes”, causing the code to not function if copied-and-pasted.

    Also, the initial call to set the error reporting level is unnecessary. AFAIK, turning that off also prevents errors from reaching the server logs, where they are wanted.