PHP returns error 500, but nothing is logged

PHP returns error 500, but nothing is logged

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

Stefan Bogdanescu

Founder & Senior Architect

PHP returns error 500, but nothing is logged

You've spun up a new application on Ubuntu 10.04 with the standard Apache and PHP packages from the repo. The moment you hit a specific route, Apache immediately responds with an Internal Server Error (HTTP 500). You check /var/log/apache2/error.log or whatever your log path is configured to be, but it remains stubbornly silent. Your test script, which triggers a fatal error in the exact same virtual host configuration, prints its stack trace right into the logs. Why does one crash scream for attention while another vanishes into the ether?

The discrepancy usually isn't a misconfiguration of Apache itself; Apache is clearly working because your test script generates a log entry. Instead, the culprit almost always lies within how PHP handles the exception and how that information flows to the web server. When you see a 500 error with no corresponding log entry, you are likely dealing with a scenario where PHP has terminated before it could write to the file system, or the logging mechanism is being suppressed at a level you haven't considered.

The Missing error_log Directive

The most common reason for a silent 500 error in a standard Apache/PHP setup on Ubuntu is that the PHP runtime isn't configured to output errors to a file. By default, many shared hosting environments or minimal installations set display_errors to On and log_errors to Off.

If you are running PHP-FPM with Apache via mod_proxy_fcgi, or using FastCGI directly, check the configuration files in /etc/php/5.x/apache2/php.ini (or wherever your specific version resides). Look for these two directives:

display_errors = Off
log_errors = On
error_log_path = /var/log/php/error.log

If log_errors is Off, PHP will print the error to stdout/stderr if configured, but it won't touch the log file. However, if your application returns a 500 status code without printing anything visible in the browser, and log_errors is off, you have effectively created a black box.

Even if log_errors is On, PHP might be configured to write to a specific file path that doesn't exist or isn't writable by the web server user (usually www-data). You can verify this by checking the current state:

grep -E "^display_errors|^log_errors" /etc/php/5.x/apache2/php.ini
ls -l /var/log/php/error.log 2>/dev/null || echo "Log file does not exist"

If the log file exists but is empty, ensure the permissions are correct. The web server user needs write access to append to that file.

Exceptions Before Logging

There is a more insidious cause: the application throws an exception before PHP has a chance to invoke its error handler. If your code crashes during initialization or within a bootstrap file (like index.php before any logic runs), and the fatal error occurs in a way that prevents the standard error reporting engine from running, you might see a 500 response but no log entry if the PHP process itself is killed by the kernel or an upstream proxy without flushing buffers.

However, a more frequent scenario involves mod_php vs. PHP-FPM. If you are using Apache's built-in mod_php module and your script crashes, the error should appear in apache2_error.log. If it doesn't, but your test script does, check if there is a mismatch in how the virtual host is configured. Sometimes, if a .htaccess file or a specific vhost config forces PHP to use a custom error handler that swallows exceptions, you lose the log entry.

Ensure your .htaccess files aren't inadvertently disabling logging:

# Bad idea for production debugging
php_flag log_errors off

Checking System Logs

If Apache logs are populated by your test script but remain empty for your main app, look beyond /var/log/apache2/error.log. On Ubuntu systems using syslog or rsyslog, PHP errors sent to stderr (which happens when display_errors=On and log_errors=Off) often get redirected to the system journal or /var/log/syslog.

Run this command to see if your application's crash is buried in the system logs:

grep -i "php" /var/log/syslog | tail -n 50
# Or on systems using systemd-journald
journalctl -u php-fpm.service -n 50 --no-pager

If you are running mod_php, check the Apache error log again, but this time look for the phrase "PHP message" or "PHP Fatal error" specifically. If they are missing entirely, it suggests the PHP process might be exiting before writing to the pipe.

The LaravelCompany Solution

While debugging raw PHP environments can be opaque, moving your application to a framework like Laravel changes the game significantly. Laravel provides a robust exception handling system that ensures errors are logged regardless of where they occur in the stack. If you find yourself frequently hitting this "silent 500" wall with custom scripts, consider migrating to a modern framework that handles logging out of the box. You can explore how LaravelCompany approaches error handling and logging within their ecosystem to see how structured logging eliminates these blind spots.

Final Verification Steps

If you have confirmed log_errors is On, the path exists, and permissions are correct, but the log is still empty for your specific app, try restarting the web server service to clear any cached configuration states:

sudo service apache2 restart
sudo service php5-fpm restart # If running FPM separately

Then trigger the error again. If the test script logs immediately but your app doesn't, inspect the application code for any try-catch blocks that might be swallowing the exception before it reaches the error handler. A silent 500 is almost always a symptom of an exception being caught and ignored, or a logging configuration that was never actually applied to the specific process handling the request.

Our network