Preloader
Magento 2
  • Estimated reading time: 1 Minute

How to setup the debugging environment for your development version of Magento 2

Without debugging enabled, your Magento project is basically a box with secrets. Unless you want to continuously read the log of the project e.g:

tail var/log/exception.log

This is obviously useful, however as a developer that works with a lot of frameworks like Symfony, CakePHP, Laravel, i know how useful it is to see immediately the exception that has been raised in the place where it ocurred. You will need to setup some basic things in your project, so you can simply see errors on the fly.

In this short article, we'll explain how to configure it quickly.

1. Set MAGE_MODE environment variable to developer

The first thing you gotta do is to set the current mode of Magento to the developer mode. This can be done in 2 ways, either directly with the command line. The first you need to do is to know in which mode are you currently set in with:

php bin/magento deploy:mode:show

This will print in the terminal something like:

Current application mode: default. (Note: Environment variables may override this value.)

To set the current mode to the developer mode, where exceptions are thrown directly in the screen and you can see what happens, use the following command:

php bin/magento deploy:mode:set developer

There are 3 modes available that you can set with the CLI:

  • default
  • production
  • developer

That should do the trick, however as mentioned on the command, the environment variables may override the defined behaviour, so to be sure that you are working as a developer in the project, modify the .htaccess file in the root directory of your magento project and define the MAGE_MODE variable to developer:

It is usually in the line #5 of the file and is commented, so you should simply uncomment it and that's it!

# Use the developer mode
SetEnv MAGE_MODE developer

Save the changes and proceed with the next configuration.

2. Enable display errors

As in fact, Magento runs on PHP, you will need to enable the error reporting of PHP. This can be done easily with these 2 lines of code:

error_reporting(E_ALL);
ini_set('display_errors', 1);

That usually, exist already on the app/bootstrap.php file and you just need to uncomment the lines of the mentioned instructions. That should be enough to see exceptions, so you can solve them.

Happy coding !

Share:
Carlos Delgado

Carlos Delgado

Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Related articles
Why Use Magento?
28 Nov, 2022
  • Estimated reading time: 3 Minutes
How to disable Magento 2 2FA plugin
15 Jul, 2022
  • Estimated reading time: 1 Minute
8 Best Magento Extensions That Will Boost Your Online Business
28 Nov, 2019
  • Estimated reading time: 7 Minutes
7 Magento Development Trends That Are Making It Big Right Now
27 Aug, 2019
  • Estimated reading time: 4 Minutes
Weekly trending
Apple Gift Card Rate Today in Nigeria (USD, CAD, GBP & More)
16 Jun, 2026
  • Estimated reading time: 4 Minutes
How Digital Airport Advertising Is Transforming the Industry
16 Jun, 2026
  • Estimated reading time: 4 Minutes
How Motorsports Sponsorship Agencies Measure Sponsorship ROI
16 Jun, 2026
  • Estimated reading time: 3 Minutes
Our Sponsors

Our blog is proudly supported by industry-leading sponsors.