Blog

PhpStorm: Fixing "Connection with xdebug was not established" in vagrant

A few months ago I decided to take advantage of some PhpStorm 8 features and give this a try. My objective was to, also run unit tests directly from the IDE, to be able to debug them.

The tutorials "Running PHPUnit tests over SSH on a remote server with PhpStorm" and "Working with Remote PHP Interpreters in PhpStorm" where very help full to get me 90% of the way to my destination.

Unfortunately, while I was able to run the test from PhpStorm 8, I was not able to get the breakpoints to work. At this point, I contacted the JetBrains support team. Apparently my problem was that I had decided to use a remote interpreter using the Vagrant option.

The first thing support asks me to do was:

Please add deployment to your Vagrant machine (Tools | Deployment | Configuration), then please add the remote interpreter with deployment option (there will be the third option in interpreter's settings).

At this time it seems like remote debugging on PHPUnit and CLI scripts is only possible when the remote interpreter and SFTP deployment server are set and the correct mappings have been configured (see Deploying PHP applications with PhpStorm for more information).

Doing so worked very well; I was able to run a unit test and add breakpoints, everything works as expected... but not for long. Inexplicably, after adding deployments to several projects, I started getting the following message while trying to debug:

"Connection with 'xdebug' was not established. Validate installation"

or simply:

"Connection with 'xdebug' was not established."

This is where things get really dicey and support was not helpful at all. The problem may be related to how the xdebug configuration is setup but I'm going to keep this portin as breef as possible. In my case I have disabled xdebug.remote_connect_back and instead enabled xdebug.remote_host=192.168.146.1. ``` ;xdebug.ini zendextension=/usr/lib/php5/20121212/xdebug.so xdebug.remoteenable = 1 xdebug.profiler_enable=1

;xdebug.remoteconnectback = 1

xdebug.remoteport = 9000 xdebug.scream=0 xdebug.clicolor=1 xdebug.showlocalvars=1 xdebug.remote_host=192.168.146.1

; vardump display xdebug.vardisplaymaxdepth = 5 xdebug.vardisplaymaxchildren = 256 xdebug.vardisplaymaxdata = 1024 ```

PhpStorm for some unknown reason started setting the xdebug.remote_host to 192.168.146.2 and this is where things stop working.

The reason still escapes me, but I device two ways to fix the issue.

  1. Restore the ~/Library/Preferences/WebIde80 directory from a backup (this is if it was ever working)
  2. Modify the ~/Library/Preferences/WebIde80/options/php.xml and manually modify the component -> phpInfoCache -> interpreter -> phpinfo and update the properyty remote_host. Then Invalidate the Caches (file -> Invalidate Caches / Restart...), restart and retry.