PHP error_reporting Explained: Configuration, Error Levels, and Best Practices

Published: 2026-07-07
Google AdSense 广告位 (待申请通过后开启)

Introduction

The error_reporting directive controls which types of PHP errors, warnings, notices, and deprecation messages are reported during script execution. Unlike display_errors, which determines whether errors are shown in the browser, error_reporting determines which error levels PHP processes.

Choosing an appropriate error reporting level helps developers identify problems during development while reducing unnecessary output in production environments.

This guide explains how error_reporting works, how to configure common error levels, and recommended settings for different environments.

Test Environment

Operating System : AlmaLinux 10
PHP Version      : PHP 8.3
Web Server       : Nginx
PHP-FPM          : Enabled
Architecture     : x86_64
Last Tested      : July 2026

What Is error_reporting?

The error_reporting directive specifies which PHP error types should be reported.

Example:

error_reporting = E_ALL

This setting instructs PHP to report all available error levels, including errors, warnings, notices, and deprecation messages.

How error_reporting Works

PHP Script
      │
      ▼
Runtime Event
      │
      ▼
error_reporting
      │
      ├── Included → Report Error
      └── Excluded → Ignore
              │
              ▼
display_errors / log_errors

The error is first filtered by error_reporting. Any reported errors can then be displayed in the browser or written to a log, depending on your other PHP settings.

Check the Current Value

Run:

php -i | grep error_reporting

Example:

error_reporting => 32767 => 32767

Or verify using:

<?php
phpinfo();

Search for:

error_reporting

Locate the Active php.ini File

php --ini

Example:

Loaded Configuration File: /etc/php.ini

If you are using PHP-FPM, edit the configuration file used by PHP-FPM.

Change error_reporting

Open the configuration file:

sudo nano /etc/php.ini

Find:

error_reporting = E_ALL

Or specify a different level if required.

Save the file and restart PHP-FPM:

sudo systemctl restart php-fpm

Common Error Levels

| Constant       | Description                        |
| -------------- | ---------------------------------- |
| `E_ERROR`      | Fatal runtime errors               |
| `E_WARNING`    | Runtime warnings                   |
| `E_PARSE`      | Parse errors                       |
| `E_NOTICE`     | Notices about potential issues     |
| `E_DEPRECATED` | Deprecated features                |
| `E_ALL`        | Reports all supported error levels |

For most modern PHP applications, E_ALL is the recommended setting during development.

Development vs Production

Development

Recommended:

error_reporting = E_ALL
display_errors = On
log_errors = On

This configuration reports every available error and displays it immediately, making debugging easier.

Production

Recommended:

error_reporting = E_ALL
display_errors = Off
log_errors = On

Errors are still detected and recorded, but visitors do not see internal error messages.

error_reporting vs display_errors

These two directives serve different purposes.

| Directive         | Purpose                                                     |
| ----------------- | ----------------------------------------------------------- |
| `error_reporting` | Determines which errors PHP reports                         |
| `display_errors`  | Determines whether reported errors are shown in the browser |

For example:

error_reporting = E_ALL
display_errors = Off

PHP continues to detect all errors, but they remain hidden from users.

Numeric Values

Some systems display a numeric value instead of E_ALL.

For example:

32767

In modern PHP versions, this numeric value corresponds to E_ALL.

Using the named constant improves readability and is generally recommended.

Common Issues

No Errors Are Displayed

Possible causes include:

display_errors is disabled.

The application suppresses errors.

PHP-FPM has not been restarted after configuration changes.

Too Many Notices

Development environments often display notices and deprecation messages that are useful for improving code quality. Production servers typically keep these messages out of the browser by disabling display_errors while continuing to log them.

Best Practices

Use E_ALL during development.

Keep display_errors disabled on production servers.

Enable log_errors so errors are recorded.

Restart PHP-FPM after modifying configuration values.

Review error logs regularly instead of relying only on browser output.

Conclusion

The error_reporting directive determines which PHP errors are detected during script execution. Combined with display_errors and log_errors, it forms the foundation of PHP's error handling system.

For most environments, enabling E_ALL while disabling display_errors on production servers provides a good balance between effective debugging and application security.

Explore More

Technology Guides →

PHP opcache.max_accelerated_files Explained: Configuration, Performance, and Best Practices

PHP opcache.validate_timestamps Explained: Configuration, Code Updates, and Best Practices

PHP opcache.revalidate_freq Explained: Configuration, Performance, and Best Practices

PHP opcache.enable Explained: Configuration, Performance, and Best Practices

Southeast Asia Insights →