CLI debugging. I never did that. Until today. My tests started to fail and I had no idea why.
So that’s my story why I started to debug tests in the CLI via SSH.
Here’s a list of ingredients:
- remote SSH (I’m using Vagrant),
- PHP + XDebug.
First thing what we need to do is to configure the PhpStorm.
Open your setting and go to Languages & Frameworks > PHP > Debug > DBGp Proxy.
- Fill the field IDE key with key you choose (I chose PHPSTORM and I recommend it).
- In the Host field put the IP which is seen by remote (run echo $SSH_CLIENT on the remote to see it).
- Default Port is 9000 and you should not change it.
Next thing to configure is Language & Frameworks > PHP > Servers.
- Put the server Name.
- In the Host field type the IP address, same as on DBGp Proxy.
- If you set other Port for DBGp Proxy then change it here.
- As we are working on XDebug you don’t have to change the Debugger :).
- My remote has different folders structure so I had to set path mapping, probably you will have to do the same.
Ok PhpStorm is ready to go.
Now go to SSH and run this command:
export XDEBUG_CONFIG="remote_host=10.0.2.2 idekey=PHPSTORM remote_connect_back=0"
In the first line put your Server Name which you’ve just set. In the second just update the remote_host with the IP address and change the idekey to yours.
The last thing to do is to enable listening for debug connections in the PhpStorm. Just click the button in the top right corner:
Ah I forgot, please add some breakpoints! And then you can run your tests / scripts etc.