You need to set up a 'server' configuration in 'Settings Languages and Frameworks PHP Servers' which maps the paths as seen on the server to the paths in your project. Normally, you would enter a URL into 'Host' and set 'Port' to the HTTP port, e.g. For CLI scripts, the info to put in here will be based on your connection to. By default, Xdebug listens on port 9000. To have PhpStorm accept any incoming connections from Xdebug engines through the port specified in the Debug port field, select the Can accept external connections checkbox. Select the Force break at the first line when no path mapping is specified. Xdebug and PhpStorm combination The combination of Xdebug and PhpStorm is one of the best ways to debug Magento 2 store. The main advantage of this method is that it adds breakpoints to the installation process and can help the developer review and change variables at any given time. By default, Xdebug 2 listens on port 9000. For Xdebug 3, the default port has changed from 9000 to 9003. You can specify several ports by separating them with a comma. By default, the Debug port value is set to 9001,9003 to have PhpStorm listen on both ports simultaneously. Set PHP CLI Interpreter. Go to Settings Languages & Frameworks PHP Debug Make sure you have set debug port for XDebug to 9003. Put your Create Magento App running port as Port value, select XDebug as Debugger value. To find what your Port value is, use status command. Debug server configuration.
Table of Contents
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:
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:
For Firefox:
In PhpStorm:
Now you will want to place a breakpoint where your code would stop. It looks like this:
When you runs the code, it would stop at the breakpoint and a debug window shows up.
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…
Phpstorm Xdebug Vagrant
Phpstorm Xdebug Not Working
While working on debug window, if you want to:
- Execute the current code and go to the next line, press
- Go into the current method, press
- Step out, press
- Stop debugging, continue the code flow, press
- Stop the code flow and then terminate the debug, press
Phpstorm Setup Xdebug
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.
Comments are closed.