500 Internal Server Error

The server tried to handle your request, something went wrong inside it, and it has no more specific way to say so. This is the only error that means the fault is definitely at the other end.

500 Internal Server Error

The short version

  • A 500 is always a server-side fault. Nothing you clear or restart will change it.
  • It is the generic code: The server failed and had nothing more specific to report.
  • It usually means an unhandled exception in the application, not an infrastructure failure.
  • If you can reproduce it on one specific action, that detail is worth reporting.

Of every error code on the web, 500 is the one that tells you least about the cause and most about the responsibility. It means: The server received your request, understood it, began to process it, and then hit a condition it did not know how to handle.

The HTTP specification describes it as the response for "an unexpected condition that prevented it from fulfilling the request". Unexpected is the operative word. A 500 is what a server sends when it has run out of more specific things to say.

What is actually happening

In the overwhelming majority of cases, an unhandled exception. Somewhere in the application code that was assembling your page, something threw an error that nobody caught - A null value where an object was expected, a division by zero, a malformed row in a database, a library that raised something the calling code did not anticipate.

The web server catches that at the outermost layer, logs a stack trace, and returns 500 because the alternative is returning a half-built page or nothing at all. On the server side there is almost always a detailed error in a log file with the exact line number. On your side there is a number.

Other, less common producers of a 500:

  • Database connection exhaustion. The pool is full, a query cannot get a connection, and the resulting exception surfaces as a 500. Common under load.
  • A misconfiguration. On Apache, a syntax error in .htaccess produces a 500 for every request under that directory. This is far and away the most common cause on shared hosting.
  • Permissions. A script that cannot be executed, or a directory the server cannot read, on hosts that run scripts directly.
  • A memory limit. The process was killed mid-request for exceeding its allocation.
  • A failed deploy. Code shipped that references something not yet present - A migration not run, an environment variable not set.

Why this one is never your fault

The 5xx family exists to distinguish server errors from client errors. A 404 or a 403 is the server saying your request was wrong. A 500 is the server saying its own handling was wrong.

That distinction is worth holding onto, because the standard advice people are given - Clear your cache, restart your router, try a different browser - Makes no sense here. Your request arrived and was understood. The failure came afterwards, in code you have no access to.

The one exception: If a 500 appears only when you submit a particular form or use a particular character in a field, you have probably found input the application does not handle. That is still the server's bug, but the workaround - Changing what you type - Is available to you.

500 versus its more specific relatives

CodeWhat it meansWhere the fault is
500The application itself failedInside the application
502A proxy got an invalid response from upstreamBetween the proxy and the app
503Temporarily unable to handle the requestCapacity or deliberate maintenance
504A proxy waited for upstream and gave upThe app is too slow or hung

The practical difference matters when you are estimating how long to wait. A 502 or 504 usually means an application process has died or stalled and will be restarted automatically within minutes. A 503 with a Retry-After header is a deliberate and usually brief decision. A 500 is a code bug, and a code bug needs a human to deploy a fix - Which takes longer.

What to do as a visitor

  1. Reload once. If the error came from a transient condition - A connection that timed out, a race - A second request may well succeed. Once, not repeatedly.
  2. Note exactly what you did. A 500 on one specific action is far more useful to report than "the site is broken". It tells the operator which code path to look at.
  3. Try without the query string. If the URL has parameters, loading the bare page tells you whether the error is specific to that input.
  4. Check whether it is everyone. A check from another network distinguishes a site-wide failure from something specific to your request or session.
  5. Wait. Genuinely the answer. Consumer-facing 500s at large services are usually noticed within minutes because error-rate alerting is standard.

If it is your site

The log has the answer. On any modern stack the 500 was accompanied by a stack trace with a file and line number; the whole job is finding where that goes. Application logs first, then the web server error log, then the platform's log aggregator.

Three checks that resolve a large share of cases before you read anything: Did something deploy in the last hour, is the database reachable and under its connection limit, and is the disk full. The third causes remarkably many 500s and is invisible until you look, because a server that cannot write a session file or a temp file fails in ways that look nothing like a storage problem.

On shared hosting with Apache, check .htaccess first. A single unsupported directive produces a 500 for every request under that directory, and renaming the file to test takes five seconds.

Never show a stack trace to the public. A debug page exposes file paths, library versions, environment variables and sometimes credentials - That is a real disclosure, not a theoretical one. The generic page is generic for a reason.

Questions people ask

Is a 500 error my fault or the website's?

The website's, always. A 500 means the server received and understood your request and then failed while processing it. Clearing your cache, changing browser or restarting your router cannot affect code running on someone else's machine.

Will refreshing fix a 500 error?

Sometimes, if the cause was transient - A connection that timed out or a race condition. Try once. If it persists, repeated refreshing only adds load to a server that is already failing.

What is the difference between a 500 and a 502?

A 500 means the application itself threw an error. A 502 means a proxy in front of the application could not get a valid response from it at all - Usually because the application process has crashed or is not running. A 502 often resolves on its own when the process restarts; a 500 usually needs a code fix.

How long does a 500 error usually last?

It depends entirely on whether the cause is transient or a code bug. A momentary resource problem clears in seconds. A bug shipped in a deploy lasts until someone rolls back or ships a fix, which at a large service is typically minutes and at a small one can be hours.

Read next

502 Bad Gateway

What a 502 Bad Gateway error means, why it is one of the most common outage errors, and why it usually clears within minutes.

Error codes explained4 min read

503 Service Unavailable

What a 503 Service Unavailable error means, why it is often deliberate, and what the Retry-After header tells you about how long to wait.

Error codes explained4 min read

504 Gateway Timeout

What a 504 Gateway Timeout means, why it indicates a stuck rather than a dead application, and what usually causes the delay.

Error codes explained4 min read

Cloudflare error codes

What Cloudflare errors 520, 521, 522, 523, 524, 525 and 526 mean, and whether the fault is Cloudflare or the website behind it.

Error codes explained4 min read