更新到 WSL2 后无法从 PhpStorm 连接到 Xdebug
Cannot connect to Xdebug from PhpStorm after updating to WSL2
环境
- OS: Windows 10 专业版 1909
- WSL:Ubuntu (18.04.5)
- PHP: 7.3
- PhpStorm: 2020.2
我听说 WSL2 可以与 1909 一起使用,所以我将 Ubuntu 从 WSL1 升级到 2。
当我在设置后尝试使用 PhpStorm 进行调试时,“未建立连接”。已显示。
然后我看了看日志,
[2640] Log opened at 2020 xx-xx: xx: xx
[2640] I: Connecting to configured address/port: localhost: 9001.
[2640] W: Creating socket for 'localhost: 9001', poll success, but error: Operation now in progress (29).
[2640] E: Could not connect to client.: - (
[2640] Log closed at 2020 xx-xx: xx: xx
已显示。
我尝试更改各种 Xdebug 设置,但无法连接到任何设置。
从WSL2开始,IP地址就不同了,不过听说现在可以用localhost了,所以改成localhost,还是不行。
目前无法使用WSL2吗?或者有什么办法吗?
提前谢谢你。
/etc/php/7.3/cli/php.ini:
[xdebug]
;extension_dir = "/usr/lib/php/20190902"
;zend_extension = "/usr/lib/php/20190902/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/tmp"
xdebug.remote_enable=1
xdebug.remote_host="localhost"
xdebug.remote_port=9001
xdebug.remote_log=/var/log/xdebug.log
xdebug.idekey = "PHPSTORM"
/etc/php/7.3/cgi/conf.d/20-xdebug
zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9001
xdebug.remote_host = "localhost"
xdebug.remote_log=/var/log/xdebug.log
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "/tmp"
xdebug.max_nesting_level = 1000
xdebug.idekey = "PHPSTORM"
php信息:
php -info | grep -i xdebug
/etc/php/7.3/cli/conf.d/20-xdebug.ini,
with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans
xdebug
xdebug support => enabled
Support Xdebug on Patreon, GitHub, or as a business: https://xdebug.org/support
xdebug.auto_trace => Off => Off
xdebug.cli_color => 0 => 0
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.coverage_enable => On => On
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.file_link_format => no value => no value
xdebug.filename_format => no value => no value
xdebug.force_display_errors => Off => Off
xdebug.force_error_reporting => 0 => 0
xdebug.gc_stats_enable => Off => Off
xdebug.gc_stats_output_dir => /tmp => /tmp
xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p
xdebug.halt_level => 0 => 0
xdebug.idekey => PHPSTORM => PHPSTORM
xdebug.max_nesting_level => 1000 => 1000
xdebug.max_stack_frames => -1 => -1
xdebug.overload_var_dump => 2 => 2
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => On => On
xdebug.profiler_enable_trigger => Off => Off
xdebug.profiler_enable_trigger_value => no value => no value
xdebug.profiler_output_dir => /tmp => /tmp
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_addr_header => no value => no value
xdebug.remote_autostart => On => On
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_host => localhost => localhost
xdebug.remote_log => /var/log/xdebug.log => /var/log/xdebug.log
xdebug.remote_log_level => 7 => 7
xdebug.remote_mode => req => req
xdebug.remote_port => 9001 => 9001
xdebug.remote_timeout => 200 => 200
xdebug.scream => Off => Off
xdebug.show_error_trace => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.trace_enable_trigger => Off => Off
xdebug.trace_enable_trigger_value => no value => no value
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => /tmp => /tmp
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3
口译员:
调试:
- 您需要获取 Windows 主机的 IP 地址。您可以通过检查您的网络设置或在 DOS 提示符下(不是在 WSL2 中)简单地通过
ipconfig
来做到这一点。
Ethernet adapter Ethernet:
Connection-specific DNS Suffix . : Speedport_XXX
IPv6 Address. . . . . . . . . . . : XXX
Temporary IPv6 Address. . . . . . : XXX
Temporary IPv6 Address. . . . . . : XXX
Link-local IPv6 Address . . . . . : XXX
IPv4 Address. . . . . . . . . . . : 192.168.2.115
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : fe80::1%8
192.168.2.1
在我的示例中,IPv4 地址的值为 192.168.2.115
。
在 PhpStorm 中转到设置 > 语言和框架 > PHP > 调试
打开高级设置并启用“传递所需的配置选项...”
Select 你的 PHP > CLI 解释器
单击“配置选项”上的文件夹图标
点击“加号”并添加一个新条目
作为键xdebug.remote_host
将您的本地 IP 地址 (192.168.2.115
) 作为值
这将允许 WSL2 内部的 Xdebug 连接回您的 windows 主机。
环境
- OS: Windows 10 专业版 1909
- WSL:Ubuntu (18.04.5)
- PHP: 7.3
- PhpStorm: 2020.2
我听说 WSL2 可以与 1909 一起使用,所以我将 Ubuntu 从 WSL1 升级到 2。 当我在设置后尝试使用 PhpStorm 进行调试时,“未建立连接”。已显示。
然后我看了看日志,
[2640] Log opened at 2020 xx-xx: xx: xx
[2640] I: Connecting to configured address/port: localhost: 9001.
[2640] W: Creating socket for 'localhost: 9001', poll success, but error: Operation now in progress (29).
[2640] E: Could not connect to client.: - (
[2640] Log closed at 2020 xx-xx: xx: xx
已显示。
我尝试更改各种 Xdebug 设置,但无法连接到任何设置。
从WSL2开始,IP地址就不同了,不过听说现在可以用localhost了,所以改成localhost,还是不行。
目前无法使用WSL2吗?或者有什么办法吗? 提前谢谢你。
/etc/php/7.3/cli/php.ini:
[xdebug]
;extension_dir = "/usr/lib/php/20190902"
;zend_extension = "/usr/lib/php/20190902/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/tmp"
xdebug.remote_enable=1
xdebug.remote_host="localhost"
xdebug.remote_port=9001
xdebug.remote_log=/var/log/xdebug.log
xdebug.idekey = "PHPSTORM"
/etc/php/7.3/cgi/conf.d/20-xdebug
zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9001
xdebug.remote_host = "localhost"
xdebug.remote_log=/var/log/xdebug.log
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "/tmp"
xdebug.max_nesting_level = 1000
xdebug.idekey = "PHPSTORM"
php信息:
php -info | grep -i xdebug
/etc/php/7.3/cli/conf.d/20-xdebug.ini,
with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans
xdebug
xdebug support => enabled
Support Xdebug on Patreon, GitHub, or as a business: https://xdebug.org/support
xdebug.auto_trace => Off => Off
xdebug.cli_color => 0 => 0
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.coverage_enable => On => On
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.file_link_format => no value => no value
xdebug.filename_format => no value => no value
xdebug.force_display_errors => Off => Off
xdebug.force_error_reporting => 0 => 0
xdebug.gc_stats_enable => Off => Off
xdebug.gc_stats_output_dir => /tmp => /tmp
xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p
xdebug.halt_level => 0 => 0
xdebug.idekey => PHPSTORM => PHPSTORM
xdebug.max_nesting_level => 1000 => 1000
xdebug.max_stack_frames => -1 => -1
xdebug.overload_var_dump => 2 => 2
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => On => On
xdebug.profiler_enable_trigger => Off => Off
xdebug.profiler_enable_trigger_value => no value => no value
xdebug.profiler_output_dir => /tmp => /tmp
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_addr_header => no value => no value
xdebug.remote_autostart => On => On
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_host => localhost => localhost
xdebug.remote_log => /var/log/xdebug.log => /var/log/xdebug.log
xdebug.remote_log_level => 7 => 7
xdebug.remote_mode => req => req
xdebug.remote_port => 9001 => 9001
xdebug.remote_timeout => 200 => 200
xdebug.scream => Off => Off
xdebug.show_error_trace => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.trace_enable_trigger => Off => Off
xdebug.trace_enable_trigger_value => no value => no value
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => /tmp => /tmp
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3
口译员:
调试:
- 您需要获取 Windows 主机的 IP 地址。您可以通过检查您的网络设置或在 DOS 提示符下(不是在 WSL2 中)简单地通过
ipconfig
来做到这一点。
Ethernet adapter Ethernet:
Connection-specific DNS Suffix . : Speedport_XXX
IPv6 Address. . . . . . . . . . . : XXX
Temporary IPv6 Address. . . . . . : XXX
Temporary IPv6 Address. . . . . . : XXX
Link-local IPv6 Address . . . . . : XXX
IPv4 Address. . . . . . . . . . . : 192.168.2.115
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : fe80::1%8
192.168.2.1
在我的示例中,IPv4 地址的值为 192.168.2.115
。
在 PhpStorm 中转到设置 > 语言和框架 > PHP > 调试
打开高级设置并启用“传递所需的配置选项...”
Select 你的 PHP > CLI 解释器
单击“配置选项”上的文件夹图标
点击“加号”并添加一个新条目
作为键
xdebug.remote_host
将您的本地 IP 地址 (
192.168.2.115
) 作为值
这将允许 WSL2 内部的 Xdebug 连接回您的 windows 主机。