500 🌐 HTTP

HTTP 500 Internal Server Error

The server hit an unexpected condition — usually an unhandled exception or misconfiguration in the application.

Meaning

A 500 is a generic “something broke on the server” response. The client usually can’t fix it; the real reason is in the server or application logs. In production, frameworks hide details for security, so the first step is always to find the log entry for the failing request.

Common causes

  • Unhandled exception in application code
  • Syntax error or fatal error (PHP) after a deploy
  • Invalid .htaccess directive (Apache returns 500 for unknown directives)
  • Database connection failure or failed query
  • Missing environment variables / config after deploy
  • File permission problems on cache, logs or upload folders
  • Exhausted memory or execution time limits

⚡ Quick fix

  1. Check the application log and web server error log at the timestamp of the request
  2. Temporarily enable detailed errors in a non-production environment
  3. Roll back the last deploy if the error started right after it
  4. Verify environment variables, DB credentials and writable folders
  5. Rename .htaccess temporarily to test whether it’s the cause

Detailed fix by platform

Apache

  1. Check error_log for "Invalid command" (missing module) or "RewriteRule: bad flag".
  2. Enable the required module (sudo a2enmod rewrite headers) or remove the directive.

Nginx

  1. Nginx itself rarely produces 500; look at the upstream app (PHP-FPM, Node, Python) logs. Also check /var/log/nginx/error.log for rewrite cycles.

PHP

  1. Log everything, display nothing in production:
    ini
    display_errors = Off
    log_errors = On
    error_log = /var/log/php/error.log
    error_reporting = E_ALL
  2. Laravel: check storage/logs/laravel.log; ensure storage/ and bootstrap/cache/ are writable.

Node.js

  1. Wrap async route handlers so rejected promises reach your error middleware; log err.stack.

WordPress

  1. Set define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false); and read wp-content/debug.log.

Code examples

Find the error for a request

bash
sudo tail -f /var/log/nginx/error.log /var/log/php*-fpm.log
journalctl -u myapp -n 100 --no-pager

How to diagnose

  1. Reproduce — Does it fail every time or intermittently?
  2. Logs — App log + server error log at the same timestamp
  3. Recent change — Deploy, config, dependency or data change?
  4. Dependencies — Database, cache, external API reachable?
  5. Resources — Memory, disk, permissions OK?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.