Magento 2 Display Error Enable Error Reporting Programmatically

You can display error/enable error reporting in Magento 2 by using these methods,

  • Method 1: Rename pub/errors/local.xml.sample file
  • Method 2: Edit .htaccess file
  • Method 3: Edit app/bootstrap.php file

Method 1: Rename pub/errors/local.xml.sample file

  • Open the Magento root directory.
  • Open the pub/errors.
  • You will see a file in this directory whose name is local.xml.sample.
  • Rename the file from local.xml.sample to local.xml.
  • And flush/clear the Magento cache.

Method 2: Edit .htaccess file

  •  Open the .htaccess of your Magento 2 site.
  • Add the following code in .htaccess file to display the error.
php_value display_errors on ## enable PHP's error display settings
php_value error_reporting -1 ## set error display to E_ALL
  • Open the terminal and access the root directory.
cd /path/to/your/magento/directory
  • To set the developer mode, run the below command.
php bin/magento deploy:mode:set developer
  • You can check the deployment by using this command.
php bin/magento deploy:mode:show
  • Clear/flush the Magento cache to check the result.
php bin/magento cache:clean

Method 3: Edit app/bootstrap.php file

  • Open your Magento root directory.
  • Open the app/bootstrap.php.
  • You will see a line at the top of the file.
#ini_set('display_errors', 1);
  • Update this line of code with the below code.
error_reporting(E_ALL); # Set Error Reporting as E_ALL (Report all PHP errors)
ini_set('display_errors', 1); # Un-commenting this line to enable PHP error display
  • Open the terminal and access the root directory.
cd /path/to/your/magento/directory
  • To set the developer mode, run the below command.
php bin/magento deploy:mode:set developer
  • You can check the deployment by using this command.
php bin/magento deploy:mode:show
  • Clear/flush the Magento cache to check the result.
php bin/magento cache:clean
 
If you are looking for Magento Developers, visit Magento Developer Agency.