What causes a 500 error in a PHP script?
PHP hit a problem it could not recover from — usually a broken .htaccess, a fatal error in the code, or a limit it ran straight into.
A 500 error is a deliberately vague, generic response the server sends when something failed and it has no more specific status code that fits. It tells a visitor almost nothing on its own — the actual cause is always something specific, and it is almost always recorded somewhere you can look, even though the page itself does not say what.
The most common causes, roughly in order of likelihood
- A syntax or fatal error in PHP code — a recently edited file, a plugin update, or a package that is not compatible with the current PHP version.
- A broken .htaccess file — a single malformed line in this file can return a 500 for the entire site it applies to. See using .htaccess for what it does and how a mistake in it behaves this way.
- A limit that was exceeded — memory exhausted, or the maximum execution time reached, both of which PHP treats as fatal and both of which produce a 500.
- A missing or incompatible PHP extension — code calling a function from an extension that is not enabled for the site's current PHP version.
- File permission problems — a file the web server process cannot read or write to when it needs to.
Finding out which one it actually is
The generic message is not the diagnosis — the error log is. Reading the PHP error log for the timestamp matching when the error occurred will almost always name the exact file, line, and reason, turning a vague 500 into a specific, fixable problem within a couple of minutes.
Where to start narrowing it down
If you cannot get to the log immediately, a quick check of what changed most recently is the fastest lead: a plugin update, an edited file, a PHP version change, or new content that happened to trip a limit for the first time — an unusually large file upload, for instance. Undo or roll back the most recent change and see whether the error clears before investigating further.
Our fuller guide to fixing a 500 internal server error walks through checking each of the causes above in turn, in the order most likely to find the actual problem quickly.
Related reading
The error log names the exact file and line that failed — here is where to find it and how to read what it is telling you.
How to fix a 500 internal server errorThe least informative error on the web. The real message is always in a log — here is how to find it and what it usually says.
How to use .htaccess on your hosting accountOne file that controls redirects, rewrites and access rules for a whole folder — and one typo in it that can take the site offline.
How to call an external API from PHPcURL, an authentication header and a decoded JSON response — the three parts of calling any external API from a PHP script.