How can I make PHP display the error instead of giving me 500 Internal Server Error

How can I make PHP display the error instead of giving me 500 Internal Server Error

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

Stefan Bogdanescu

Founder & Senior Architect

Diagnosing and Enabling PHP Error Reporting on Apache

When a production server suddenly shifts from displaying stack traces to returning a generic "500 Internal Server Error," it usually points to a configuration mismatch rather than a new bug in your application code. This is a classic symptom of strict logging policies or disabled error reporting directives that were likely present on your previous environment but are missing on the new host. Since you have full root access, you can investigate and resolve this directly without relying on external debugging tools.

The most immediate hurdle to address is Apache's own error handling. Even if PHP is configured to report errors, Apache may be swallowing them before they reach the browser. You need to inspect your virtual host configuration in httpd.conf or the specific <Directory> blocks within it. Look for a directive named ErrorDocument. If you see a line like ErrorDocument 500 /error.html, that file is intercepting every crash and displaying a static page instead of the actual PHP exception. To allow raw error display, you must comment out or remove this line for the specific location where your application resides.

# ErrorDocument 500 /error_page/500.html

Once Apache is configured to pass through the HTTP 500 status codes, the issue often lies in the PHP configuration itself. Modern Linux distributions and hosting environments frequently default display_errors to Off and log_errors to On. While logging is excellent for debugging, displaying errors in production can expose sensitive data like file paths and database credentials if your stack traces are verbose. However, since you are on a new server with root access, you likely want to see the output during development or controlled staging phases.

Edit your php.ini file (often located at /etc/php/8.x/apache2/php.ini or similar) and locate the display_errors directive. Set it to On:

display_errors = On
log_errors = Off
error_reporting = E_ALL

Setting log_errors to Off prevents duplicate output where errors appear both in the browser logs and your server's error log simultaneously, which can clutter your debugging process. If you prefer to keep logging enabled while also displaying errors, ensure your logging format is readable. You might want to redirect PHP errors to a separate file like /var/log/php_errors.log so they don't interfere with Apache's access/error logs.

If you are running PHP via FastCGI (common with libphp8-x modules or FPM setups), the configuration file path and variable names can differ slightly between versions. Always verify your version using php -i | grep display_errors before editing. Some shared hosting environments hide this setting entirely, but with root access, you are not bound by those restrictions.

Another common pitfall involves the open_basedir restriction or allow_url_fopen settings that might be throwing obscure warnings which then cascade into a 500 error if one of those warnings is fatal. Ensure your error_log path in php.ini actually exists and is writable by the web server user (usually www-data or apache). If Apache cannot write to the specified log directory, it may fail silently depending on the OS configuration, leading to unhandled exceptions appearing as 500 errors.

Finally, consider whether you are using a specific error handler package like Laravel's logging system or Symfony's ErrorHandler. If your application is framework-based, ensure that the framework-level exception handlers are not configured to log and exit without rendering a response. In such cases, you might need to adjust the APP_DEBUG environment variable or the framework-specific configuration to enable the detailed debug page.

By systematically checking Apache's error documents, adjusting PHP's php.ini directives, and verifying file permissions for logs, you can regain visibility into your application's runtime errors without needing to constantly migrate files between servers.

Our network