Skip to content

Enabling and disabling PHP error messages in .htaccess

The display_errors directive in PHP controls whether error messages are shown in the browser. By default, error messages may be enabled during development but should be disabled in production for security reasons. On ruachost.com, you can configure this setting using a custom .htaccess file.

  • Enable: Useful during development to debug issues quickly.
  • Disable: Prevents sensitive information (like file paths or variables) from being exposed to users.

Steps to Configure display_errors in .htaccess

Section titled “Steps to Configure display_errors in .htaccess”
  • Log in to cPanel or use FTP/File Manager.
  • Navigate to your site’s root directory (e.g., /public_html).
  1. If .htaccess already exists, open it for editing.
  2. If not, create a new file named .htaccess.

Insert one of the following lines depending on your needs:

# Enable error messages (development only)
php_flag display_errors On
# Disable error messages (recommended for production)
php_flag display_errors Off
  1. Save the .htaccess file.

  2. Create a test file info.php with:

    <?php phpinfo(); ?>
  3. Load it in your browser and search for display_errors.

  4. Confirm whether it is enabled or disabled.

  5. Delete the test file afterward for security.

  • Keep display_errors On only in development environments.
  • Always set display_errors Off in production to avoid exposing sensitive details.
  • Use log_errors and error_log to capture errors privately while keeping them hidden from users.