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.
Why Manage Error Display?
Section titled “Why Manage Error Display?”- Development: Helpful for debugging by showing detailed error messages.
- Production: Error messages can reveal sensitive information (paths, variables) and should be hidden.
Default Behavior
Section titled “Default Behavior”- By default, PHP displays error messages in the browser.
- This is useful during development but poses a security risk once your site is live.
How to Configure display_errors
Section titled “How to Configure display_errors”1. Using a Custom php.ini File
Section titled “1. Using a Custom php.ini File”Add or edit the directive:
display_errors = On ; Enable error displaydisplay_errors = Off ; Disable error display2. Using .user.ini
Section titled “2. Using .user.ini”If your hosting environment supports .user.ini, add:
display_errors = Off3. Using .htaccess
Section titled “3. Using .htaccess”On Apache servers, you can override the directive:
php_flag display_errors Off4. Using cPanel (CageFS Enabled Accounts)
Section titled “4. Using cPanel (CageFS Enabled Accounts)”- Log in to cPanel.
- Go to Software → Select PHP Version → Options tab.
- Locate
display_errors. - Toggle between On (development) and Off (production).
- Save changes.
Verification
Section titled “Verification”-
Create a test script with an intentional error:
<?phpecho $undefined_variable;?> -
If
display_errors = On, the error appears in the browser. -
If
display_errors = Off, the error is hidden.
Best Practices
Section titled “Best Practices”- Always disable error display (
Off) on production sites. - Use error logging (
log_errors = On) to capture errors securely. - Combine with
error_reportingto fine‑tune which errors are logged. - Delete test scripts after verification for security.