首页 > 解决方案 > XDEBUG 无法正常工作,但已安装并且日志显示“连接到客户端 :-)”

问题描述

xDebug 已安装,日志已启用,验证正常,日志告诉我 xdebug 可以连接到客户端;但是 - 没有连接到 IDE

20-xdebug.ini:

xdebug.idekey=PHPSTORM
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.remote_host=172.55.0.20
xdebug.remote_port=9000
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=0
xdebug.profiler_enable_trigger_value=PHPSTORM
xdebug.profiler_output_dir=/var/www/html/htdocs/var
xdebug.trace_enable_trigger=1
xdebug.trace_enable_trigger_value=PHPSTORM
xdebug.trace_output_dir=/var/www/html/htdocs/var
xdebug.remote_log=/var/www/html/htdocs/var/log/xdebug.log
zend_extension=/usr/lib/php/20151012/xdebug.so

我已经安装了带有 PHP7 FPM 模块和 xDebug 的 Docker。我已经安装了它pecl install xdebug

xdebug 正在 FPM 和 CLI 中加载,我已将相应的文件正确放置在 fpm 和 cli 文件夹中。我可以验证它是否加载。

我已经启用了日志并且里面有这个块:

Log opened at 2019-02-08 08:12:24
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Remote address found, connecting to 127.0.0.1:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/htdocs/index.php" language="PHP" xdebug:language_version="7.0.24-1+ubuntu16.04.1+deb.sury.org+1" protocol_version="1.0" appid="16" idekey="PHPSTORM"><engine version="2.6.1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2018 by Derick Rethans]]></copyright></init>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

Log closed at 2019-02-08 08:12:24

所以,logs告诉我有一个成功的连接。

在 PHPStorm 中,我设置了 DBGp:IDE 密钥:PHPSTORM 主机:172.55.0.1 端口:9000

我究竟做错了什么?

标签: dockerxdebug

解决方案


这一行显示了问题

I: Remote address found, connecting to 127.0.0.1:9000.

它试图远程连接回127.0.0.1容器内的哪个容器本身,而不是您的机器主机。当重新连接打开时,远程主机被忽略:

如果启用了 xdebug.remote_connect_back,则忽略此设置。

https://xdebug.org/docs/all_settings#remote_host

remote_connect_back您应该明确禁用并指定远程主机:

xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal

推荐阅读