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.


  1. taylan on October 2, 2008

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

  2. Antonie Potgieter on October 2, 2008


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

  3. Firefly on November 20, 2008

    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.


  4. mr.The on August 6, 2009

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

  5. Ben on August 21, 2009

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

  6. David Hood on October 28, 2009

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

  7. Larry Levenson on February 17, 2010

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

  8. […] lost-in-code website You can find the solution: just add theese two lines error_reporting(0); […]

  9. Mark McLaren on June 3, 2011

    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.

  10. Voyagerfan5761 on June 15, 2011

    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.


Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

%d bloggers like this: