简体   繁体   English

无法让 PhpStorm 连接到在 WSL 2 中运行的 Xdebug

[英]Unable to get PhpStorm to connect to Xdebug running in WSL 2

I am having trouble getting PhpStorm 2020.2 to work with xdebug with the following setup: WSL2 running Ubuntu 20, with PHP and php-xdebug installed.我无法通过以下设置使 PhpStorm 2020.2 与 xdebug 一起使用:WSL2 运行 Ubuntu 20,安装了 PHP 和 php-xdebug。 Whenever I run my tests with debugging enabled it says "Connection was not established.".每当我在启用调试的情况下运行测试时,它都会显示“未建立连接。”。

This is what the Xdebug log shows:这是 Xdebug 日志显示的内容:

[5877] Log opened at 2020-08-14 17:20:45
[5877] I: Connecting to configured address/port: 172.18.48.1:9006.
[5877] E: Time-out connecting to client (Waited: 200 ms). :-(
[5877] Log closed at 2020-08-14 17:20:46

This is for CLI only , I'm not trying to connect via php-fpm (so no Apache, nginx, ...).这仅适用于 CLI ,我不尝试通过 php-fpm 连接(所以没有 Apache、nginx,...)。

So far I have tried:到目前为止,我已经尝试过:

  • Changing the port to something other than 9000 (portscans also reveal that none of them are in use).将端口更改为 9000 以外的端口(端口扫描还显示它们都没有被使用)。

  • Adding a firewall rule to allow incoming requests as described in https://github.com/microsoft/WSL/issues/4585#issuecomment-610061194 (as well as restarting a couple times after adding the rule)添加防火墙规则以允许传入请求,如https://github.com/microsoft/WSL/issues/4585#issuecomment-610061194中所述(以及在添加规则后重新启动几次)

     New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
  • Adding options like xdebug.remote_enable=1 to the config, but this is being done by PhpStorm anyways when it runs the remote php instance ( remote_connect_back also did not do the trick):将诸如xdebug.remote_enable=1之类的选项添加到配置中,但这无论如何都是由 PhpStorm 在运行远程 php 实例时完成的( remote_connect_back也没有做到这一点):

     [wsl://UBUNTU2004]:php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9006 -dxdebug.remote_host=172.18.48.1 /home/spaceemotion/code/xxxxxx/backend/vendor/phpunit/phpunit/phpunit [rest ommitted]

Any help would be much appreciated!任何帮助将非常感激!

As per: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000436444/comments/360000168070根据: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000436444/comments/360000168070

In Windows Control Panel > Windows Firewall > Allow a program or feature through Windows Firewall you can see a list of software that is allowed to communicate through private and public networks.在 Windows 控制面板 > Windows 防火墙 > 允许程序或功能通过 Windows 防火墙中,您可以看到允许通过专用网络和公共网络进行通信的软件列表。

Make sure the phpstorm.exe is actually allowed (for me the private network options were unchecked).确保实际允许使用 phpstorm.exe(对我来说,未选中专用网络选项)。

Use Xdebug with PhpStorm and WSL 将 Xdebug 与 PhpStorm 和 WSL 一起使用

It help me this and also de xdebug.org/wizard它对我有帮助,也对 xdebug.org/wizard 有帮助

Just follow those to pages只需按照这些页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM