“Heard about Sevalla? They let you deploy PHP apps with ease.” Claim $50 →

PHP: show all errors (E_ALL) safely

3 minutes read

PHP: show all errors (E_ALL) safely

Show all PHP errors using ini_set() and error_reporting()

To display all PHP errors during development, place this snippet at the top of your PHP script:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Using PHP’s built-in ini_set() and error_reporting() functions, this ensures you won’t miss any runtime or startup issues, or subtle coding mistakes.

Here’s what each line does:

`display_errors`
Controls whether errors appear directly in the output. Setting this to `1` ensures errors are displayed. However, never enable this in production as it exposes sensitive server details.
`display_startup_errors`
Shows errors encountered during PHP’s startup phase. Essential for catching config problems early.
`error_reporting(E_ALL)`
Sets PHP to report every possible error, including warnings and notices. This is the most thorough level of error visibility. Note: The PHP error suppression operator (`@`) can individually silence errors regardless of this global setting.

Production-safe fallback

After debugging, ensure you turn error display off before deploying:

// Production-safe error handling
ini_set('display_errors', 0);
ini_set('log_errors', 1);
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);

In production, hiding errors from public view and logging them instead protects your app’s sensitive information.

Enable error reporting via php.ini

Prefer setting errors globally? Adjust these directives in your php.ini file:

  1. Run php --ini from your terminal to locate your active php.ini file.
  2. Open php.ini and locate the following directives:
display_errors = 1
display_startup_errors = 1
error_reporting = E_ALL
  1. Save your changes and restart your PHP server (Apache, Nginx, PHP-FPM) to apply these settings.

Pro tip: Remember, some environments like PHP-FPM pools can override these global settings. Double-check configuration if errors still aren’t appearing.

Quickly debug PHP from CLI

For a one-off debugging session in your terminal, use this handy shortcut:

php -d display_errors=1 -d error_reporting=E_ALL script.php

Consider advanced debugging tools

If you need more precise debugging, consider Xdebug or built-in debuggers in IDEs like VS Code or PhpStorm. These tools let you set breakpoints, step through code, and inspect variables in real-time.

Disable error reporting in production

Exposing PHP errors on a live site can unintentionally leak sensitive information, like your server’s configuration or paths. Always:

  • Disable display_errors.
  • Enable logging via:
log_errors = on
error_log = /path/to/non-public/error.log

This ensures you can review errors safely without revealing information publicly.

Also, be mindful of PHP version differences. PHP 8.4 (expected late 2025) slightly reclassifies error levels. Keep an eye on PHP’s official error reporting documentation for updates.


Did you like this article? Then, keep learning:

0 comments

Guest