docker容器中的Xdebug无法连接到Qubes OS上的PhpStorm

时间:2019-10-31 10:53:03

标签: linux docker phpstorm xdebug qubes-os

Docker容器中的Xdebug无法连接到我系统上的PhpStorm。

我正在尝试使用PhpStorm在Linux上的Docker环境中设置Xdebug(qubes-os / Fedora 30)。 Xdebug已启用,我可以访问错误消息。在PhpStorm中,我始终使用我给Xdebug作为远程主机的相应IP更新DBGp代理设置。我尝试了许多版本的Xdebug安装程序,但都失败了。

我目前的最佳猜测是内部IP管理有些混乱。这可能是由于qubes-os引起的,但是我并没有真正确信,因为它是正常的Fedora,而且我以前从未遇到过类似的问题...

我的 Xdebug conf

zend_extension=xdebug.so

[Xdebug]
xdebug.idekey=PHPSTORM
xdebug.remote_enable=true
xdebug.remote_port=5902
xdebug.remote_host=host.docker.internal
xdebug.remote_log=/tmp/xdebug-remote.log

我知道host.docker.internal在Linux上不起作用。无论如何,我正在使用它,通过在{{1} docker容器的文件)

我的 phpinfo()

/etc/hosts

我的网络日志告诉我,我的请求来自 xdebug support enabled Version 2.6.1 IDE Key PHPSTORM xdebug.remote_enable On On xdebug.remote_handler dbgp dbgp xdebug.remote_host host.docker.internal host.docker.internal xdebug.remote_log /tmp/xdebug-remote.log /tmp/xdebug-remote.log xdebug.remote_mode req req xdebug.remote_port 5902 5902 xdebug.remote_timeout 200 200

我的 172.18.0.1 - - [31/Oct/2019:09:58:22 +0000] "GET / HTTP/1.1" 200 47698 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36"输出主机

ifconfig

