docker - XDEBUG 无法正常工作,但已安装并且日志显示“连接到客户端 :-)”
问题描述
xDebug 已安装,日志已启用,验证正常,日志告诉我 xdebug 可以连接到客户端;但是 - 没有连接到 IDE
- 在 Docker 中使用 PHP7 安装 xDebug
- 在环境中添加了相应的ini文件
- 设置断点
- 在 CLI 和 FPM 中验证 xDebug
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
我究竟做错了什么?
解决方案
这一行显示了问题
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
推荐阅读
- wordpress - :nth-of-type(3n) 在第 21 个项目后停止工作
- vue.js - 为什么我的 v-for 中的索引生成字符串而不是 0、1、2 等?
- math - 为什么将相机分辨率减半会使现实世界中的物体缩小 1.5 倍
- python - 计算按其他列的唯一值分组的唯一值百分比
- c - 如何将目录名称正确存储到链表中?
- ag-grid - 如何在 ag-grid 中检索所选列的 ID?
- javascript - 除非我将其存储到新变量中,否则 join('') 不起作用
- python - Python中的子列表提取
- python - 如何解决google colab中“没有名为'tools'的模块”?
- android - 无法从 url 链接检索图像