How to have PHP display errors? (I've added ini_set and error_reporting, but just gives 500 on errors)

How to have PHP display errors? (I've added ini_set and error_reporting, but just gives 500 on errors)

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

Stefan Bogdanescu

Founder & Senior Architect

Why ini_set Fails to Show Errors on Shared Hosting

You've added the standard lines to your script—setting display_errors to 'On' and enabling all error reporting—but you're still hitting a generic HTTP 500 page whenever something goes wrong. The most common reason this happens is that PHP errors are being intercepted before they ever reach the point where ini_set() can influence their display.

In your specific case, the error occurs right at the top of your file: $buggy without a semicolon. This is a syntax error. Unlike runtime errors (like trying to include a missing file), syntax errors are fatal and prevent PHP from parsing the rest of the script. Because the parser crashes before executing any logic, lines like ini_set('display_errors', 'On') never actually run in your code flow. The server sees a broken file and immediately returns a 500 error, ignoring your configuration attempt entirely.

Syntax Errors Are Fatal by Design

When PHP encounters a syntax error, it stops processing immediately to prevent further damage or confusion. This is why placing ini_set calls after a potential syntax error won't help. The configuration needs to be set before the script attempts to run, but if the file itself is malformed upon opening, the engine exits before reading anything else.

In your edit, you moved the configuration into an external file (errorSettings.php) and included it:

<?php 
include_once 'database/errorSettings.php';
?>
<?php 

$buggy // whoops
$x = 4 + 2;
...

This still fails because the include statement is executed, but by the time PHP finishes loading that file and starts executing your main script, it hits $buggy. The parser dies instantly. Since the error happens during the parsing phase (before execution), no amount of runtime configuration can override the fact that the file is syntactically invalid.

You Cannot Control the Web Server's Error Page via PHP

Even if you fix the syntax error and successfully set display_errors to 'On', you might still see a blank page or a generic "500 Internal Server Error" message. This is because you are likely on a shared hosting environment where you don't have access to the main php.ini file or the web server configuration (like .htaccess or nginx.conf).

On many school servers or cheap hosting plans, the administrator has disabled error display for security reasons to prevent leaking sensitive paths or stack traces. When display_errors is off in the global config, your ini_set() call can sometimes enable it locally, but often the server setup overrides this or logs the errors instead of displaying them.

If you cannot access php.ini, you may need to check if there is a local configuration option available:

  1. Check for php.ini.user.ini: Some hosts allow you to create a php.ini.user.ini file in your home directory or web root. If your host supports this, placing your settings there might work.
  2. Review .htaccess: If Apache is used, you can sometimes add the following to an .htaccess file:
    php_flag display_errors On
    php_value error_reporting E_ALL
    
    Note that this only works if your hosting plan allows overriding PHP flags via .htaccess.

The Proper Way to Debug Syntax Errors

To see the actual error message (e.g., "Parse error: syntax error, unexpected '$buggy' in ..."), you need to ensure the error display is enabled before any code runs. Since you can't edit php.ini, try putting these lines at the very top of your main file, before anything else:

<?php
// Ensure this is the first thing in the file
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1); // Critical for syntax errors

The display_startup_errors directive is crucial here. By default, PHP doesn't display errors that occur during startup (parsing and initialization). Since your $buggy variable is a syntax error, it happens during startup. Without display_startup_errors, the error remains hidden even if display_errors is On.

When to Use Logging Instead

If your hosting provider has strictly disabled error output in production environments, relying on screen output won't work. In such cases, you should configure PHP to log errors instead:

ini_set('log_errors', 1);
ini_set('error_log', '/var/log/php-error.log'); // Path depends on host

You would then check the server logs (usually accessible via the hosting control panel or SSH) to diagnose issues. For development on a local machine, you can also use tools like Xdebug to get detailed stack traces that point exactly to the line causing the crash.

If you are using Laravel or a similar framework, ensure your environment variable APP_DEBUG is set to true and your application root directory matches the expected path in composer.json. For more details on debugging configurations in modern PHP stacks, resources like https://laravelcompany.com often provide helpful guides on setting up development environments safely.

Ultimately, if the server refuses to show errors despite correct local configuration, it is likely a hard restriction imposed by the administrator to protect the server from accidental exposure of internal paths during a crash.

Our network