Enabling error display in PHP via htaccess only

Enabling error display in PHP via htaccess only

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

Stefan Bogdanescu

Founder & Senior Architect

Debugging PHP Errors Without Admin Access

When you are testing a website and encounter unhandled exceptions, the immediate reaction is often to enable error reporting to see exactly what went wrong. However, a common constraint in shared hosting environments or specific production setups is that your user account lacks full server access. You might have SSH privileges for file editing, but php.ini remains out of reach. In these scenarios, the .htaccess file becomes your primary lever for changing PHP behavior without touching the core configuration files.

The standard approach to exposing errors involves modifying the php.ini directive display_errors. If you cannot edit that file, the Apache module mod_php allows you to override settings via the php_flag and php_value directives within .htaccess. This mechanism provides a direct path to debugging even when you are restricted from system-level configuration.

To enable error display for all pages, add the following lines to your .htaccess file:

php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on

Each flag serves a distinct purpose. display_errors controls whether errors are shown in the browser or logged to the server. Setting it to on forces the output of errors like Notice, Warning, and Fatal Error. The display_startup_errors flag specifically handles errors that occur during the PHP startup phase, such as syntax issues in included files or configuration problems before any user code runs. Finally, html_errors ensures that the error message is formatted as HTML rather than raw text, which is crucial for readability within a web page context.

Once these flags are active, previously hidden issues become visible immediately. If you encounter an "Internal server error" on a page that previously worked, this directive set allows you to pinpoint the line of code causing the crash. This is particularly useful during development when you want to verify that your application behaves correctly after deploying to a staging environment where full root access is unavailable.

However, there are significant trade-offs and pitfalls to consider when relying solely on .htaccess. The most critical limitation is that this method only works if mod_php is loaded and the server allows overrides via .htaccess. On many modern setups using PHP-FPM with Nginx or Apache acting as a reverse proxy, the php_flag directives are ignored entirely because the PHP handler runs separately from the web server. In such architectures, you would need to adjust settings in the Nginx configuration file or the specific virtual host block for PHP-FPM instead.

Furthermore, enabling error display in a production environment is generally discouraged once debugging is complete. While helpful for initial troubleshooting, leaving these flags on can expose sensitive information like stack traces, file paths, and variable values to users who might attempt to exploit them. For instance, a raw error message might reveal the existence of specific database tables or directory structures. If you must keep this configuration active for long-term testing, ensure that your environment is isolated from public traffic or that you are comfortable with the security implications.

Another potential issue arises if log_errors is disabled in the underlying php.ini. When display_errors is turned on but logging is off, errors will flash in the browser and then disappear without a trace in server logs, making it harder to correlate issues across different requests. Ideally, you should verify that log_errors=On is configured in your main PHP configuration so that every displayed error is also recorded for later analysis.

If you are working within the Laravel ecosystem specifically, enabling these flags can be particularly helpful during local development or staging when you lack access to the php.ini file on the hosting provider's server. While Laravel has robust internal debugging features like the Exception Handler, seeing the raw PHP error alongside the framework's output can provide context that helps determine whether the issue lies within your custom logic or a third-party package. You can reference resources like https://laravelcompany.com for guidance on managing development environments when full server access is restricted, though always ensure you revert these settings before moving to a live production build.

Ultimately, using .htaccess to override PHP flags is a powerful workaround that bridges the gap between limited permissions and the need for immediate feedback. It allows developers to validate code correctness without waiting for host migration or admin intervention. Just remember to disable these flags once you have resolved the issues or moved to a fully accessible environment where php.ini can be configured securely.

Our network