Lab-tested: PHP 8.4.27 built-in server · 2 Dec 2026 · Reproduced and fixed in our lab
Fix Box — Try This First (10 Seconds)
When the server itself returns 500, the config is the first suspect. Test the config before you reload anything.
- Run the config test for your server and read the first error.
- Check the error log for the matching timestamp and request.
- Fix one directive at a time, test again, then reload.
The Exact Symptoms
Nginx and Apache both answer 500 for bad config, broken rewrites, and dead upstreams. The browser text is identical.
The difference lives in the error log. Nginx writes to its error log; Apache writes to error_log per virtual host.
What Our Lab Could and Could Not Reproduce
Our lab machine runs PHP 8.4.27 but has no Nginx or Apache installed. We reproduced the application-layer 500s directly: fatal, memory, and parse errors all returned HTTP 500 with matching log lines.
We could not runtime-test Nginx or Apache config on this machine. The snippets below follow the official documentation, and we say so plainly rather than claim a test we did not run.
Config Fixes That Work
Apache: broken .htaccess. An invalid directive in .htaccess returns 500 for the whole directory. Rename the file, reload, and restore rules one by one.
# Minimal safe .htaccess baseline
Options -Indexes
RewriteEngine On
Nginx: dead PHP-FPM upstream. When PHP-FPM is down, Nginx logs connect() failed and returns 502 or 500 depending on setup. Restart the pool, then check the socket path matches fastcgi_pass.
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
include fastcgi_params;
}
Both: permissions. Config and code files need to be readable by the server user. A chmod 000 on a required file produces a clean, repeatable 500.
Decision Table
| Log signal | Likely layer | First move |
|---|---|---|
| Invalid command in .htaccess | Apache config | Rename .htaccess, restore stepwise |
| connect() failed (upstream) | Nginx → PHP-FPM | Restart pool, check socket path |
| Permission denied in log | Filesystem | Fix ownership and 644/755 |
| PHP Fatal error in log | Application | See the PHP 500 guide |
What Did Not Work
Reloading the server without a config test did not fix anything in our documented cases. A bad config simply fails to load, or loads broken.
Editing several directives at once also failed as a method. When the 500 cleared, nobody knew which change mattered.
Prevention
Test config on every change: nginx -t or apachectl configtest. Keep the last known-good config under version control.
Application fatals behind these servers are covered in PHP 500 Error and 500 Error in WordPress. Check any URL live with the 500 Error Checker, or start at the pillar 500 Internal Server Error.
FAQ
Why does Nginx return 502 sometimes and 500 other times? The code depends on where the failure happens: upstream connect failures are usually 502, internal config errors are 500.
Can one bad .htaccess line break the whole site? Yes. Apache parses it per request for that directory tree.
Should I edit config on the live server? Test first, keep a backup, and reload — never restart blind.
How do I know if it is config or code? The error log layer. Config errors name directives; code errors name PHP files and lines.
Does Cloudflare cause 500s? Cloudflare usually shows its own 5xx pages. An origin 500 passes through with your server’s log entry behind it.
Sources and date
Application-layer lab tests run 2 Dec 2026 on PHP 8.4.27; Nginx/Apache snippets from official docs, not runtime-tested on this machine. References checked live 2 Dec 2026.
- RFC 9110 §15.6.1: https://www.rfc-editor.org/rfc/rfc9110.html
- MDN — 500: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/500
- Nginx core module: https://nginx.org/en/docs/http/ngx_http_core_module.html
- Apache core: https://httpd.apache.org/docs/current/mod/core.html






Leave a Reply