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
.htaccessdirective (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
- Check the application log and web server error log at the timestamp of the request
- Temporarily enable detailed errors in a non-production environment
- Roll back the last deploy if the error started right after it
- Verify environment variables, DB credentials and writable folders
- Rename
.htaccesstemporarily to test whether it’s the cause
Detailed fix by platform
Apache
- Check
error_logfor "Invalid command" (missing module) or "RewriteRule: bad flag". - Enable the required module (
sudo a2enmod rewrite headers) or remove the directive.
Nginx
- Nginx itself rarely produces 500; look at the upstream app (PHP-FPM, Node, Python) logs. Also check
/var/log/nginx/error.logfor rewrite cycles.
PHP
- Log everything, display nothing in production:ini
display_errors = Off log_errors = On error_log = /var/log/php/error.log error_reporting = E_ALL - Laravel: check
storage/logs/laravel.log; ensurestorage/andbootstrap/cache/are writable.
Node.js
- Wrap async route handlers so rejected promises reach your error middleware; log
err.stack.
WordPress
- Set
define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false);and readwp-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-pagerHow to diagnose
- Reproduce — Does it fail every time or intermittently?
- Logs — App log + server error log at the same timestamp
- Recent change — Deploy, config, dependency or data change?
- Dependencies — Database, cache, external API reachable?
- 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026