How to Turn Off PHP Error Reporting

When developing or managing PHP-based websites and applications, error reporting is an essential tool for identifying issues in the code. However, displaying PHP errors on a live website can pose security risks and lead to a poor user experience. For this reason, many website owners and administrators prefer to turn off PHP error reporting in production environments.

In this guide, Go4hosting will walk you through the reasons to disable PHP error reporting, and the various methods to turn it off safely on your server.

What is PHP Error Reporting?

PHP error reporting is a feature that displays or logs errors encountered while running PHP scripts. These errors can include:

  • Syntax errors

  • Runtime errors

  • Warnings

  • Notices

By default, PHP can be configured to display errors directly on the web page or log them to a file for debugging purposes.

While error reporting is very useful during development and testing phases, displaying errors on a live website can:

  • Expose sensitive server or code information to visitors.

  • Break the user interface by showing ugly error messages.

  • Potentially give attackers insight into vulnerabilities.

Hence, controlling how and when errors are reported is critical for secure and professional website management.

When Should You Turn Off PHP Error Reporting?

Development Environment

  • Error reporting ON: During development, developers want to see all errors and warnings to debug and fix issues promptly.

Production Environment

  • Error reporting OFF: On a live website, error messages should generally be hidden from users.

  • Instead, errors should be logged for administrators to review without exposing details publicly.

How to Turn Off PHP Error Reporting: Methods Overview

There are multiple ways to disable PHP error reporting. The best approach depends on your server setup, access level, and whether you want to hide errors completely or just prevent them from showing on screen.

Here are the common methods:

  1. Modify the php.ini configuration file

  2. Use .htaccess directives (for Apache servers)

  3. Add PHP code directly to your scripts

  4. Control error reporting in frameworks or CMS settings

Method 1: Turn Off Error Reporting via php.ini

The php.ini file is the main configuration file for PHP on your server. Editing it lets you control error reporting globally.

Steps to disable error reporting in php.ini:

  1. Locate the php.ini file:
    On most servers, this file is located at:

    • /etc/php/7.x/apache2/php.ini (Linux + Apache)

    • /etc/php/7.x/fpm/php.ini (Linux + PHP-FPM)

    • Use phpinfo() to find the loaded configuration file.

  2. Open the file for editing:
    Use a text editor like vi, nano, or access it through your hosting control panel.

  3. Modify the following directives:

ini

CopyEdit

display_errors = Off

log_errors = On

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

  • display_errors = Off ensures PHP errors are not displayed on the browser.

  • log_errors = On keeps errors logged to your server's error log files for debugging.

  • error_reporting controls which types of errors to report; adjust as needed.

  1. Save changes and restart the web server:
    For Apache:

bash

CopyEdit

sudo systemctl restart apache2

For Nginx with PHP-FPM:

bash

CopyEdit

sudo systemctl restart php7.x-fpm

sudo systemctl restart nginx

Method 2: Turn Off Error Reporting Using .htaccess

If you are on a shared hosting environment or cannot access php.ini, you can control error reporting via the .htaccess file (only applicable if you are using Apache).

Steps:

  1. Locate or create a .htaccess file in your website's root directory.

  2. Add the following lines:

apache

CopyEdit

php_flag display_errors Off

php_value error_reporting 0

  1. Save and test your website.

Note: Some hosts disable overriding PHP settings in .htaccess. If this does not work, try the PHP code method below or contact your hosting provider.

Method 3: Disable Error Reporting Using PHP Code

You can also control error reporting directly in your PHP scripts, especially useful if you want to disable errors temporarily or conditionally.

Add the following code at the top of your PHP file:

php

CopyEdit

ini_set('display_errors', '0');

error_reporting(0);

?>

  • ini_set('display_errors', '0') disables error display.

  • error_reporting(0) disables all error reporting.

Alternatively, for finer control:

php

CopyEdit

error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);

This disables notices and warnings but keeps other errors visible.

Method 4: Framework or CMS Configuration

