Showing all errors and warnings

Showing all errors and warnings

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

Stefan Bogdanescu

Founder & Senior Architect

Why PHP Errors and Warnings Aren't Appearing in Your Browser

You are likely encountering a frustrating scenario where your script generates clear warnings or exceptions—visible clearly in Apache logs—but remains invisible to the end-user in their browser. The code snippet provided attempts to handle form validation and database operations, yet when logic fails (such as attempting an invalid SQL operation), the error is swallowed. This disconnect usually stems from how PHP handles output buffering, configuration layers, and the specific context of where errors occur.

The Configuration Layer Mismatch

The root cause often lies in the interaction between php.ini settings and the actual execution environment. You mentioned setting display_errors = On and configuring error_reporting to include E_ALL and E_STRICT. While these are the correct directives for a development server, they do not always behave as expected in production or specific virtual host configurations.

Even after restarting Apache with commands like /etc/init.d/apache2 restart, changes to php.ini might not take effect if your application is running under a different pool of processes (such as PHP-FPM) or if the configuration file being read isn't the one you edited. Additionally, simply setting error_reporting(E_ALL) inside the script is a best practice for local debugging, but it does not override server-level suppression if display_errors is set to Off in the .htaccess file or the specific virtual host configuration. If your web server is configured to hide errors for security reasons (a common default in production), PHP will log the error but suppress the output stream.

Output Buffering and Early Exit

A critical factor in this behavior is output buffering. Many web servers and frameworks buffer output until the script finishes or a specific flush occurs. If an error happens before any output has been sent to the browser, modern PHP versions might handle it differently depending on the zlib.output_compression setting or if the server expects a full page response.

However, looking closely at the provided code, there is a more immediate culprit: the flow of execution. In your script, you have an if ($err) block that executes database logic. Inside this block, after successfully executing the queries (or catching exceptions), you call header() and then exit().

The problem arises if an error occurs before any headers are sent, but the server configuration is strict about output control. More importantly, if your Apache logs show an error occurring during the try...catch block, specifically inside the database execution, and the code subsequently calls header() followed by exit(), the script terminates immediately. If the error happened before this point, it might have been buffered but not flushed because the script continued to render the HTML.

The real issue in your specific case, however, is likely that the error is happening, being caught by a custom handler or suppressed by the server configuration, and then the script proceeds to output HTML without flushing the buffer state correctly regarding the error message. The catch block echoes the exception, but if the display_errors setting is effectively off at the Apache level, that echo might be suppressed depending on how the web server interprets the request lifecycle.

The Danger of Swallowing Exceptions

In your code, you are wrapping database interactions in a try...catch (PDOException $e) block and echoing $e->getMessage(). This is excellent practice for debugging, but it can mask the root cause if the exception is not being logged to the error log or if the output is intercepted.

When you change an "insert" statement to a "delete into" statement without proper context (as mentioned in your updates), PHP generates a SQL syntax error. If display_errors is off, this raw stack trace never reaches the browser. Instead, it goes into the Apache error log. To fix this visibility issue without disabling production safety features, you should ensure that your .htaccess file or virtual host config does not contain php_flag display_errors Off.

Instead of relying solely on display_errors, consider setting log_errors = On to capture these events in a file where you can inspect them later. This allows you to maintain a clean user interface while still having visibility into failures. You can verify your effective configuration by running php -i | grep display_errors from the command line to see if the local settings match what the web server is actually using.

Debugging Without Breaking Production

The most robust solution for displaying errors temporarily without exposing full stack traces in production is to use error logging combined with a custom error handler. You can create a script that logs every error to a file and then displays a generic message to the user. However, for immediate debugging, ensuring that display_errors is On in the specific configuration file used by your web server (often found in the conf.d directory) is the most direct path.

If you continue to see errors in logs but not on the page, check for output buffering issues. Adding ob_end_clean() before attempting to display errors can sometimes help flush previous buffers, though this is less likely the primary cause here compared to configuration mismatches. The key takeaway is that browser visibility depends entirely on the server's permission to send error headers and bodies to the client.

Our network