HTTP 500 Internal Server Error — What Causes It and How to Debug

A 500 error means the server hit an unexpected condition it couldn't handle. Learn how to find the real cause using server logs and where to start debugging.

Published September 20, 2026

HTTP 500 means the server hit an unexpected error while handling a valid request. The cause is on the server side, so the fix starts with the error log, not the browser.

The concept

500 is the generic 'something broke' status. Typical causes: an uncaught exception, a syntax error after a deploy, a failed database connection, a missing environment variable, wrong file permissions or a misconfigured server.

The browser cannot tell you why, so reproduce the request, read the application and web-server logs, and look at the stack trace.

Debugging checklist

  1. Reproduce it: curl -i the exact URL
  2. Read the log: storage/logs, Nginx/Apache error log
  3. Find the first exception and its file/line
  4. Fix and verify with the same request

Practical examples

Tail the logs

tail -f storage/logs/laravel.log
tail -f /var/log/nginx/error.log

Reproduce with curl

curl -i -X POST https://api.example.com/orders -d '{"x":1}' -H 'Content-Type: application/json'

Catch and log in Express

app.use((err, req, res, next) => {
  console.error(err.stack)
  res.status(500).json({ error: 'Internal error' })
})

Typical config culprits

# PHP
chmod -R 775 storage bootstrap/cache
php artisan config:clear

Common mistakes

  • Showing stack traces to users in production.
  • Returning 500 for validation problems (use 400/422).
  • Not logging the real error.
  • Only checking the frontend.

Key takeaways

  • 500 = server bug or misconfiguration.
  • Logs are the answer.
  • Return meaningful 4xx codes for client mistakes.

FAQ

500 vs 502 vs 503?

500 is the app failing, 502 a bad response from an upstream, 503 temporary unavailability.

Can a user fix a 500?

Rarely; they can retry, but the site owner must fix the cause.

More HTTP articles