我的 br-8d5002ad7a3a: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.18.0.1 netmask 255.255.0.0 broadcast 172.18.255.255 inet6 fe80::42:17ff:feaa:e865 prefixlen 64 scopeid 0x20<link> ether 02:42:17:aa:e8:65 txqueuelen 0 (Ethernet) RX packets 5 bytes 513 (513.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 11 bytes 866 (866.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 inet6 fe80::42:99ff:fe38:e669 prefixlen 64 scopeid 0x20<link> ether 02:42:99:38:e6:69 txqueuelen 0 (Ethernet) RX packets 4055 bytes 233615 (228.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 4367 bytes 55073512 (52.5 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.137.0.17 netmask 255.255.255.255 broadcast 10.255.255.255 inet6 fe80::216:3eff:fe5e:6c00 prefixlen 64 scopeid 0x20<link> ether 00:16:3e:5e:6c:00 txqueuelen 1000 (Ethernet) RX packets 555370 bytes 785064402 (748.6 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 208464 bytes 13235820 (12.6 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 107 bytes 227427 (222.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 107 bytes 227427 (222.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 veth0271483: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::183d:fdff:fe2b:f8ce prefixlen 64 scopeid 0x20<link> ether 1a:3d:fd:2b:f8:ce txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 16 bytes 1379 (1.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 veth25193ce: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::603c:beff:fe87:6283 prefixlen 64 scopeid 0x20<link> ether 62:3c:be:87:62:83 txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 16 bytes 1379 (1.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 vetha36c6d7: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::789d:60ff:fe15:8eb4 prefixlen 64 scopeid 0x20<link> ether 7a:9d:60:15:8e:b4 txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 16 bytes 1379 (1.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 vethc039300: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::a0a9:4eff:fe3d:8338 prefixlen 64 scopeid 0x20<link> ether a2:a9:4e:3d:83:38 txqueuelen 0 (Ethernet) RX packets 5 bytes 513 (513.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 11 bytes 866 (866.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 vethe777af4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::c07e:11ff:fe1a:9f6b prefixlen 64 scopeid 0x20<link> ether c2:7e:11:1a:9f:6b txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 16 bytes 1379 (1.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 输出在Docker容器上

ifconfig

我的主机上的 eth0 Link encap:Ethernet HWaddr 02:42:AC:12:00:05 inet addr:172.18.0.5 Bcast:172.18.255.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:14 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1260 (1.2 KiB) TX bytes:0 (0.0 B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

netstat -ltn

我来自Docker容器的 Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:10137 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:6942 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:5902 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:63342 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:20080 0.0.0.0:* LISTEN tcp6 0 0 ::1:631 :::* LISTEN tcp6 0 0 :::9000 :::* LISTEN tcp6 0 0 :::3306 :::* LISTEN tcp6 0 0 :::80 :::* LISTEN tcp6 0 0 :::81 :::* LISTEN tcp6 0 0 :::8082 :::* LISTEN

netstat -ltn

使用Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.11:34183 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:9001 0.0.0.0:* LISTEN 时我会得到

xdebug.remote_connect_back=1

另外,当我在docker容器中运行I: Checking remote connect back address. I: Checking header 'HTTP_X_FORWARDED_FOR'. I: Checking header 'REMOTE_ADDR'. I: Remote address found, connecting to 172.18.0.1:5902. E: Time-out connecting to client (Waited: 200 ms). :-( Log closed at 2019-10-31 09:32:55 时,我得到172.18.0.1

因此,我得出的结论是netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}'

但是当我使用docker添加到容器的xdebug.remote_host = 172.18.0.1的IP(IP更改为172.17-18.0.1-4,现在是172.18.0.4)并查看我得到的Xdebug日志

/etc/hosts

因此,由于这些IP并不确定,因此我只是尝试以W: Creating socket for 'host.docker.internal:5902', poll success, but error: Operation in progress (29). E: Could not connect to client. :-( 的方式访问docker容器时遇到的每个IP。而且我还是来自xdebug的上述故障日志之一

另外xdebug.remot_hosttelnet的结果:

ping

结论:我迷路了。我基本上尝试了所有可能的IP地址。请帮助我理解调试PHP代码所需做的事情。谢谢!

2 个答案:

答案 0 :(得分:0)

TLDR:在您的Docker容器xdebug.remote_connect_back=0xdebug.remote_host=172.17.0.1中指定,它应该可以工作。切记:Xdebug需要从Web服务器(在Docker内部)连接到侦听端口9000的IDE。

您没有显示Docker的ifconfig,所以我可能得到了上面错误的IP地址。但是,重要的是,您在xdebug.remote_host中指定的IP地址是您的 IDE 监听的IP地址。而且该IP地址需要可从Docker访问。您可以通过在Docker容器中运行“ telnet IpAddress 9000”进行测试,以查看是否获得了正确的主机IP地址。

但还有其他几点:

在docker容器上,netstat显示:

tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      
tcp        0      0 0.0.0.0:9001            0.0.0.0:*               LISTEN 

您在那里运行DBGp代理吗?您不需要这样做。代理只会使情况变得更复杂。

我在您主机的netstat中看到了

tcp6       0      0 :::9000                 :::*                    LISTEN     

您是否正在使用仅侦听IPv6的IDE?您可能想看看是否可以更改它以与IPv4一起运行。

答案 1 :(得分:0)

如果您在本地计算机上并且具有docker容器,则足以设置xdebug.remote_host=host.docker.internal并将host.docker.internal添加到/ etc / hosts。

我在输入sh脚本中执行此操作:netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2" host.docker.internal"}' >> /etc/hosts

如何检查数据是否已发送:

  1. 您可以启用xdebug.remote_log=/var/log/xdebug_remote_log.log
  2. 我更喜欢监听主机nc -l 5902nc -l 0.0.0.0 5902上的端口。从docker telnet host.docker.internal 5902通过telnet发送文本并输入内容。您应该在主机上的nc中看到它

如果您的码头工人位于远程主机上,则必须允许ssh GatewayPorts yes侦听0.0.0.0:5904或将流量转发至127.0.0.0:5905。看here

  1. 在远程主机上运行一次:socat TCP-LISTEN:5904,fork TCP:127.0.0.1:5905
  2. 要获取有关本地计算机运行的响应:ssh -R 5905:localhost:5904

您可以使用nctelnet检查连接。