PHP 500 Error: Fatal Errors, Memory Limit and Fixes

Written by

in

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)

PHP returns 500 when a script dies before finishing. The error log tells you which of three deaths it was.

  1. Read the last line of the PHP error log after one reload.
  2. Match it: undefined function, memory exhausted, or parse error.
  3. Apply the matching fix below, then verify with curl.

The Exact Symptoms

Visitors see a blank page or a generic 500 message. The real message stays in the server log, by design.

Three log lines cover most cases. Each one needs a different fix, so read before you change anything.

The Three Deaths We Reproduced

Undefined function. Our script called a function that does not exist. PHP logged: Call to undefined function this_function_does_not_exist().

Memory exhausted. With a 16 MB limit, an allocation loop died with: Allowed memory size of 16777216 bytes exhausted (tried to allocate 2097152 bytes).

Parse error. A missing semicolon produced: syntax error, unexpected end of file, expecting "," or ";". All three returned HTTP 500.

The Fixes

For an undefined function, define it or remove the call. Our fixed script returned HTTP/1.1 200 OK immediately.

For memory, fix the leak first, then size the limit to the workload. Blindly raising the limit only delays the same crash.

; php.ini — raise only after fixing the cause
memory_limit = 256M
log_errors = On
display_errors = Off

For a parse error, run php -l file.php before deploying. It caught our broken file instantly, with the exact line number.

Decision Table

Log line contains Cause First fix
Call to undefined function Missing or renamed code Define, include, or remove the call
Allowed memory size exhausted Leak or undersized limit Fix allocation, then size the limit
Parse error / syntax error Broken file syntax php -l, fix the named line
Cannot redeclare function Duplicate definitions Rename or disable one copy

What Did Not Work

Raising memory_limit did not fix the undefined-function case. The script died at the first call, far below any limit.

Turning on display_errors in production also helped nobody. It leaked file paths to visitors while the status stayed 500.

Prevention

Lint every PHP file in your deploy step, and keep display_errors off in production. Log errors to a file you actually read.

These same fatals sit behind most WordPress 500 errors. Server-level causes are covered in 500 Error on Nginx and Apache.

Confirm any live URL with the 500 Error Checker, and start from the pillar 500 Internal Server Error if the layer is unclear.

FAQ

Why is the page blank instead of showing the error? Because display_errors is off, which is correct for production. The log has the message.

What memory_limit should I use? The smallest value your real workload fits in. Measure first; 256M is a common ceiling, not a target.

Does a parse error affect the whole site? Only requests that load that file. A broken shared include can still take down everything.

Can I test syntax without running the site? Yes. php -l checks a file without executing it.

Is 500 always PHP’s fault? No. A proxy or web server can also return 500; the log layer tells you which.

Sources and date

Lab tests run 2 Dec 2026 on PHP 8.4.27. References checked live on the same date.

  • 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
  • PHP — Error handling configuration: https://www.php.net/manual/en/errorfunc.configuration.php
  • PHP — Core php.ini directives: https://www.php.net/manual/en/ini.core.php

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *


More posts