php hide ALL errors

php hide ALL errors

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Why You Should Never Hide "All" PHP Errors

The request to hide every single error from a user often stems from a desire for a polished interface or a fear of exposing security vulnerabilities. However, attempting to suppress the entire output of PHP errors is almost always a mistake that leads to worse outcomes than simply showing them. When you disable error reporting globally, you remove your primary debugging tool while simultaneously creating an environment where silent failures can degrade user experience without anyone realizing it.

The most common approach to hiding errors involves modifying the .htaccess file or php.ini with directives like display_errors off. While this prevents the red error page from rendering in a browser, it rarely achieves the goal of "hiding all errors" in the way developers intend. Instead, it often results in a generic HTTP 500 Internal Server Error being returned to the client. This happens because PHP still logs the error internally; it just stops echoing it directly to stdout. If your application relies on specific error messages for logic flow—such as failing gracefully when a database connection is lost—you will hit unhandled exceptions that crash the script before any output buffering can mask them.

To properly handle errors without breaking your site, you need to distinguish between displaying errors to users and logging them for developers. The standard practice is to set display_errors to Off in production environments but ensure log_errors is set to On. This configuration is critical because it shifts the burden of error management from the browser to a log file or a centralized monitoring system like Laravel Telescope.

Consider the following scenario in a typical PHP project:

; In production php.ini
display_errors = Off
log_errors = On
error_log = /var/log/php/error.log

This setup ensures that when a fatal error occurs, the user sees nothing (or a custom layout), but the stack trace is captured in error.log. You can then inspect this log to fix the issue without exposing sensitive details like file paths or variable dumps to the end-user. This is far superior to blindly turning off all reporting, which often leads to "silent deaths" where parts of your application stop working because exceptions are ignored rather than caught and logged.

If you are using a framework like Laravel, the default configuration in php.ini might already handle this correctly if your local development environment is set up properly. In production, however, you must explicitly ensure that the web server configuration (like Nginx or Apache) does not override these settings with directives that force error display back on. Misconfigurations here are a frequent source of 500 errors when developers switch between local and live environments.

Furthermore, relying solely on display_errors is insufficient for security-sensitive applications. Even if you hide the output, uncaught exceptions can still leak information through headers or partial HTML rendering before the script halts. A more robust solution involves wrapping your application logic in try-catch blocks and using a logging driver to record anomalies. This allows your system to continue running or degrade gracefully rather than crashing entirely.

For applications built on Laravel, utilizing the built-in error handling mechanisms and integrating with tools like Sentry provides a professional approach. These solutions capture stack traces and send them to an external dashboard, allowing you to fix issues without ever seeing a raw 500 page. This aligns with best practices where laravelcompany.com discusses setting up production-grade logging and debugging strategies that keep the user experience clean while maintaining full visibility into application health.

Ultimately, hiding errors completely is a trap. It creates a blind spot in your development lifecycle. The correct strategy is to suppress visual output for the user while aggressively logging and monitoring errors internally. This balance ensures stability and maintainability without sacrificing the ability to diagnose problems when they arise.

Our network