简体   繁体   English

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

[英]Xdebug in docker container fails to connect to PhpStorm on Qubes OS

Xdebug within a Docker container does not connect to PhpStorm on my system. Docker 容器中的 Xdebug 未连接到我系统上的 PhpStorm。

I am trying to setup Xdebug with PhpStorm for a Docker environment on Linux (qubes-os / Fedora 30).我正在尝试使用 PhpStorm 为 Linux(qubes-os / Fedora 30)上的 Docker 环境设置 Xdebug。 Xdebug is enabled, and I can access error messages. Xdebug 已启用,我可以访问错误消息。 In PhpStorm I always updated DBGp Proxy setting with the respective IPs I gave Xdebug as remote host.在 PhpStorm 中,我总是使用我给 Xdebug 作为远程主机的相应 IP 更新 DBGp 代理设置。 I tried many versions of Xdebug setups but all failed.我尝试了许多版本的 Xdebug 设置,但都失败了。

My current best guess is that something with the internal IP management is messed up.我目前最好的猜测是内部 IP 管理的东西搞砸了。 This could be due to qubes-os , but I'm not really convinced since it's a normal Fedora and I have never had issues like that before...这可能是由于qubes-os造成的,但我不太相信,因为它是普通的 Fedora,而且我以前从未遇到过这样的问题......

My Xdebug conf我的Xdebug 配置

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

( I'm aware that host.docker.internal does not work for Linux. I'm using it anyway for easier debugging by setting an IP to this variable in the /etc/hosts file of the docker container) ( I'm aware that host.docker.internal does not work for Linux. I'm using it anyway for easier debugging by setting an IP to this variable in the /etc/hosts file of the docker container)

My phpinfo()我的phpinfo()

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

My web-log tells me, that my requests are coming from 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"我的网络日志告诉我,我的请求来自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"

my ifconfig output host machine我的ifconfig output主机

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

my ifconfig output on the docker container我在 docker 容器上的ifconfig output

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)

My netstat -ltn from my host machine的主机上的netstat -ltn

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    

My netstat -ltn from the docker container我的netstat -ltn来自 docker 容器

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    

When using xdebug.remote_connect_back=1 I get当使用xdebug.remote_connect_back=1我得到

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

Also when I run netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}'当我运行netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}' netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}' netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}' within the docker container I get 172.18.0.1 netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}'在 docker 容器中我得到 172.18.0.1

Thus I would conclude that xdebug.remote_host = 172.18.0.1因此我会得出结论xdebug.remote_host = 172.18.0.1

But when I use the IP added by docker to the container's /etc/hosts (the IP changes to 172.17-18.0.1-4, right now it's 172.18.0.4) and look into the Xdebug logs I get But when I use the IP added by docker to the container's /etc/hosts (the IP changes to 172.17-18.0.1-4, right now it's 172.18.0.4) and look into the Xdebug logs I get

