本文介绍了无法让 PhpStorm 连接到在 WSL 2 中运行的 Xdebug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过以下设置使 PhpStorm 2020.2 与 xdebug 一起使用:WSL2 运行 Ubuntu 20,安装了 PHP 和 php-xdebug.每当我在启用调试的情况下运行测试时,它都会显示未建立连接".

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. Whenever I run my tests with debugging enabled it says "Connection was not established.".

这是 Xdebug 日志显示的内容:

This is what the Xdebug log shows:

[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

这仅适用于 CLI,我不想通过 php-fpm 进行连接(因此没有 Apache、nginx 等).

This is for CLI only, I'm not trying to connect via php-fpm (so no Apache, nginx, ...).

到目前为止我已经尝试过:

So far I have tried:

  • 将端口更改为 9000 以外的其他端口(端口扫描还显示它们均未在使用中).

  • Changing the port to something other than 9000 (portscans also reveal that none of them are in use).

添加防火墙规则以允许传入请求,如 https 中所述://github.com/microsoft/WSL/issues/4585#issuecomment-610061194(以及添加规则后重新启动几次)

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)

New-NetFirewallRule -DisplayName "WSL" -Direction Inbound  -InterfaceAlias "vEthernet (WSL)"  -Action Allow

  • xdebug.remote_enable=1 之类的选项添加到配置中,但无论如何,PhpStorm 在运行远程 php 实例时都会这样做(remote_connect_back 也没有做到这一点):

  • 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):

    [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]
    

  • 任何帮助将不胜感激!

    推荐答案

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

    在 Windows 控制面板中 >Windows 防火墙 >允许程序或功能通过 Windows 防火墙,您可以看到允许通过专用和公共网络进行通信的软件列表.

    确保确实允许使用 phpstorm.exe(对我而言,未选中专用网络选项).

    Make sure the phpstorm.exe is actually allowed (for me the private network options were unchecked).

    这篇关于无法让 PhpStorm 连接到在 WSL 2 中运行的 Xdebug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-07 07:02