Question
I have checked my php.ini file and confirmed that display_errors is enabled and error_reporting is set to E_ALL. I also restarted my Apache web server.
I have even added these lines at the top of my script:
error_reporting(E_ALL);
ini_set('display_errors', '1');
However, my script still does not show errors in the browser. Even simple syntax problems, such as missing semicolons or other parse errors, only produce a blank page.
What else should I check or configure to make PHP errors display correctly?
Short Answer
By the end of this page, you will understand how PHP error reporting works, why some PHP errors appear as a blank page, and what to check when display_errors seems enabled but errors still do not show. You will also learn the difference between runtime errors and parse errors, where configuration can override your settings, and how developers usually debug this safely in real projects.
Concept
PHP error display depends on when the error happens and which configuration file or environment is controlling PHP.
The key idea is this:
error_reporting(E_ALL);tells PHP which kinds of errors to report.ini_set('display_errors', '1');tells PHP to display them.- But these lines only run after PHP has already started executing the script.
That matters because parse errors happen before execution begins. If PHP cannot parse the file, it never reaches your error_reporting() or ini_set() calls.
This is why a script can show a blank page even though those lines are present.
Why this matters
In real development, seeing errors quickly helps you:
- fix syntax mistakes faster
- debug broken logic
- identify missing files, undefined variables, and failed function calls
- avoid wasting time on blank pages
At the same time, displaying raw errors in production is dangerous because error messages can reveal:
- file paths
- SQL details
- server configuration
- internal application structure
So the usual rule is:
- development: display errors
- production: log errors instead of showing them
Common reasons errors do not display
Even when you think PHP is configured correctly, one of these may still be true:
Mental Model
Think of PHP like a speaker reading a script aloud.
- First, the speaker checks whether the script is written correctly.
- Only if the script is valid does the speaker start reading it.
- Your
error_reporting()andini_set()lines are part of the script itself.
So if the script has a syntax mistake, PHP stops at step 1. It never gets to the lines that tell it to display errors.
Another way to think about it:
php.inisettings are the house rules set before the game starts.ini_set()is changing rules during the game.- A parse error means the game never even starts.
That is why server-level configuration is so important when debugging blank pages in PHP.
Syntax and Examples
Core syntax
Enable error reporting in a PHP script:
error_reporting(E_ALL);
ini_set('display_errors', '1');
Useful related setting:
ini_set('display_startup_errors', '1');
Example: runtime error that can be displayed
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include 'file-that-does-not-exist.php';
echo $undefinedVariable;
What this does
includeof a missing file usually triggers warnings.echo $undefinedVariable;triggers a notice or warning depending on PHP version.- Because the file parses correctly, PHP reaches the error settings and can display these messages.
Example: parse error that these lines cannot catch
(E_ALL);
(, )
;
Step by Step Execution
Consider this valid script:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
echo $name;
Step by step
- PHP reads the file.
- The file has valid syntax, so parsing succeeds.
- PHP executes
error_reporting(E_ALL);. - PHP executes
ini_set('display_errors', '1');. - PHP reaches
echo $name;. $nameis undefined, so PHP raises an error message.- Because display is enabled, the message appears in the browser.
Now compare it with this file:
<?php
error_reporting(E_ALL)
ini_set('display_errors', '1');
echo "Test";
What happens here
- PHP reads the file.
- PHP finds a missing semicolon after
error_reporting(E_ALL). - Parsing fails.
- Script execution never starts.
- is never executed.
Real World Use Cases
Local development
When building a PHP app on your machine, displayed errors help you quickly fix:
- syntax mistakes
- undefined variables
- missing includes
- wrong function arguments
Debugging a staging server
On a test environment, developers may temporarily enable displayed errors to investigate a broken page, then disable them again afterward.
Logging production failures
In production, teams usually keep display_errors off and use logs instead:
- PHP error log
- Apache or Nginx error log
- application log files
- monitoring tools
Diagnosing blank pages
A blank page in PHP often means one of these:
- fatal error
- parse error
- startup error
- output buffering hides visible output
Knowing how error display works helps you narrow down the cause quickly.
CLI vs browser debugging
When running PHP from the command line, parse errors are often shown directly in the terminal even if browser output is blank. This is useful for testing a file quickly:
php test.php
Real Codebase Usage
In real projects, developers rarely rely only on placing ini_set() at the top of a file.
Common patterns
Environment-based configuration
Applications often use different settings for development and production:
<?php
if ($_ENV['APP_ENV'] === 'development') {
error_reporting(E_ALL);
ini_set('display_errors', '1');
} else {
ini_set('display_errors', '0');
ini_set('log_errors', '1');
}
Logging instead of displaying
In production, developers usually prefer:
display_errors = Offlog_errors = On
This prevents sensitive details from being exposed to users.
Guarding against silent failures
Developers check logs when a page is blank because blank output often means the error happened before normal rendering.
Framework integration
Frameworks may provide their own error pages and exception handlers. Even then, PHP's base error configuration still matters, especially for startup and parse issues.
Common Mistakes
1. Expecting ini_set() to catch parse errors
Broken example:
<?php
ini_set('display_errors', '1')
error_reporting(E_ALL);
Problem:
- The file itself has a syntax error.
- PHP never executes
ini_set().
How to avoid it:
- Enable errors in
php.inifor development. - Run
php -l yourfile.phpto detect syntax issues.
2. Editing the wrong php.ini
Many systems have multiple PHP configurations, for example:
- CLI PHP
- Apache module PHP
- PHP-FPM
How to avoid it:
- Use
phpinfo()in the browser. - Check Loaded Configuration File.
3. Forgetting to restart the correct service
You may restart Apache, but your setup might actually use PHP-FPM.
How to avoid it:
- Restart the web server and PHP process manager if needed.
Comparisons
| Topic | What it does | Works for parse errors in the same file? | Best use |
|---|---|---|---|
error_reporting(E_ALL) | Chooses which error levels PHP reports | No, if the file cannot parse | Enable full reporting during development |
ini_set('display_errors', '1') | Tells PHP to show errors in output | No, if the file cannot parse | Runtime debugging |
display_errors in php.ini | Global config before script execution | Yes, if the config is loaded correctly | Development environment setup |
display_startup_errors | Shows startup-related errors | Helps with startup issues, not every scenario | Troubleshooting initialization problems |
Cheat Sheet
// Show most runtime errors during development
error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
; Development php.ini settings
display_errors = On
display_startup_errors = On
error_reporting = E_ALL
log_errors = On
<?php
phpinfo(); // Check which php.ini is actually loaded
php -l file.php # Syntax check a PHP file
Rules to remember
ini_set()only works after the script starts executing.- Parse errors happen before execution.
- Blank page often means an error is hidden.
phpinfo()helps confirm the active config.- In production, prefer logging over displaying.
Quick troubleshooting checklist
FAQ
Why does PHP show a blank page instead of an error?
A blank page usually means PHP hit a fatal, parse, or startup error, but error display is disabled or misconfigured.
Why doesn't ini_set('display_errors', 1) show syntax errors?
Because syntax errors happen before the script executes. PHP must parse the file first, so it never reaches that line.
How do I know which php.ini file my website is using?
Create a file with phpinfo(); and open it in the browser. Look for Loaded Configuration File.
Should I enable display_errors on a live website?
No. On production systems, keep display_errors off and use logging instead.
What setting should I use to see startup-related errors?
Enable display_startup_errors in development.
How can I check a PHP file for syntax errors quickly?
Use:
php -l yourfile.php
If errors still do not appear, where should I look next?
Check the PHP error log, Apache or Nginx error log, and confirm that no local server configuration is overriding your settings.
Mini Project
Description
Build a small PHP debugging helper page that confirms whether your environment is showing and logging errors correctly. This project is useful because it teaches the difference between configuration checks, runtime errors, and syntax errors in a practical way.
Goal
Create a PHP page that reports active error settings and deliberately triggers a visible runtime warning for testing.
Requirements
Requirement 1 Requirement 2 Requirement 3
Keep learning
Related questions
Converting HTML and CSS to PDF in PHP: Core Concepts, Limits, and Practical Approaches
Learn how HTML-to-PDF conversion works in PHP, why CSS support varies, and how to choose practical approaches for reliable PDF output.
How PHP foreach Actually Works with Arrays
Learn how PHP foreach works internally, including array copies, internal pointers, by-value vs by-reference behavior, and common pitfalls.
How to Check String Prefixes and Suffixes in PHP
Learn how to check whether a string starts or ends with specific text in PHP using simple functions and practical examples.