HTTP 500 Internal Server Error: how to find the cause and what to tell users

Open this example in the tool

Try it in the tool

HTTP Status Codes

Every HTTP status code with its RFC, meaning and when to use it.

Chmod Calculator

Translate 755 ↔ rwxr-xr-x ↔ u=rwx,g=rx,o=rx instantly.

HTTP 500 Internal Server Error is the catch-all for “the server hit something it did not expect”. It is defined in RFC 9110, section 15.6.1. The request may well have been fine, and the failure is on the server: an unhandled exception, a misconfiguration, or a dependency that broke.

The first ten minutes

  1. Find the log line. Every 500 should leave one: the application log, the web server’s error log, or the platform’s log viewer. Search for the time of the request or its request ID.
  2. Reproduce it with curl -i and the same method, headers and body. An error that only occurs with one input points at the code path; one that happens for every request points at configuration or a dependency.
  3. Look at what changed: the last deploy, a new environment variable, a rotated secret, a database migration, a full disk.
  4. Check the dependencies: the database, cache, queue and any third-party API. A timeout there often becomes a 500 in your application.

Common causes

Where Typical cause
Any application an unhandled exception, a null value, a failing JSON parse of a database column
PHP a syntax error, a missing extension, memory_limit reached, a wrong .htaccess directive
Node a rejected promise nobody handles, a missing environment variable at start-up
Apache a bad rule in .htaccess (the log says Invalid command), wrong permissions on a script or folder
Database a connection limit reached, a lock, a failed migration
Platform out of memory, a full disk, an expired certificate for an internal call

On shared hosting, permissions are a classic cause. Scripts are normally 644 with folders 755; some hosts refuse to run anything writable by the group or by others. If the 500 started after files were copied from another machine, check the modes with the chmod calculator and read 755 and 644.

What a good 500 looks like

HTTP/1.1 500 Internal Server Error
Content-Type: application/json

{"error":"internal_error","message":"Something went wrong on our side.","request_id":"9f2c1d7e"}

Log the full error with the same request_id, so a user can quote it and you can find it. The user should see nothing about the internals.

500 compared with 502, 503 and 504

  • 500: the application itself failed.
  • 502: a proxy or gateway got an invalid answer from the application behind it.
  • 503: the service is unavailable now (overload, maintenance), and you may say when to come back.
  • 504: the proxy waited and the application did not answer in time.

The HTTP status codes tool opens the four together. If a 500 appears under load only, or with one specific input, add a test that reproduces it before you fix it, so it does not return.

Frequently asked questions

Can the visitor fix a 500?

Almost never. Reload once, since some are brief, and try again later. If it persists, tell the site owner what you did and when it happened; with a request ID, even better.

What should a 500 response show to users?

A short apology, a request ID and perhaps a link to the status page. Never the stack trace, file paths, SQL or configuration: they help an attacker more than they help the user.

Why does my site show a blank page with 500 and nothing in the log?

The error was written somewhere else or not at all. PHP sends errors to its own log, and with display_errors off the page stays empty. Check error_log, the application's log and the web server's log, and raise the log level while you debug.

Is 500 a good response for invalid input?

No. Invalid input is the client's mistake, so answer 400 or 422. A 500 on bad input hides real server failures in your monitoring and makes clients retry in vain.

More in this reference