Xdebug 在多版本 PHP Vagrant 中停止连接到 PhpStorm
Xdebug stopped connecting to PhpStorm in multi-versioned PHP Vagrant
我使用的是非常老的 Homestead 2.0 版,PHP 7.0 并启用了 Xdebug。当我升级到同时支持 PHP 运行ning 多个版本的 Homestead 7.0.1 时,Xdebug 停止连接到 PhpStorm 2017.
PhpStorm中的配置与Homestead升级前相同
我将原来的 xdebug.ini
复制到新的 PHP Xdebug 7.1 ini 中。这是我当前的配置:
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"
如果我 运行 php -m
我看到 Xdebug 不在那个列表中,因为 Homestead 7 使 PHP 7.2 成为默认值,从这个 post.但是,如果我这样做 php7.1 -m
我会在列表中看到 Xdebug,并且 php7.1 -v
显示:
with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
所以我知道 Xdebug 安装正确。
PhpStorm 的首选项显示它在 Vagrant 上使用 7.1 解释器并且能够成功连接到 Vagrant。我通过 PhpStorm 的 UI 手动导航到 vagrant 上的 xdebug.so
文件,只是为了确保它能找到它。
运行 CLI 脚本通过 php7.1 artisan
显式代替 php artisan
没有帮助。
这在我的 /home/vagrant/Projects/logs/xdebug_remote.log
中显示不一致,但大多数时候没有远程日志条目:
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
为什么 PhpStorm 无法再从 Vagrant 上的 Xdebug 接收信号?
要解决此问题,我需要将 PHP 7.1 设置为默认值,而不是 PHP 7.2。这是通过 运行 这一系列命令完成的,然后在 PHPStorm:
中重新连接 Xdebug
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
我使用的是非常老的 Homestead 2.0 版,PHP 7.0 并启用了 Xdebug。当我升级到同时支持 PHP 运行ning 多个版本的 Homestead 7.0.1 时,Xdebug 停止连接到 PhpStorm 2017.
PhpStorm中的配置与Homestead升级前相同
我将原来的 xdebug.ini
复制到新的 PHP Xdebug 7.1 ini 中。这是我当前的配置:
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"
如果我 运行 php -m
我看到 Xdebug 不在那个列表中,因为 Homestead 7 使 PHP 7.2 成为默认值,从这个 post.但是,如果我这样做 php7.1 -m
我会在列表中看到 Xdebug,并且 php7.1 -v
显示:
with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
所以我知道 Xdebug 安装正确。
PhpStorm 的首选项显示它在 Vagrant 上使用 7.1 解释器并且能够成功连接到 Vagrant。我通过 PhpStorm 的 UI 手动导航到 vagrant 上的 xdebug.so
文件,只是为了确保它能找到它。
运行 CLI 脚本通过 php7.1 artisan
显式代替 php artisan
没有帮助。
这在我的 /home/vagrant/Projects/logs/xdebug_remote.log
中显示不一致,但大多数时候没有远程日志条目:
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
为什么 PhpStorm 无法再从 Vagrant 上的 Xdebug 接收信号?
要解决此问题,我需要将 PHP 7.1 设置为默认值,而不是 PHP 7.2。这是通过 运行 这一系列命令完成的,然后在 PHPStorm:
中重新连接 Xdebugsudo 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