Get your next remote job on LaraJobs.
1 contributor Edit on GitHub PHP

Easily show all errors in PHP

Table of contents:

Easily show all errors in PHP

Show all PHP errors using ini_set() and error_reporting()

To showcase all errors in PHP, include these lines at the top of your PHP file:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

By tweaking these settings using the ini_set() and error_reporting() functions, PHP will now show all runtime errors, startup errors, and even notify you about potential issues.

Let’s decode what all this means:

  • display_errors: This key is a directive which determines whether errors should be printed as a part of the program’s output or hidden. We set it to 1 to instruct PHP to display errors.

  • display_startup_errors: This directive decides if PHP will show errors that occur during PHP’s startup sequence. We set ‘display_startup_errors’ to 1, so PHP clearly communicates any startup issues.

  • error_reporting(E_ALL): This setting controls the level of error reporting. E_ALL is a constant that instructs PHP to show all possible errors, warnings, and notices.

How to adjust the setting in your php.ini to show all errors

Besides adding these values in your PHP script, you can also set them globally from the php.ini file. Here are the steps to find and edit this file:

  1. Open a command line, and run php --ini. If PHP is installed correctly, this command will output the location of the php.ini file.
  2. Open php.ini in your preferred text editor. Scroll through the file or do a quick search for display_errors, display_startup_errors, and error_reporting.
  3. Set the values as we did in our script - display_errors and display_startup_errors to 1, and error_reporting to E_ALL.

Remember to save your changes. And if you don’t want to shout at your computer because nothing is happening, restart your PHP server to apply them.

Don’t display all PHP errors in production

Altering these settings can be very useful for debugging during development, but beware that you must not do it in the context of a live application.

Having PHP show all errors can give malicious users more information about your server configuration and potential attack routes.

Therefore, always ensure production-safe settings values before deploying. As a safer alternative in production, consider logging errors to a non-publicly accessible file that you can review later. Set log_errors = on and provide a file path for error_log in the php.ini file for this purpose.

Benjamin Crozat

Written by Benjamin Crozat

Indie hacker, blogger, and AI enthusiast building things with the TALL stack. 🔥

Follow me on:

Recommended articles

This is where your php.ini file is This is where your php.ini file is

Discover the location of your php.ini file using two simple methods: the phpinfo() function or the command line.

Published on Nov 2, 2023

PHP 8.3 is out, now! Here's what's new and changed. PHP 8.3 is out, now! Here's what's new and changed.

PHP 8.3 was released on November 23, 2023, and as usual, you need to be up to date with new features and breaking changes for easier transitions.

Modified on Nov 23, 2023

20+ Laravel best practices, tips and tricks to use in 2023 20+ Laravel best practices, tips and tricks to use in 2023

Learning a framework can be overwhelming, but time and execution will make you a master. Here are some best practices to help you toward your goal.

Modified on Oct 17, 2023

Laravel interview questions and answers for 2023 Laravel interview questions and answers for 2023

Nailing a Laravel job interview can be a daunting task, but with the right preparation and mindset, you can set yourself up for success.

Modified on Sep 19, 2023 Audio available

An early look at PHP 9.0's new features and changes An early look at PHP 9.0's new features and changes

PHP 9.0 is still far in the future. We don't know a lot, but we have a few breaking changes planned for it.

Published on Nov 3, 2023


Gold sponsors New

  • Wire Elements
    Beautiful handcrafted Livewire components.
    Check site
Your business here


If you buy from one of my partners below, I will be compensated at no cost to you. These are services I use or used, and 100% stand behind.

  • Scalable and reliable VPS hosting.
    Bonus: $200 of free credits
    Check site
  • The Google Analytics alternative without compromise.
    Free trial: 30 days
    Bonus: $10 off your first invoice
    Check site
  • Flare
    Track PHP and JavaScript errors in one place.
    Free trial: 10 days
    Check site
  • Keep track of your Google rankings.
    Free trial: 7 days
    Promo code: WELCOME30
    Check site
- / -