Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

PHP shows a blank page and no error message

ErrorA white page with no output at all (HTTP 500 in the access log)

Short answer

A blank page means PHP hit an error but was told not to print it. Check display_errors and error_reporting in the php.ini the web server really uses, not the CLI one. Turn display on in development only. On production, set log_errors and read the log instead of showing errors.

  • Applies to PHP 8.3, PHP 8.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask PHP which settings are active and which php.ini was loaded. Run it for the CLI, then compare with phpinfo() served through the web server, because the two often use different files.

    php --ini
    php -i | grep -E "^(display_errors|error_reporting|log_errors|error_log) "
  2. 2Match what you see, then jump to its fix

    1. 1Blank page; phpinfo() through the web server shows display_errors => Offdisplay_errors is Off in the php.ini that serves the siteFix
    2. 2ini_set('display_errors', 1) at the top of the script, still a blank page, and the problem is a syntax errorThe error is a parse error in the same file as ini_set()Fix
    3. 3display_errors is Off, log_errors is Off or error_log points at a file PHP cannot writeProduction: errors are hidden on purpose and nobody reads the logFix
    4. 4A working page prints Warning: lines above the HTMLYou want a warning to stop appearing on the pageFix

What does the error look like?

  • A white page with no output at all (HTTP 500 in the access log)
  • No Warning or Fatal error text, even though the script is broken
  • ini_set('display_errors', 1) has no effect on a Parse error in the same file

Cause 1 of 4

display_errors is Off in the php.ini that serves the site

1Check

The shipped php.ini-production file sets display_errors to Off, and php.ini-development sets it to On. A server installed from the production template hides every error.

php --ini
# Debian/Ubuntu package path; use the "Loaded Configuration File" from phpinfo() on other systems
grep -n -E "^(display_errors|error_reporting)" /etc/php/8.3/fpm/php.ini

2Fix

In development, set both directives in the php.ini used by the web server (the path comes from the web SAPI, not from the CLI), then restart PHP-FPM or Apache.

; php.ini (development machine only)
display_errors = On
error_reporting = E_ALL

3Verify

Reload a page that has a deliberate error and the message appears. Remove the test error afterwards.

sudo systemctl restart php8.3-fpm

Confirmed by php.net

Did this fix it?

Cause 2 of 4

The error is a parse error in the same file as ini_set()

1Check

PHP parses the whole file before it runs any line of it. A ini_set() call inside a file that fails to parse never executes, so it cannot turn display on for that file's own parse error.

php -l public/index.php

2Fix

Set the directives in php.ini, or put the ini_set() calls in a small bootstrap file and include the broken file from it.

<?php
// bootstrap.php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include __DIR__ . '/public/index.php';

3Verify

Open bootstrap.php in the browser; the parse error from index.php is now printed.

php -l public/index.php

Confirmed by php.net

Did this fix it?

Cause 3 of 4

Production: errors are hidden on purpose and nobody reads the log

1Check

Showing errors to visitors is not advised on a live site. The manual's advice is to log them instead. log_errors defaults to off, so you must switch it on.

php -i | grep -E '^(log_errors|error_log) '

2Fix

Keep display off, turn logging on and give error_log a path the PHP user can write to.

; php.ini (production)
display_errors = Off
log_errors = On
error_log = /var/log/php/error.log

3Verify

Trigger one error, then read the last lines of the log.

sudo tail -n 20 /var/log/php/error.log

Confirmed by php.net

Did this fix it?

Cause 4 of 4

You want a warning to stop appearing on the page

1Check

Find the line named in the message. The @ operator only silences diagnostics (warnings, notices); it also hides errors you did not expect, so it should be a last resort.

grep -rn "Warning" storage/logs/ | tail -n 5

2Fix

Fix the cause first, for example test the value with isset() before reading it. If a warning is expected and harmless, silence only that one expression, and keep display_errors Off on production.

<?php
$port = isset($config['port']) ? $config['port'] : 3306;

3Verify

Reload the page; the warning is gone and the log stays quiet.

php -l config.php

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • Use php.ini-development locally and php.ini-production on servers, and keep both in version control notes.
  • On production, log errors to a file and rotate it, so a blank page always has a log line behind it.
  • Run php -l on changed files in CI so parse errors never reach the server.
  • Compare php --ini with phpinfo() from the web server whenever a setting seems ignored.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

Apache returns 403 when a URL contains %3F

a request like /page%3Fname=test is refused while /page?name=test works

Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.