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

Debug Magento 2 with Xdebug and PhpStorm part 2

Introduction

In this second part of the series, I’m going to guide you how to start a debugging session, place a breakpoint and track the debugging progress. But before we begin, make sure that you have installed and set up Xdebug with PhpStorm.

If you don’t know how to do it, please visit our instructions on Part 1 here.

Working on Xdebug

You can start a debugging session with PhpStorm either by clicking on the debug button (with a bug icon), or turn on debugging connection listening and let PhpStorm catch debugging requests from the browser. I personally prefer the second way, as it is convenient and easier to manage.

On the taskbar, go to Run -> Edit Configurations to enter the configuration window for your debug:

image5

Click on the green plus button on the top left corner and choose PHP Web Application and fill in the necessary parameters. The Start URL is quite important, as it defines the start page when you start a new debug session with PhpStorm.

When it is done, click OK to save.

Now you can either:

  • Click on the green bug on the top right corner to get started.
  • Or you can switch on browser debugging and enable debug listening on PhpStorm, as follows:

For Chrome:

image9

For Firefox:

image6

In PhpStorm:

image3

Now you will want to place a breakpoint where your code would stop. It looks like this:

image1

When you runs the code, it would stop at the breakpoint and a debug window shows up.

image11

As in the photo above, there is a white line that shows where your debug is, and the code in the white-line is not executed. On the bottom, the debug window show you all of the debugging flow, variables’ values, object’s properties, etc…

While working on debug window, if you want to:

  • Execute the current code and go to the next line, press  image2
  • Go into the current method, press  image10
  • Step out, press  image7
  • Stop debugging, continue the code flow, press image8
  • Stop the code flow and then terminate the debug, press  image4

Congrats! You just mastered an very important tool for developers. If you have any questions or problems about Xdebug, don’t mind leaving them in the comment section below.

 

Share

Comments (40)

  1. price of gold
    Hi there, i read your blog from time to time and i own a similar one and i was just wondering if you get a lot of spam responses? If so how do you prevent it, any plugin or anything you can recommend? I get so much lately it's driving me crazy so any help is very much appreciated.
  2. small business
    Hi to every single one, it's in fact a good for me to go to see this website, it consists of precious Information.
  3. best buy outlet
    Hmm it looks like your site ate my first comment (it was extremely long) so I guess I'll just sum it up what I had written and say, I'm thoroughly enjoying your blog. I too am an aspiring blog blogger but I'm still new to everything. Do you have any tips for first-time blog writers? I'd definitely appreciate it.|
  4. value investing
    Thank you for sharing your info. I really appreciate your efforts and I am waiting for your next write ups thank you once again.
  5. electronic shop
    Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I've been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.
  6. mobsex.mobi
    Hi, Тһere's no doubt that your wensite miցht bе having web browser compatibility problems. When I take a look at your site in Safaгi, it looks fine however, when opening in I.E., іt has some overlapping issues. I merely wаqnted to provide you with a quiсk heads up! Beѕideѕ that, fаntastic blog!
  7. healthy
    Amazing! Its actually awesome piece of writing, I have got much clear idea regarding from this paragraph.
  8. special education
    You actually make it appear so easy along with your presentation however I to find this matter to be really one thing that I think I might by no means understand. It sort of feels too complex and very vast for me. I am looking ahead in your next put up, I will attempt to get the cling of it!
  9. home business
    I think that what you said was actually very logical. However, what about this? suppose you were to write a awesome headline? I am not saying your information isn't good, however suppose you added something to possibly get folk's attention? I mean %BLOG_TITLE% is a little boring. You ought to look at Yahoo's home page and watch how they create article titles to grab viewers to click. You might try adding a video or a related pic or two to get readers interested about what you've written. In my opinion, it would make your website a little livelier.
  10. nikon camera
    Great delivery. Outstanding arguments. Keep up the great work.
  11. recommended financial advisors
    I am sure this article has touched all the internet visitors, its really really nice piece of writing on building up new webpage.
  12. employment advice
    It is actually a nice and useful piece of info. I'm satisfied that you simply shared this helpful information with us. Please keep us informed like this. Thank you for sharing.
  13. cheap online shopping sites
    My partner and I stumbled over here coming from a different page and thought I should check things out. I like what I see so now i am following you. Look forward to looking at your web page for a second time.
  14. post a job
    Heya excellent website! Does running a blog like this require a lot of work? I've virtually no expertise in coding however I had been hoping to start my own blog in the near future. Anyways, if you have any ideas or tips for new blog owners please share. I know this is off subject but I simply had to ask. Thank you!
  15. best medical websites
    Hello there, just changed into alert to your blog thru Google, and found that it is truly informative. I'm gonna watch out for brussels. I will appreciate in case you proceed this in future. Many people will be benefited from your writing. Cheers!
  16. estate financial planning
    I read this post fully on the topic of the resemblance of hottest and preceding technologies, it's awesome article.
  17. camera accessories
    I got this website from my buddy who shared with me about this website and at the moment this time I am browsing this site and reading very informative articles at this place.
  18. education school
    Hello there! Do you know if they make any plugins to help with SEO? I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good results. If you know of any please share. Thank you!
  19. family search
    My spouse and I stumbled over here coming from a different page and thought I might as well check things out. I like what I see so now i am following you. Look forward to checking out your web page repeatedly.
  20. phone cases
    Now I am ready to do my breakfast, later than having my breakfast coming over again to read more news.
  21. health coverage
    Good information. Lucky me I discovered your website by accident (stumbleupon). I've book marked it for later!
  22. how to buy gold
    I need to to thank you for this excellent read!! I certainly loved every bit of it. I've got you book-marked to look at new stuff you post…
  23. employment law discrimination
    When someone writes an piece of writing he/she retains the idea of a user in his/her brain that how a user can understand it. So that's why this post is great. Thanks!
  24. education degree
    I always used to read article in news papers but now as I am a user of web therefore from now I am using net for content, thanks to web.

Speak Your Mind