Popular PHP frameworks (Laravel, Symfony, CodeIgniter) and CMS platforms (WordPress, Joomla, Drupal) often have their own debug and error reporting settings.

For example:

  • WordPress:
    In wp-config.php, set:

php

CopyEdit

define('WP_DEBUG', false);

define('WP_DEBUG_DISPLAY', false);

  • Laravel:
    In .env file, set:

ini

CopyEdit

APP_DEBUG=false

Check your platform's documentation for recommended production error handling.

Additional Tips for Managing PHP Errors

Enable Error Logging

Even if you turn off error display, it's important to log errors to diagnose issues. Ensure in php.ini:

ini

CopyEdit

log_errors = On

error_log = /var/log/php_errors.log

Check your hosting control panel or ask Go4hosting support for the default location of PHP error logs.

Use Custom Error Pages

Hide raw PHP errors and instead serve user-friendly custom error pages (like 404, 500). This improves user experience and security.

Regularly Monitor Error Logs

Set up log rotation and monitoring to detect issues early and keep your server optimized.

Why Should You Turn Off PHP Error Reporting on Production?

  • Security: Error messages can reveal paths, file names, database queries, or sensitive information that hackers can exploit.

  • User Experience: Displayed errors look unprofessional and can confuse visitors.

  • Performance: Excessive error output can slow down page rendering.

How Go4hosting Helps You Manage PHP Error Reporting

At Go4hosting, we understand the importance of error management for your PHP applications.

  • Our cloud and dedicated hosting plans provide full access to php.ini and .htaccess files.

  • Our managed hosting team can help you configure your server to turn off error display and enable logging.

  • We provide guidance to optimize your PHP environment for security and performance.

  • Need help troubleshooting PHP errors? Our expert support team is ready 24*7.

Summary

Method

Description

Suitable For

Edit php.ini

Global PHP configuration for error reporting

VPS, Dedicated, Managed Hosting

Modify .htaccess

Apache override on shared hosting

Shared Hosting with Apache

Use PHP Code (ini_set)

Script-level control of error reporting

Quick fixes, Conditional toggles

Framework / CMS Configurations

Platform-specific error settings

WordPress, Laravel, Joomla, etc.

Final Thoughts

Turning off PHP error reporting is an essential best practice for live websites and production environments. It protects your site from leaking sensitive information and ensures a clean, professional user experience.

However, turning off error display should always be paired with proper error logging and monitoring so your development or support team can track and fix issues promptly.

For more assistance in configuring PHP error reporting or setting up secure and optimized hosting environments, reach out to the Go4hosting team. We provide expert hosting solutions tailored for PHP websites and applications of all sizes.

Was this answer helpful? #0 #0
 

Did We Miss Out on Something?

Relax, we have you covered. At Go4hosting, we go the extra mile to keep our customers satisfied. We are always looking out for opportunities to offer our customers “extra” with every service. Contact our technical helpdesk and we’d be more than happy to assist you with your Cloud hosting, Colocation Server, VPS hosting, dedicated Server or reseller hosting setup. Get in touch with us and we’d cover all your hosting needs, however bizarre they might be.

Related Questions

Submit your Query

  • I'm not a robot

Browse by ServicesBrowse by Services

Resource Library

What is Cloud Computing

Understand the term cloud computing, the ongoing trend, its playing field, future growth and how industry...

Myths about Cloud Computing

Cloud computing, in the recent years, has become a subject of significant discussion among the industry experts.

Download Now

Did We Miss Out on Something?

Relax, we have you covered. At Go4hosting, we go the extra mile to keep our customers satisfied. We are always looking out for opportunities to offer our customers “extra” with every service. Contact our technical helpdesk and we’d be more than happy to assist you with your Cloud hosting, Colocation Server, VPS hosting, dedicated Server or reseller hosting setup. Get in touch with us and we’d cover all your hosting needs, however bizarre they might be.

Submit Query

Please fill in the form below and we will contact you within 24 hours.