500 Internal Server Error: how to diagnose and fix it
500 Internal Server Error is a catch-all for an unhandled server-side exception. The status itself tells you nothing — the real cause is in your application log (a stack trace), so go find that.What causes 500 Internal Server Error
An unhandled exception in application code; a failed database or external call; a misconfiguration (missing env var, bad file permission); or an out-of-memory/crash mid-request.
How to diagnose it
Read the application log at the moment of the 500 — it holds the stack trace with the actual exception and line. In frameworks, enable debug logging temporarily. Correlate the access-log 500 timestamp with the app log.
How to fix 500 Internal Server Error
- Find the stack trace. Open the app log (not just the web server log) at the 500's timestamp — the exception type and line are the real error.
- Reproduce and fix the exception. Fix the root cause — null handling, a failed query, a missing config value — not the symptom.
- Add error handling + monitoring. Wrap risky calls, return proper 4xx where appropriate, and alert on 500 rate so you catch regressions early.
Example log line
ERROR app: Traceback (most recent call last): ... KeyError: 'user_id' -> 500 POST /api/checkout
How LogLens detects 500 Internal Server Error
LogLens groups 500s with the exact exception templates behind them, so you see the one real cause instead of scrolling the access log. LogLens AI is a free, self-hosted AI log analyzer that surfaces lines like this automatically, groups them into one incident, and explains them in plain language.
Related errors
FAQ
How do I see what caused a 500 error?
Look in your application log (not the web server access log) at the time of the request — it contains the stack trace with the actual exception.
Is a 500 a client or server problem?
Server-side. It means your application threw an error it did not handle. The client can only retry.