【问题标题】:Xdebug running on remote host: cannot connect back to client -> timeoutXdebug 在远程主机上运行:无法连接回客户端 -> 超时
【发布时间】:2019-09-07 07:49:16
【问题描述】:

两天以来,我试图让我的 Xdebug 配置运行但没有成功,这让我抓狂!

我的设置

客户端:带有 PhpStorm 的 Macbook Pro

Xdebug 正在 jwilder/nginx 代理后面的 Docker(最新稳定版本)容器中的远程服务器 (Ubuntu 18.04) 上运行。

Xdebug 运行于 PHP 7.3.9,Xdebug 版本为 2.7.2

Xdebug 设置:

xdebug.remote_enable=1
xdebug.remote_host=host.docker.internal
xdebug.remode_mode=req
xdebug.remote_handler=dbgp
xdebug.remote_port=10000
xdebug.idekey=PHPSTORM
xdebug.remote_connect_back=1
xdebug.remote_autostart=1
xdebug.remote_log=/var/log/xdebug.log

xdebug.remote_hostdocker.host.internal,因为我从本地 xdebug.ini 复制了我的配置文件。在 Mac 上,您使用此值。在这种情况下,xdebug.remote_host 将被忽略,因为 xdebug.remote_connect_back 已打开。

这是 phpinfo 页面(太大而无法在此处显示实际图像)。

phpinfo

这是我的 xdebug 日志文件中的输出

[17] Log opened at 2019-09-07 07:40:29
[17] I: Checking remote connect back address.
[17] I: Checking header 'HTTP_X_FORWARDED_FOR'.
[17] I: Remote address found, connecting to 178.203.235.46:10000.
[17] E: Time-out connecting to client (Waited: 200 ms). :-(
[17] Log closed at 2019-09-07 07:40:29

这是我在 PhpStorm 中的远程 Xdebug 验证:

似乎一切都应该运行:PhpStorm 设置正确(侦听端口 10000) - 但它不是!!!

我尝试了什么:几乎所有东西。我使用了较旧的 Xdebug 版本,其他 PHP 版本......什么都没有。 Xdebug 想要连接到我的客户端时总是超时。

我还禁用了xdebug.remote_connect_back 并将HTTP_X_REAL_IP 用作xdebug.remote_host --> 超时。

然后我想可能是 nginx 代理。所以我在没有它的情况下尝试了它->同样的错误:超时。

我做错了什么?

【问题讨论】:

  • 1) “远程服务器”是什么意思?它只是描述 Docker 容器......还是它实际上在其他地方的另一台计算机上运行(不是运行 IDE 的地方)? 2) 确保 PhpStorm 是侦听 TCP 10000 端口(@98​​7654334@ 或类似名称,例如 netstat 可能)的端口 3) 确保它不是防火墙问题。
  • 远程服务器是其他地方的计算机
  • 嗯......然后确保 Xdebug 连接可以完全脱离远程服务器,并且您的本地计算机/路由器允许 Xdebug 端口上的传入连接。 xdebug.remote_host=host.docker.internal 不会工作......因为在这种情况下,它只是尝试连接到 Docker 的主机操作系统,仅此而已(除非您有一些 SSH 隧道/转发,可以将连接进一步传递回您的本地计算机)。
  • 所以 SSH 到远程服务器(不是 docker 容器)并尝试从那里连接回 IDE(例如使用 telnet)。如果可行——深入挖掘/下一步;如果没有 - 修复它。以防万一:xdebug.org/docs/remote#communication -- 看看 Xdebug 是如何工作的。
  • 然后使用 SSH 隧道(从您的 Mac 到远程服务器)。如果一切正常,来自 Docker 容器的 xdebug 连接将到达主机操作系统,并将连接到 SSH 端口,该端口会将其转发回您的计算机。它仍然有点复杂(因为它是 SSH + Docker)——参见 jetbrains.com/help/phpstorm/…

标签: php docker debugging phpstorm xdebug


【解决方案1】:

几年前我写了这篇文章,可能会有所帮助:https://medium.com/@pavlakis/setting-up-xdebug-with-docker-and-php-7-2-f5a6553cb956

如果您使用的代理为您提供不同的 IP,请尝试以下操作:https://github.com/phpminds/website/blob/master/docker.sh

【讨论】:

    猜你喜欢
    • 2012-07-18
    • 1970-01-01
    • 2013-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-13
    相关资源
    最近更新 更多