Introduction
If you are a PHP developer or even just starting with PHP, you know that debugging is one of the most crucial steps in building stable, bug-free applications. But what happens when PHP errors are not visible? You could waste hours trying to figure out what went wrong.
That’s why learning how to show all PHP errors in PHP is an essential skill. Whether you’re working on a live server or a local development environment, enabling PHP error reporting ensures that you can spot issues immediately, fix them faster, and deliver high-quality code.
In this complete step-by-step tutorial, we’ll cover:
What PHP error reporting is
Why enabling all PHP errors helps developers
Different methods to display all errors
The difference between
E_ALL
,display_errors
, anderror_reporting()
Best practices for error reporting in development vs production
1. Understanding PHP Error Reporting
PHP error reporting is a built-in mechanism that notifies you when something goes wrong in your code. Depending on your configuration, errors might appear on your browser, in your server logs, or remain completely hidden.
PHP has different error levels, such as:
E_ERROR – Fatal errors that stop execution
E_WARNING – Non-fatal warnings
E_NOTICE – Informational notices about potential issues
E_ALL – All errors, warnings, and notices
Focus Keyword Example: If you want to show all PHP errors in PHP, you need to configure your error reporting level to E_ALL
and ensure errors are displayed on your screen or logged appropriately.
2. Why You Should Enable All PHP Errors in Development
Here’s why enabling error reporting is a must for developers:
Faster debugging – See exactly where the problem occurs
Better code quality – Catch hidden warnings and notices
Early detection – Prevent small issues from becoming big problems
Efficient teamwork – Helps team members troubleshoot issues easily
⚠ Important: You should never display all errors on a live production site because it can expose sensitive information.
3. Methods to Show All PHP Errors in PHP
A) Using error_reporting()
Function
The simplest way to show all PHP errors in PHP is to use the error_reporting()
function at the top of your PHP script:
error_reporting(E_ALL);
→ Reports all errors, warnings, and noticesini_set('display_errors', 1);
→ Ensures errors are shown in the browser
B) Editing php.ini
Configuration File
If you have access to your PHP configuration file (php.ini
), you can enable error reporting globally:
After editing php.ini
, restart your server (Apache, Nginx, etc.) for the changes to take effect.
C) Using .htaccess
File (For Apache Servers)
If you’re on a shared hosting environment, you can enable PHP error reporting using .htaccess
:
D) Using WP-Config in WordPress
For WordPress developers, you can enable debug mode in wp-config.php
:
4. PHP Error Reporting Levels
Error Level | Description |
---|---|
E_ERROR | Fatal run-time errors |
E_WARNING | Non-fatal warnings |
E_PARSE | Compile-time parse errors |
E_NOTICE | Runtime notices |
E_ALL | All errors, warnings, and notices |
If your goal is to show all PHP errors in PHP, always set your reporting level to E_ALL.
5. Best Practices for Showing PHP Errors
Enable in Development Only – Hide errors in production
Log Errors in Production – Use
log_errors
inphp.ini
to save errors to a file instead of displaying themUse Custom Error Handlers – Implement a function to handle errors gracefully
Combine with Debugging Tools – Use Xdebug for deeper analysis
Example for production logging in php.ini
:
6. Common Mistakes to Avoid
❌ Leaving Error Reporting On in Production – This could expose database credentials, file paths, and server details to hackers.
❌ Not Restarting Server After Changes – php.ini
updates won’t work without a restart.
❌ Ignoring Warnings & Notices – These could become bigger issues later.
7. Troubleshooting – Why PHP Errors Are Not Showing
If you’ve enabled everything but still can’t show all PHP errors in PHP, check:
Is
display_errors
overridden in.htaccess
?Are you editing the correct
php.ini
file?Is there an
error_reporting
override inside your framework or CMS?
Conclusion
Knowing how to show all PHP errors in PHP is a must-have skill for every developer. It makes debugging easier, improves code quality, and helps you deliver reliable web applications.
Remember:
Use E_ALL to show all errors
Combine
error_reporting()
withini_set()
for quick debuggingTurn off
display_errors
on production servers for security
By following the steps in this guide, you’ll be able to debug faster, smarter, and safer.