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. How To Debug PHP Container With Xdebug And PhpStorm. May 20th 2020 11,692 reads @ifominIgor Fomin. Full stack web developer, tech lead, project manager. 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.
In the development process, we have several existing codes with a number of functionalities. We don’t have to create that functionality from the core every time. We can rather use the existing code and make simple modifications that will save our time and energy. Product development processes work the same. Before modifying the existing code, we need to know how they work and which codes have which functionality.
Now you may have the question, can we see how the PHP code works? It is a virtual object, right?
Absolutely! You can see the flow of the PHP code, and there is a tool. It is called Xdebug. Here we can see how to configure the Xdebug with PhpStorm IDE.
Install Xdebug on Ubuntu using following cmd:
Once you have installed the Xdebug into your system, restart your apache2 server and enable error tracing using the below cmd.
You have successfully installed Xdebug into your system!
Now, we need to configure Xdebug with PhpStorm.
Step 2: Install Xdebug helper extension in the Chrome browser to receive the details from the browser to PhpStorm.
Step 3: In PhpStorm Settings/Preferences dialog (Ctrl+Alt+S), select Languages & Frameworks | PHP.
Step 4: Check the Xdebug installation associated with the selected PHP interpreter:
On the PHP page, choose the relevant PHP installation from the CLI Interpreter list and click ” .. “ next to the field. The list shows all the PHP installations available in PhpStorm.
The CLI Interpreters dialog that opens shows the following:
The version of the selected PHP installation.
The name and version of the debugging engine associated with the selected PHP installation (Xdebug or Zend Debugger).
Step 5: Define the Xdebug behaviour. Click Debug under the PHP node. On the Debug page that opens, specify the following settings in the Xdebug area:
In the Debug Port field, appoint the port through which the tool will communicate with PhpStorm. This must be exactly the same port number as specified in the php.ini file: xdebug.remote_port =<port_number> 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.
Select the Force break at the first line when the script is outside the project. Don’t miss saving these options.
Step 6: Now, you are ready to use Xdebug with PhpStorm.
Add breakpoints where you need to debug using click on corresponding code.
Step 7: Then click Run > Stop Listening For PHP Debug Connections option. Please make sure it is in the green color.
Step 8: Open the Chrome Browser where you can see the green bug in the right corner of the Chrome browser, then click and choose Debug option. Now, your browser is ready to send the details to PhpStorm.
Step 9: Now, you should load the page where you must execute the breakpoints, which has been mentioned in Step 6 in PhpStorm. After some time, the PhpStorm will show the variable values which you must select as the breakpoint. Then, press F7 to bring up the flow on how the final output should be displayed.
This debugging of code using Xdebug and PhpStorm can be beneficial for your development in the debug process, thus helping you save the amount of time spent searching on Google.
The page is available only when the PHP plugin is enabled. The PHP plugin is bundled with PhpStorm and activated by default. If the plugin is disabled, enable it on the Settings/Preferences | Plugins page as described in Managing plugins.
Use this page to configure the behaviour of the Xdebug and Zend Debugger.
Phpstorm Xdebug Ssh
Item
Description
Pre-configuration
This area shows brief guidelines for installing a debugger, generating bookmarklets through which you will start/stop a debugging session by controlling the debugger cookie, and starting Zero-configuration debugging.
External connections
In this area, specify how you want PhpStorm to treat connections received from hosts and through ports that are not registered as deployment server configurations.
Ignore external connections through unregistered server configurations: Select this checkbox to have PhpStorm ignore connections received from hosts and through ports that are not registered as deployment server configurations. When this checkbox is selected, PhpStorm does not attempt to create a deployment server configuration automatically.
Break at first line in PHP scripts: Select this checkbox to have the debugger stop as soon as connection between it and PhpStorm is established (instead of running automatically until the first breakpoint is reached). Alternatively turn on the Run | Break at first line in PHP scripts option from the main menu.
Max. simultaneous connections Use this spin box to limit the number of external connections that can be processed simultaneously.
Xdebug
Use the controls in this area to configure debugging using the Xdebug tool.
Debug port: in this field, specify the port for PhpStorm and the Xdebug engine to communicate through.
This must be the same port number as specified in the php.ini file:
xdebug.remote_port='<the port (9000 by default) to which Xdebug connects>'
xdebug.client_port='<the port (9003 by default) to which Xdebug connects>'
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.
Can accept external connections: select this checkbox to enable PhpStorm to accept any incoming connections from Xdebug engines through the port specified in the Debug port field.
Resolve breakpoint if it's not available on the current line (Xdebug 2.8+): if selected, the support for the Xdebug breakpoints resolving mechanism will be enabled in PhpStorm. Under this mechanism, the debugger evaluates whether PHP can generate internal executable bytecode for the current line. If no such code is generated for a line, the corresponding breakpoint cannot be hit. Xdebug will scan up to 5 subsequent lines, and stop at the line where executable code is located. Resolving breakpoints is supported in Xdebug 2.8 and later.
Force break at first line when no path mapping specified: Select this checkbox to have the debugger stop as soon as it reaches and opens a file that is not mapped to any file in the project on the Servers page. The debugger stops at the first line of this file and Examine/update variables shows the following error message: Cannot find a local copy of the file on server <path to the file on the server> and a link Click to set up mappings. Click the link to open the Resolve Path Mappings Problem dialog and map the problem file to its local copy.
When this checkbox cleared, the debugger does not stop upon reaching and opening an unmapped file, the file is just processed, and no error messages are displayed.
Force break at first line when a script is outside the project: Select this checkbox to have the debugger stop at the first line as soon as it reaches and opens a file outside the current project. With this checkbox cleared, the debugger continues upon opening a file outside the current project.
Zend Debugger
Use the controls in this area to configure debugging using the Zend Debugger tool.
Debug port: In this field, specify the port for PhpStorm and the Zend Debugger engine to communicate through. Type the port number within the tunnel specified in the php.ini file through zend_debugger.tunnel_min_port and zend_debugger.tunnel_max_port. For details, see Zend Debugger - Configuration Directives
Can accept external connections: Select this checkbox to enable PhpStorm to accept any incoming connections from Zend Debugger engines through the port specified in the Debug port field.
Settings broadcasting port: In this field, specify the port through which the debugger settings are passed to the debugging toolbar in the browser.
Automatically detect IDE IP: when this checkbox is selected, PhpStorm detects all the host IP addresses to be sent to Zend Debugger through the debug_host parameter. All the detected IP addresses are listed in the field to the right. Auto-detection of IP address is helpful when you use Vagrant, or VirtualBox, or other virtualization tool.
Clear the checkbox to block auto-detection of host IP addresses and specify the required ones explicitly in the field.
Ignore Z-Ray system requests: Select this checkbox to block requests from the Z-Ray system if they annoy you by invoking the PhpStorm debugger too often.
If starting the Zend Debugger tool fails with the message 'Port is busy', specify a port number of your choice higher than 10000.
Evaluation
Show array and object children in Debug Console: Select this checkbox to show the output for arrays and objects in the Console pane. When the checkbox is cleared, the output is not displayed.
Safe evaluation mode in value hints and Watches Frame:
When this checkbox is selected, PhpStorm checks that the expression or code fragment to be evaluated does not contain any undefined elements and informs you about any discrepancies detected.
If the checkbox is cleared, an exception appears if PhpStorm encounters any undefined elements during evaluation.
See Evaluate expressions for details.
Import namespace and 'use' statements from evaluation context: When this checkbox is selected, during a debugging session PhpStorm is aware of the current namespace and of all the imported namespaces at the execution point. This information is used for calculating and showing Watches and Evaluate expressions to ensure that PhpStorm debug evaluations are identical with the actual result of the PHP code execution. By default, the checkbox is selected.
The result of executing the following code is true (or showing 1 in the browser):
namespace TooCar;class Car{}$my_car = new Car();echo $my_car instanceof Car;
If the Import namespace and use statements... checkbox is selected, evaluating the $my_car instanceof Car expression and the $my_car instanceof Car watch will also show this result:
However if you clear the checkbox, Watches and Evaluate Expression will be executed in the global context. This means that instead of $my_car instanceof Car you will need to use the fully qualified class name $my_car instanceof TooCarCar.
Advanced settings
Detect path mappings from deployment configurations:
When this checkbox is selected, PhpStorm attempts to retrieve path mappings for debugging in a remote environment from the server access configuration (deployment configuration ).
When the checkbox is cleared, you have to specify the path mappings manually.
See Validate the Configuration of a Debugging Engine and Configure remote PHP interpreters for details.
Notify if debug session was finished without being paused: Select this checkbox to have PhpStorm display a notification when no breakpoints are hit during Zero-Configuration debugging. This may happen if the path mappings are not configured or configured erroneously, or if you have not set any breakpoints. In the latter case, you can do any of the following:
Set a breakpoint by clicking the gutter at the desired executable line of code. See Breakpoints for details.
In the Settings/Preferences dialog Ctrl+Alt+S, go to PHP | Debug and in the External Connections area, select the Break at first line in PHP scripts checkbox.
Enable the Run | Break at first line in PHP scripts option from the main menu.
If the checkbox is cleared, no debugging session is established and the PHP script is just executed without being suspended.
Pass required configuration options through command line (still need to enable debug extension manually): select this checkbox to have debugger configuration options passed through a command line.
Notify if breakpoint was resolved to a different line (Xdebug 2.8+): if selected, PhpStorm displays a notification when a breakpoint is resolved. Note that you need to enable Xdebug breakpoints resolving for this to work.