PHP display_errors Explained: Configuration, Debugging, and Best Practices

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

Introduction

The display_errors directive controls whether PHP displays error messages directly in the browser. It is an important configuration option for debugging applications during development, but it should be used carefully on production servers.

Displaying detailed error messages can help developers quickly identify problems. However, exposing internal paths, database information, or application details to visitors may introduce security risks.

This guide explains how display_errors works, how to configure it, recommended settings for different environments, and common troubleshooting scenarios.

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 display_errors?

The display_errors directive determines whether PHP sends error messages to the browser.

Example:

display_errors = On

With this setting enabled, PHP displays runtime errors, warnings, and notices directly in the page output.

To disable error display:

display_errors = Off

Errors are no longer shown to visitors, although they can still be written to log files if error logging is enabled.

How display_errors Works

PHP Script
     │
     ▼
Runtime Error
     │
     ▼
display_errors
     │
 ┌───┴───────────┐
 │               │
On              Off
 │               │
 ▼               ▼
Browser      Error Log

When display_errors is enabled, errors are visible in the browser. When disabled, users see only the application response, while administrators can review the logs.

Check the Current Value

Run:

php -i | grep display_errors

Example:

display_errors => Off => Off

Or verify using:

<?php
phpinfo();

Search for:

display_errors

Locate the Active php.ini File

php --ini

Example:

Loaded Configuration File: /etc/php.ini

If you are using PHP-FPM, ensure you modify the configuration used by the web server.

Enable display_errors

Open the PHP configuration file.

sudo nano /etc/php.ini

Find:

display_errors = Off

Enable it:

display_errors = On

Save the file.

Restart PHP-FPM

Apply the configuration.

sudo systemctl restart php-fpm

Verify:

sudo systemctl status php-fpm

Expected output:

Active: active (running)

Development vs Production

Development Environment

Recommended:

display_errors = On
log_errors = On

Displaying errors makes debugging faster and helps identify syntax errors, warnings, and exceptions.

Production Environment

Recommended:

display_errors = Off
log_errors = On

Users should never see internal PHP error messages.

Instead, errors should be recorded in log files for later analysis.

display_errors vs log_errors

These directives serve different purposes.

| Directive        | Purpose                     |
| ---------------- | --------------------------- |
| `display_errors` | Shows errors in the browser |
| `log_errors`     | Writes errors to log files  |

Many production servers use:

display_errors = Off
log_errors = On

This configuration protects sensitive information while preserving useful diagnostic data.

Common Issues

Blank White Page

If the page is completely blank, temporarily enable:

display_errors = On

This often reveals the underlying PHP error.

Remember to disable it again after debugging.

Changes Have No Effect

Possible causes include:

PHP-FPM was not restarted.

The wrong php.ini file was modified.

The application overrides the setting at runtime.

Error Messages Still Do Not Appear

The application may suppress errors using:

error_reporting(0);

or the server may have additional configuration that affects error reporting.

Security Considerations

Displaying errors on a production website may reveal:

File system paths

Database queries

Framework structure

Configuration details

Installed software versions

This information can help attackers understand the application's internal structure.

For public-facing websites, keeping display_errors disabled is considered a security best practice.

Best Practices

Enable display_errors only during development.

Keep display_errors = Off on production servers.

Enable log_errors to preserve diagnostic information.

Restart PHP-FPM after changing configuration values.

Verify the setting using phpinfo() or php -i.

Conclusion

The display_errors directive controls whether PHP displays runtime errors directly in the browser. While enabling it can simplify debugging during development, it should generally remain disabled on production servers to avoid exposing sensitive information.

A common production configuration is to disable error display while enabling error logging, providing a balance between security and effective troubleshooting.

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 →