phpphpstormxdebugphpstorm-2017.2

Xdebug stopped connecting to PhpStorm in multi-versioned PHP Vagrant


I was using a really old Homestead version 2.0 with PHP 7.0 and Xdebug enabled. When I upgraded to Homestead 7.0.1 which supports multiple versions of PHP running at the same time, Xdebug stopped connecting to PhpStorm 2017.

The configuration in PhpStorm is the same as before the Homestead upgrade.

I copied my original xdebug.ini into the new PHP 7.1 ini for Xdebug. Here is my current config:

zend_extension=xdebug.so
xdebug.var_display_max_data = -1
xdebug.var_display_max_depth = 10
xdebug.default_enable = 0
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9001
xdebug.remote_host = 192.168.10.1
xdebug.remote_autostart = 0
xdebug.remote_handler = dbgp
xdebug.idekey = PHPSTORM
xdebug.collect_return = 1
xdebug.collect_params = 10
xdebug.show_mem_delta = 1
xdebug.profiler_enable_trigger = 1
xdebug.profiler_output_dir = "/home/vagrant/Projects/xdebug_profiler"
xdebug.trace_enable_trigger = 1
xdebug.trace_output_dir = "/home/vagrant/Projects/xdebug_traces"
xdebug.profiler_enable = 0
xdebug.trace_enable = 1
xdebug.cli_color = 1
xdebug.remote_log = "/home/vagrant/Projects/logs/xdebug_remote.log"

If I run php -m I see Xdebug is not in that list because Homestead 7 makes PHP 7.2 the default, which is incompatible with Xdebug as of this post. However, if I do php7.1 -m I see Xdebug in the list and php7.1 -v shows:

with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans

So I know Xdebug is installed properly.

PhpStorm's prefs show it is using the 7.1 interpreter on Vagrant and that it is able to successfully connect to Vagrant. I manually navigated to the xdebug.so file on vagrant thru PhpStorm's UI just to be sure it could find it.

enter image description here

enter image description here

enter image description here

Running CLI scripts by doing php7.1 artisan explicitly instead of php artisan does not help.

This inconsistently shows up in my /home/vagrant/Projects/logs/xdebug_remote.log but most of the time there is no remote log entry:

Log opened at 2018-01-17 17:50:46
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
I: Remote address found, connecting to 192.168.10.1:9001.
W: Creating socket for '192.168.10.1:9001', poll success, but error: Operation now in progress (29).
E: Could not connect to client. :-(
Log closed at 2018-01-17 17:50:46

Why can't PhpStorm receive signals from Xdebug on Vagrant anymore?


Solution

  • To fix this I need to set PHP 7.1 as the default instead of PHP 7.2. This was done by running this series of commands and then reconnecting too Xdebug within PHPStorm:

    sudo update-alternatives --set php /usr/bin/php7.1
    sudo update-alternatives --set phar /usr/bin/phar7.1
    sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.1 
    sudo update-alternatives --set phpize /usr/bin/phpize7.1
    sudo update-alternatives --set php-config /usr/bin/php-config7.1
    sudo service php7.1-fpm restart