How to Debug Magento 2 Store Easily With Just a Few Steps

How to Debug Magento 2 Store Easily With Just a Few Steps

Debugging is an essential aspect of every e-commerce store’s design phase. Software developers are aware of it and plan for the assignment from the beginning.

 

Most developers prefer to track the entire process before debugging, whereas others choose to debug throughout runtime – both of these are effective methods for tidying up faults in your e-commerce business.

 

Because Magento 2 is a new release of Magento, debugging it differs slightly from Magento 1. There are several methods for debugging Magento 2 software on a site, and in this blog, I’ll go over how to accomplish it quickly and easily to reach the expected outcome.

 

Let’s begin with the fundamentals.

Development Modes of Magento 2

 There are three kinds of development options accessible in Magento 2. They are as follows:

 

  1. Default Mode
  2. Development Mode
  3. Production Mode 

 

Magento 2 Developer Mode is used by developers to troubleshoot Magento 2 stores. Errors are displayed immediately on the screen in this manner. It is, in reality, a straightforward approach to debug even failing packages that display a blank screen or a 500 error on the display. Simply log in to your server through SSH and perform the following Magento 2 CLI Command on the root folder of your Magento 2 shop to activate developer mode:

 

php bin/magento deploy:mode:set developer

To debug Magento Store, enable PHP Display Errors

For apparent safety concerns, Magento 2 has disabled PHP display failures in production mode. You could, nonetheless, allow these display faults for debugging purposes.

 

Open the $Magento2Root/app/bootstrap.php file and uncomment the ini set(‘display errors’, 1); line to allow PHP to show error monitoring.

 

The value ‘1’ indicates that the display errors settings are now switched to ‘On.’ This will show any PHP issues that occurred when running the Magento 2 shop on the web.

How to Activate Magento 2 Error Display for Magento 2 Debug

When an issue occurs, Magento 2 records it in the var/reports file rather than displaying it on the screen. You may, nonetheless, need it to display the problem on your monitor for debugging purposes. Just rename the local.xml.sample file to local.xml to activate it from the $Magento2Root/pub/errors/ directory.

 

[Add code here from the Cloudways blog]

Activate the ‘Template Path Hints’ option

The ‘Template path hints’ scan tool provides notes with the path upon every Magento 2 framework layout. Through the setup menu, users may activate it for the marketplace and the Admin panel.

 

Simply log in to your Magento 2 Admin panel and browse to Stores > Configuration to activate template path suggestions for debugging your Magento 2 shop. Select Developer in the Advanced tab on the left panel. Set Enabled Template Path Hints for Storefront, Enabled Template Path Hints for Admin, and Add Block Names to Hints to Yes from the right panel.

 

When you save the settings, you will see a difference on both ends of your Magento 2 e-commerce business.

Integration of Xdebug and PhpStorm

One of the effective methods to debug a Magento 2 shop is to use Xdebug and PhpStorm together. The key benefit of this strategy is that it provides breakpoints to the setup process, allowing the developer to examine and alter parameters at any moment.

 

To configure Magento 2 Xdebug, create a new file in your Git repo or install it in your system. Then, arrange port forwarding and configure PhpStorm as the IDE tensionmatleyaar.

 

This authorized Magento document explains how to deploy and use Xdebug with PhpStorm for debugging your Magento 2 shop.

Final words

Magento 2 is an extremely useful software for business owners to start their e-commerce journey, you just have to get good hosting for Magento and then you are good to go. 

 

This blog has discussed every one of the details required to debug a Magento 2 shop, and with the integration of Xdebug and PhpStorm, the creator’s job will be much easier. This knowledge should be plenty to get you to begin troubleshooting a Magento 2 shop on your own.