W: Creating socket for 'host.docker.internal:5902', poll success, but error: Operation in progress (29).
E: Could not connect to client. :-(

So since these IPs were somewhat inconclusive, I simply tried every IP that I encountered on my way as my xdebug.remot_host for the docker container.因此,由于这些 IP 有点不确定,我只是尝试了我在途中遇到的每个 IP 作为 docker 容器的xdebug.remot_host And I either one of the above failure logs from xdebug我来自 xdebug 的上述失败日志之一

Additionally the results of telnet and ping :另外telnetping的结果:

telnet 172.18.0.1 5902:
telnet: can't connect to remote host (172.18.0.1): Operation timed out
bash-4.4# telnet 172.18.0.4
telnet: can't connect to remote host (172.18.0.4): Connection refused

bash-4.4# ping 172.18.0.1:
5 packets transmitted, 0 packets received, 100% packet loss

bash-4.4# ping 172.18.0.4
PING 172.18.0.4 (172.18.0.4): 56 data bytes
5 packets transmitted, 5 packets received, 0% packet loss

Conclusion : I'm lost.结论:我迷路了。 I basically tried every possible IP address.我基本上尝试了所有可能的 IP 地址。 Please help me understand what I need to do in order to debug my PHP code.请帮助我了解我需要做什么才能调试我的 PHP 代码。 Thanks!谢谢!

TLDR: Specify in your docker container xdebug.remote_connect_back=0 and xdebug.remote_host=172.17.0.1 and it should work. TLDR:在您的 docker 容器中指定xdebug.remote_connect_back=0xdebug.remote_host=172.17.0.1它应该可以工作。 Remember: Xdebug needs to connect from your webserver (inside Docker) to your IDE listening on port 9000.请记住:Xdebug 需要从您的网络服务器(在 Docker 内部)连接到您的 IDE 监听端口 9000。

You didn't show Docker's ifconfig, so I might have gotten the IP address above wrong.你没有显示 Docker 的 ifconfig,所以我可能把上面的 IP 地址弄错了。 But, the important thing is that the IP address you specify in xdebug.remote_host is the one where your IDE listens.但是,重要的是您在xdebug.remote_host中指定的 IP 地址是您的IDE监听的地址。 And that IP address needs to be reachable from Docker.并且需要从 Docker 访问 IP 地址。 You can test that by running "telnet IpAddress 9000" from within your Docker container, to see whether you got the right IP addess of your host.您可以通过在 Docker 容器中运行“telnet IpAddress 9000”来测试它,以查看您是否获得了主机的正确 IP 地址。

But some other points:但还有其他几点:

On your docker container, your netstat shows:在您的 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 

Do you have a DBGp Proxy running there?您在那里运行 DBGp 代理吗? You shouldn't need to do that.你不应该这样做。 The proxy only makes things more complicated for your situation.代理只会使您的情况变得更加复杂。

I see in your host's netstat:我在您主机的 netstat 中看到:

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

Are you using an IDE that only listens on IPv6?您是否使用仅侦听 IPv6 的 IDE? You might want to see if you can change that to run with IPv4.您可能想看看是否可以将其更改为使用 IPv4 运行。

If you are on a local machine and have a docker container there it's enough to set xdebug.remote_host=host.docker.internal and add host.docker.internal to /etc/hosts.如果您在本地计算机上并且有一个 docker 容器,那么设置xdebug.remote_host=host.docker.internal并将host.docker.internal添加到 /etc/hostsDA4 就足够了

I do this in the entry sh script: netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2" host.docker.internal"}' >> /etc/hosts我在条目 sh 脚本中执行此操作: netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2" host.docker.internal"}' >> /etc/hosts netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2" host.docker.internal"}' >> /etc/hosts

How to check that data is sent:如何检查数据是否已发送:

  1. you can enable xdebug.remote_log=/var/log/xdebug_remote_log.log您可以启用xdebug.remote_log=/var/log/xdebug_remote_log.log
  2. I prefer to listen to ports on a host nc -l 5902 or nc -l 0.0.0.0 5902 .我更喜欢收听主机nc -l 5902nc -l 0.0.0.0 5902上的端口。 Send text via telnet from docker telnet host.docker.internal 5902 and type something.从 docker telnet host.docker.internal 5902通过 telnet 发送文本并输入一些内容。 You should see it in nc on the host您应该在主机上的nc中看到它

If your docker is on a remote host then you have to allow ssh GatewayPorts yes to listen 0.0.0.0:5904 or forward traffic to 127.0.0.0:5905.如果您的 docker 在远程主机上,那么您必须允许 ssh GatewayPorts yes以侦听 0.0.0.0:5904 或将流量转发到 127.0.0.0:5905。 Look here这里

  1. on the remote host run once: socat TCP-LISTEN:5904,fork TCP:127.0.0.1:5905在远程主机上运行一次: socat TCP-LISTEN:5904,fork TCP:127.0.0.1:5905
  2. to get response on the local machine run: ssh -R 5905:localhost:5904在本地机器上获得响应运行: ssh -R 5905:localhost:5904

You can check the connection with nc and telnet .您可以检查与nctelnet的连接。

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

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