PhpStorm在尝试运行调试会话时插入了错误的client_host IP。

huangapple go评论63阅读模式
英文:

PhpStorm inserts wrong client_host IP when trying to run debug session

问题

PHP解释器运行在Docker容器中,Xdebug配置如下:

zend_extension=xdebug.so

[xdebug]
xdebug.mode=debug
xdebug.idekey=Docker
xdebug.discover_client_host=on
xdebug.client_host=host.docker.internal
xdebug.client_port=9011
xdebug.cli_color=1

当我在测试中运行调试会话时,PhpStorm运行以下执行字符串:

[docker-compose://[/home/Projects/service/docker-compose.yaml]:php/]:php -dxdebug.mode=debug -dxdebug.client_port=9011 -dxdebug.client_host=172.24.0.83 ...

请注意-dxdebug.client_host=172.24.0.83部分... 但host.docker.internal有另一个IP:

$ docker-compose exec php ping host.docker.internal
PING host.docker.internal (172.17.0.1): 56 data bytes
64 bytes from 172.17.0.1: seq=0 ttl=64 time=0.053 ms

当然,它无法启动调试会话。我在项目中和PhpStorm设置中没有找到任何关于这个奇怪的IP 172.24.0.83 的出现。我该如何摆脱PhpStorm中这显然无效的条件?

英文:

PHP interpreter runs in docker container, Xdebug configuration is

zend_extension=xdebug.so

[xdebug]
xdebug.mode=debug
xdebug.idekey=Docker
xdebug.discover_client_host=on
xdebug.client_host=host.docker.internal
xdebug.client_port=9011
xdebug.cli_color=1

When I run debugging session in tests, PhpStorm runs the execution string starting with

[docker-compose://[/home/Projects/service/docker-compose.yaml]:php/]:php -dxdebug.mode=debug -dxdebug.client_port=9011 -dxdebug.client_host=172.24.0.83 ...

Notice -dxdebug.client_host=172.24.0.83 part... But host.docker.internal has another IP:

$ docker-compose exec php ping host.docker.internal
PING host.docker.internal (172.17.0.1): 56 data bytes
64 bytes from 172.17.0.1: seq=0 ttl=64 time=0.053 ms

And of course it failed to start debug session. I didn't find any occurrence of this strange IP 172.24.0.83 anywhere in the project nor in the PhpStorm setting. How can I get rid of this obviously non-working condition in PhpStorm?

答案1

得分: 1

问题解决了。有一些步骤可以解决像我这样的情况。

如@LazyOne所述,您可以在“设置/首选项 | PHP | 调试”中的“设置”部分中取消选中“通过命令行传递所需的配置选项(仍然需要手动启用调试扩展)”复选框,从而禁用自动传递Xdebug CLI配置选项。

如@Derick所述,最好使用您机器的实际IP地址(类似于192.168.1.200)作为“xdebug.client_host”。这也适用于非root的docker。

英文:

Problem solved. There is some steps to fix xdebug in cases like mine.

As @LazyOne mentioned, you can disable automatic passing of Xdebug CLI configuration option in Settings/Preferences | PHP | Debug in a Settings section by unchecking Pass required configuration options through command line (still need to enable debug extension manually) checkbox.

As @Derick mentioned, it is better to use your actual IP address of the machine (smth like 192.168.1.200) for xdebug.client_host. That is working for rootless docker also.

huangapple
  • 本文由 发表于 2023年7月20日 19:44:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76729511.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定