我想尝试Xdebug 3.0.0RC1,探索其中的变化和新功能。我还使用最新的PhpStorm 2020.3 EAP,它支持Xdebug 3而无需进行任何重要配置。下面是我的PhpStorm调试器配置:
这是我尝试的Xdebug3配置:
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal # here I tried several combinations like: "localhost", "127.0.0.1", "172.17.0.1"
xdebug.client_port=9001 # here I tried several ports 9003 included with no success
我也尝试不添加client_host/client_port
设置,但仍然失败。
我收到了这个错误:
Script php bin/console doctrine:cache:clear-metadata returned with error code 255
!! [17-Nov-2020 15:24:40 UTC] Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9001 (through xdebug.client_host/xdebug.client_port) :-(
!! [17-Nov-2020 15:24:41 UTC] PHP Fatal error: Method class@anonymous::__toString() must not throw an exception, caught Symfony\Component\DependencyInjection\Exception\AutowiringFailedException: in /var/www/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php on line 233
关于我的环境的一些信息:
- Fedora 33
- Docker 版本为 19.03.13,构建版本为 4484c46d9d
- PhpStorm 2020.3 EAP 版本 #PS-203.5784.36
很奇怪(因为显然我使用的 Docker 版本不支持 host.docker.internal
,但它还是可以正常工作),而且以下配置即使调试器始终侦听传入连接,也可以在 Xdebug 2 中正常工作:
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
xdebug.remote_autostart=0
xdebug.remote_enable=1
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9000
我在这里缺少什么?
注意:我已经按照Xdebug开发人员在这里提供的解决方案进行了应用。
host.docker.internal
不支持 Linux 系统,仅支持 Windows 和 Mac 系统 -- https://github.com/docker/for-linux/issues/264 。自 Docker v20 版本开始将支持该主机名 -- https://github.com/docker/for-linux/issues/264#issuecomment-714253414 。如果您想使用该主机名,您需要动态检测 IP 地址(上述链接提供了许多实现方法)。 - LazyOnexdebug.remote_connect_back = 1
——Xdebug 2相当于Xdebug 3中的xdebug.discover_client_host = true
)。使用显式IP地址(硬编码)...或者动态检测它。 - LazyOneufw allow 9003
解决了这个问题,但最好还是按IP/设备进行锁定。 - Farkie