How to Make PHP Show All Errors: Complete Guide

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

"PHP shows a white screen, but I need errors!" — a familiar situation?



You write PHP code, run the script, and instead of a result — nothing. Or, even worse, some strange error without a single hint of the cause. Sound familiar? If you've ever asked yourself "How can I get useful error messages in PHP?" — you're not alone. This question on Stack Overflow has gathered thousands of views, and for good reason. PHP is configured by default to hide errors on production servers, but during development this turns into a real headache.



In this article, we'll cover all the ways to make PHP speak to you in a clear language. You'll learn how to enable error display, configure the level of detail, and log them so debugging stops being guesswork. Let's go!



Why is PHP silent? The root of the evil — server settings



Before we learn how to get useful messages, let's understand why they aren't there. PHP is a language with a strict security philosophy. On production servers, showing errors to users is bad practice and a security risk. Therefore, in php.ini (PHP's main configuration file), the default settings are:



  • display_errors = Off — errors are not displayed on screen.
  • error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT — not all error types are shown.


But for local development, this is a disaster. How to fix it? There are three main ways.



Method 1: Modify php.ini (if you have access)



The most reliable way is to edit the php.ini file. Find it (usually located in the PHP installation root or in the etc/ folder on Linux). Then find and change the following lines:



; Enable error output to screendisplay_errors = On

; Set the maximum reporting level (all errors except deprecation notices)error_reporting = E_ALL


After making changes, be sure to restart the web server (Apache, Nginx, or the built-in PHP server), otherwise the settings won't take effect.



Important: On a production server, display_errors should always be Off. Use this method only for development.



Method 2: Use .htaccess (for Apache)



If you don't have access to php.ini but you use Apache, you can override settings via the .htaccess file in your site's root. Add the following to it:



php_flag display_errors onphp_value error_reporting E_ALL


This will work if Apache allows overriding PHP directives (which is usually the case on most hosting providers).



Method 3: Enable errors directly in code (most flexible)



This is my favorite method for quick debugging. You can insert these lines at the beginning of your script (right after <?php):



<?php// Enable maximum error reporting levelerror_reporting(E_ALL);

// Enable error output to screenini_set('display_errors', 1);

// Enable startup errors (e.g., if there's an error in ini_set itself)ini_set('display_startup_errors', 1);?>


Now any Warning, Notice, or Fatal Error will be displayed right in the browser. Convenient, right?



What types of errors exist in PHP and what do they mean?



To read PHP's "signals," you need to know their language. Here are the main types of errors you'll see most often:



  • E_ERROR — fatal error. The script stops. Example: calling a non-existent function.
  • E_WARNING — warning. The script continues running, but something went wrong. Example: include() of a non-existent file.
  • E_NOTICE — notice. Not an error, but a potential problem. Example: using an undefined variable.<

Blogs

Book Recommendations