How to debug Magento 2 code with Xdebug and PhpStorm( Part 1)

Debug Magento 2 with Xdebug and PhpStorm

Debug Magento 2 with Xdebug and PhpStorm

Debug Magento 2: Introduction

Debugging is critical in the development process of any system. Some developers like to log things out, some like to print it right on the screen, but most prefer run-time debugging. Predictably, correctly debug your application will save you tons of time and effort. To debug Magento 2 code, you can use either XDebug or Zend Debug. In this article together we will try to install and config Xdebug, since it is more popular and easier to use. Also note that the IDE we use in this article is PhpStorm.

Ready? Let’s start with the most important thing: Install XDebug.

Install XDebug

From now on we assume you have your web server running Ubuntu locally on /var/www/html/. First you have to put a file named info.php there, with the content:




Then go to, the following screen should display:

A sample Phpinfo page

A sample Phpinfo page

Now to install xdebug, open terminal and type in the following command:

sudo apt-get install php5-xdebug

Here you have your Xdebug installed. However we need to add some config script to setup Xdebug locally. Go check your info.php again, look for this line where you can get the php.ini file location

Find your php.ini path

Find your php.ini path

Go there and paste the following code into the end of the file











One thing worth mentioning is the zend_extension variable. The number might change depending on your machine. If you are running on php 7 then it would be /usr/lib/php7/20131226/

You will need to restart apache  to apply the changes:

Sudo service apache2 restart

Now take a look again at phpinfo, if you can see this part then it is configured correctly

Your Xdebug configuration

Your Xdebug configuration

Setup XDebug with PhpStorm

In order to use Xdebug to debug Magento 2, you have to setup it with your IDE (in our case it is PhpStorm). In PhpStorm windows, you need to go to File -> Settings -> Languages & Frameworks -> PHP and set the CLI interpreter

Set correct CLI Interpreter for Php

Set correct CLI Interpreter for Php

Then go to Servers and set up a debug server. Additionally, you can set up several ones if you want.

Setup Test Server

Setup Test Server

Save the config, then go to Run -> Debug Configuration and add a PHP Web Application debug config.

Setup Magento Application that you want to debug

Setup Magento Application that you want to debug

Then look at the upper right corner, you will see the debug listener is now clickable. It means your PhpStorm is ready to listen to debug signals

PhpStorm debug tab

PhpStorm debug tab

Now there are two ways that you can get started with debugging, first way is clicking on the green bug, then a new browser page will load up and you can start your debugging from that point

Alternatively, you can install xdebug helper extensions for browsers, Chrome and Firefox, so that it can send debugging signal out to PhpStorm to catch it.


With Chrome: Xdebug helper

With Firefox: The easiest Xdebug

Have you finished all these setup with ease? Great job! In the second part we will discuss more about how to debug Magento 2 code effectively with Xdebug and PhpStorm. See you soon!


Comments (17)

  1. internet health
    Valuable information. Fortunate me I found your site unintentionally, and I'm shocked why this coincidence didn't happened earlier! I bookmarked it.
  2. 897theriver
    This topic discusses how to debug custom code using PhpStorm and the Chrome web browser using Xdebug.
  3. How to debug Magento 2 code with Xdebug and PhpStorm (Part 2)
    […] If you don’t know how to do it, please visit the instructions on Part 1 here. […]
  4. funny kid jokes
    My brother suggested I would possibly like this web site. He was once totally right. This submit actually made my day. You can not consider simply how so much time I had spent for this info! Thanks!
  5. home business internet
    Hello, I enjoy reading all of your article post. I wanted to write a little comment to support you.
  6. employment law advice
    Today, I went to the beachfront with my kids. I found a sea shell and gave it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She put the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is entirely off topic but I had to tell someone!
  7. gold price today
    I absolutely love your site.. Great colors & theme. Did you create this site yourself? Please reply back as I'm attempting to create my own blog and want to find out where you got this from or just what the theme is named. Thank you!
  8. advice on employment contracts
    Its not my first time to pay a quick visit this site, i am browsing this site dailly and get pleasant data from here everyday.
  9. finance
    Howdy would you mind stating which blog platform you're working with? I'm looking to start my own blog in the near future but I'm having a difficult time selecting between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I'm looking for something unique. P.S Sorry for being off-topic but I had to ask!
  10. bloomington carpet cleaners
    First off I want to say terrific blog! I had a quick question in which I'd like to ask if you don't mind. I was interested to know how you center yourself and clear your head prior to writing. I've had a hard time clearing my mind in getting my thoughts out there. I do enjoy writing but it just seems like the first 10 to 15 minutes are lost simply just trying to figure out how to begin. Any recommendations or tips? Many thanks!
  11. masters in education
    I every time spent my half an hour to read this website's content everyday along with a mug of coffee.
    For example diet meal plans for an average person may be disastrous for a person suffering from someone with diabetes.

Speak Your Mind

+ 42 = 51