Table of contents
This tutorial shows you how to debug your code using PhpStorm and Google Chrome browser with Xdebug.
Configure PhpStorm to work with Xdebug
- Open PhpStorm Project > Settings panel
- Windows: Select File > Settings.
- Mac OS X: Select PhpStorm > Preferences.
- Expand Language & Frameworks > PHP
- Set the CLI interpreters.
- Click Server then Add a new server configuration.
Configure as below:
– Name: localhost (Same as PHP_IDE_CONFIG
in docker-compose.yml)
– Host: localhost
– Port: 80
- Tick the Use path mapping checkbox and add your mappings.
- Under the PHP node, click Debug.
- Set the Xdebug port to
9000
(Xdebug 2). For Xdebug 3, set the port to9003
. - Click Apply.
Create an SSH tunnel
Before you run Xdebug, you must create an SSH tunnel to the DevBox container. You can download Magento DevBox on Magento Tech Resource Download page.
On Windows
To use an SSH tunnel on Windows:
1. Start Putty.
2. In the Category pane, click Session.
3. In Hostname (or IP address) field: Enter the SSH URL for your Cloud server
In Port field: Enter 22
4. In the Category pane, click Connection > SSH > Tunnels.
5. Enter the following information:
– Source port field: Enter 9000
– Destination field: Enter 127.0.0.1:9000
Click Remote
Click Add.
6. In the Category pane, click Session.
7. In the Saved Sessions field, enter a name for this SSH tunnel.
8. Click Save.
9. From the Saved Sessions list, click the name of your DevBox SSH session and click Load.
10. Click Open.
11. At the Login as prompt, enter magento2
On Mac OS
To create an SSH tunnel on Mac OS, open a Terminal window and enter the following command:
./<DevBox root folder>/m2devbox-debug.sh
*If it shows an “unable to connect” or “could not listen to port on remote” error, there could be another active SSH session on the server that is occupying port 9000
. If that connection isn’t being used, you can terminate it.
Use Xdebug in Chrome
- Install the Xdebug Helper extension.
- Enable the extension in Chrome.
- Open your DevBox PhpStorm project.
- In the top navigation bar, click(Start listening). If the navigation bar isn’t displayed, click View > Navigation Bar.
- In the PhpStorm navigation pane, double-click the PHP file to test.
- In the right pane, in the gray area next to a line number, click to set a breakpoint.
- In Chrome, go to a URL that invokes the breakpoint.If Chrome is already displaying the URL, click Refresh in the Chrome toolbar.
If the Incoming Connection from Xdebug dialog box displays, select the same file in which you set the breakpoint and click Accept.