Contents
Hi everyone, when your Magento gets errors but you don’t know what it is. Today I will show you how to debug in Magento 2
1. Add show error PHP on index.php file
Open Magento root/index.php and add the following code at the beginning of the file.
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
2. Change your Magento to developer mode
Method 1. Open Magento root/app/etc/env.php file in “MAGE_MODE” change to “developer” like bellow:
‘MAGE_MODE’ => ‘developer’
then flush your magento cache
Method 2. change magento mode via command line like bellow:
php bin/magento deploy:mode:set developer
php bin/magento cache:flush
3. Find any files and edit with feature template path hints
Method 1. Go to Admin > Store > Settings > Configuration > Advance > Developer > Debug you will see like image bellow

+ Config “Enable Template Path Hints for Storefront”: choose “Yes” to enable template path hints
+ Enable Hints for Storefront with URL Parameter: choose “Yes” to enable URL Parameter
+ Parameter Value: change to your parameter or keep default is “magento” if you enable parameter
+ Enable Template Path Hints for Admin: choose “Yes” if you want debug admin
+ Add Block Class Type to Hints: choose “Yes” to show block class comes with the template
Method 2. Enable template path hints with command line:
+ Bellow is command to Enable template path hints
php bin/magento config:set dev/debug/template_hints_storefront 1
+ Enable parameter value
php bin/magento config:set dev/debug/template_hints_storefront_show_with_parameter 1
+ Command Add Block Class Type to Hints
php bin/magento config:set dev/debug/template_hints_blocks 1
Add ?templatehints=magento after url to enable template path hints on storefont like image bellow:

Done, I hope this article will helpful for you.