Docker和XDebug没有读取断点VSCode

时间:2017-04-12 04:25:12

标签: php debugging docker xdebug

在过去的6个月里,我一直在使用XDebug和PHP版本7.0。*在MAC上使用远程调试到Docker容器。

我正在运行一个旧版本的docker,它使用VirtualBox到VM for docker,一切正常。

我最近将docker更新到17.03.1版本,除了xDebug之外什么都没有。我通过他的存储库上的一个问题联系了vscode-php-debug的创建者,然后他指出我用xdebug和/或docker来解决这个问题。

我的问题如下:

XDebug正在运行并处理我的容器,xdebug日志显示它连接到我的IDE,但它只是关闭连接,就像我在VSCode中设置了断点时没有断点一样。

我在vscode-php-debug上发布的问题可以找到here

其中包含我的xDebug日志和VSCode调试日志的副本...它显示已建立连接但未命中断点。

我已经阅读了一些博客,其中docker现在需要为xdebug的连接创建一个环回ip才能正常工作,我也尝试过它。

我发现在长时间使用调试器后没有调试器就很难调试。

我尝试了许多配置,重新安装,重新启动,重建图像/容器,甚至尝试了freenode上的docker和xdebug irc通道,但没有成功。

2 个答案:

答案 0 :(得分:3)

EDIT-2 2018

现在可以更改remote_host值以支持所有平台:

xdebug.remote_host = "host.docker.internal"

EDIT-1 2018 它不再需要使用plist修复。正如本文所述:https://gist.github.com/chadrien/c90927ec2d160ffea9c4#gistcomment-2398281您现在可以使用docker for mac internal IP。

[xdebug]
xdebug.remote_host = "docker.for.mac.host.internal"
xdebug.default_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 0
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_port = 9000
xdebug.idekey="PHPSTORM"

OLD CONFIG

由于您在Mac上使用docker我发布了解决方案的工作方式。大多数学分转到this post on the docker forum

假设您的xdebug安装正确,这是php.ini中的配置。

[xdebug]
xdebug.remote_host=10.254.254.254
xdebug.remote_autostart=1
xdebug.idekey = PHPSTORM
xdebug.default_enable = 0
xdebug.remote_enable = 1
xdebug.remote_connect_back = 0
xdebug.profiler_enable = 1

您可以在终端中执行此命令来测试您的配置。 sudo ifconfig en0 alias 10.254.254.254 255.255.255.0

如果这样做,您可以将其转换为plist文件并将其放在以下位置。 /Library/LaunchDaemons/com.docker.xdebugFix.plist。您将在下面找到我的plist文件版本。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.docker.xdebugFix</string>
    <key>ProgramArguments</key>
    <array>
        <string>ifconfig</string>
        <string>en0</string>
        <string>alias</string>
        <string>10.254.254.254</string>
        <string>255.255.255.0</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

注意:plist仅在重启Mac后才能工作。

PHPSTORM配置(2018年编辑后也需要)

之后我用这样的调试服务器设置我的PHP风暴: php storm config 1

php storm config 2

之后我的断点在哪里工作,如果你正在使用chrome,你也需要使用xdebug扩展,但我很确定你知道这一点,因为你过去曾经使用它。 / p>

答案 1 :(得分:0)

检查你的 docker-compose.yml

我有一个环境变量:

XDEBUG_CONFIG: remote_host=${LAN_IP}

需要改为:

XDEBUG_CONFIG: client_host=${LAN_IP}

其中 LAN_IP 定义为 .env 文件中的本地 LAN IP

相关问题