Skip to content

Managing PHP error messages with the display_errors directive

The display_errors directive in PHP controls whether error messages are shown directly in the browser. On ruachost.com, you can enable or disable this setting depending on whether you are developing or running a production site.

  • Development: Helpful for debugging by showing detailed error messages.
  • Production: Error messages can reveal sensitive information (paths, variables) and should be hidden.
  • By default, PHP displays error messages in the browser.
  • This is useful during development but poses a security risk once your site is live.

Add or edit the directive:

display_errors = On ; Enable error display
display_errors = Off ; Disable error display

If your hosting environment supports .user.ini, add:

display_errors = Off

On Apache servers, you can override the directive:

php_flag display_errors Off
  1. Log in to cPanel.
  2. Go to Software → Select PHP Version → Options tab.
  3. Locate display_errors.
  4. Toggle between On (development) and Off (production).
  5. Save changes.
  • Create a test script with an intentional error:

    <?php
    echo $undefined_variable;
    ?>
  • If display_errors = On, the error appears in the browser.

  • If display_errors = Off, the error is hidden.

  • Always disable error display (Off) on production sites.
  • Use error logging (log_errors = On) to capture errors securely.
  • Combine with error_reporting to fine‑tune which errors are logged.
  • Delete test scripts after verification for security.