500 Internal Server Error
Unexpected server-side failures preventing request completion produce the 500 Internal Server Error status code, a catch-all for conditions not covered by more specific server errors.
Usage
The 500 Internal Server Error status code signals a generic failure on the server side. Due to the broad nature of this error, the specific cause depends on the environment. The web server is experiencing problems and the server administrator needs to take action to resolve the issue.
The error is often attributed to a permissions
problem on one or more files, a script timeout,
or corruption in the .htaccess file. The only
certainty is the HTTP request was not fulfilled.
Example
The client requests a resource and the server responds with a 500 Internal Server Error status code, indicating the request will not be satisfied.
Request
GET /news.html HTTP/1.1
Host: www.example.re
Response
HTTP/1.1 500 Internal Server Error
Content-Type: text/html; charset=UTF-8
Content-Length: 139
<html>
<head>
<title>Request Failed</title>
</head>
<body>
<p>The request failed due to a server error.</p>
</body>
</html>
500 vs 502, 503, and 504
The four common 5xx codes point at different layers, which narrows the first diagnostic step.
| Code | What failed | First place to look |
|---|---|---|
| 500 | The application itself raised an unhandled error | Application logs and stack traces |
| 502 | A gateway got an invalid response from upstream | Whether the upstream process is running |
| 503 | The server is up but declining requests | Overload, maintenance mode, or a full worker pool |
| 504 | A gateway timed out waiting for upstream | Slow queries or an unresponsive upstream |
A 500 is not heuristically cacheable, so a CDN holds it only when the response carries explicit freshness. During an incident a 500 usually reaches every client rather than being served from cache.
How to fix
Start with the error log. In nginx, check
/var/log/nginx/error.log. In Apache, check
/var/log/apache2/error.log or
/var/log/httpd/error_log. The log entry almost
always names the failing file and line number.
Common root causes and their fixes:
- File permissions. The web server process needs
read access to application files and write access
to upload or cache directories. On Linux, set
directories to
755and files to644. Confirm the owner matches the web server user (www-dataon Debian/Ubuntu,nginxorapacheon RHEL/CentOS). - Corrupted
.htaccess. On Apache, rename.htaccesstemporarily to confirm. A single invalid directive or a reference to an unloaded module triggers a 500 for every request in the directory tree. - PHP fatal errors. Syntax errors, undefined
function calls, and exceeded
memory_limitall produce a 500. Setdisplay_errors = Offandlog_errors = Oninphp.ini, then read/var/log/php/errors.log. Raisememory_limitwhen the log shows "Allowed memory size exhausted." - PHP-FPM crashes. When nginx proxies to
PHP-FPM and the pool dies, the error log shows
"upstream prematurely closed connection." Check
the PHP-FPM pool log for segfaults or
out-of-memory kills. Increase
pm.max_childrenif the pool runs out of workers. - Database connectivity. Wrong credentials,
unreachable host, or connection pool exhaustion
all surface as a 500. Test connectivity directly
from the server (
mysql -u user -p -h hostorpsql -U user -h host) to isolate the database from the application. - Disk full. A server with no free disk space
fails to write temporary files, sessions, or
logs. Run
df -hand clear old logs, cache files, or core dumps.
After identifying the cause, deploy the fix and monitor the error log for recurrence. Set up log alerting to catch 500 spikes before users report them.
Code references
.NET
HttpStatusCode.InternalServerError
Rust
http::StatusCode::INTERNAL_SERVER_ERROR
Rails
:internal_server_error
Go
http.StatusInternalServerError
Symfony
Response::HTTP_INTERNAL_SERVER_ERROR
Python3.5+
http.HTTPStatus.INTERNAL_SERVER_ERROR
Java
java.net.HttpURLConnection.HTTP_INTERNAL_ERROR
Apache HttpComponents Core
org.apache.hc.core5.http.HttpStatus.SC_SERVER_ERROR
org.apache.hc.core5.http.HttpStatus.SC_INTERNAL_SERVER_ERROR
Angular
@angular/common/http/HttpStatusCode.InternalServerError
See also
- RFC 9110: HTTP Semantics
- Google: HTTP status codes and network errors
- 501 Not Implemented
- 502 Bad Gateway
- 503 Service Unavailable
- 504 Gateway Timeout
- HTTP status codes