【问题标题】:Laravel sail - How to debug in VSCode with windows docker desktopLaravelsai - 如何在 VSCode 中使用 windows docker 桌面进行调试
【发布时间】:2021-07-09 19:48:07
【问题描述】:

我对 Linux 和 Docker 很陌生。 Sail 为我管理一切真是太好了!但我想允许在 VSCode 中进行调试。 我已经添加到我的 windows laravel 文件夹 /docker/8.0/php.ini

[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host = host.docker.internal
xdebug.remote_port = 9001

我已经在我的 windows laravel 文件夹 /docker/8.0/Dockerfile 中添加了这个

ARG INSTALL_XDEBUG=true
RUN if [ ${INSTALL_XDEBUG} = true ]; then \
    # Install the xdebug extension
    pecl install xdebug && \
    docker-php-ext-enable xdebug \
    ;fi

# Copy xdebug configration for remote debugging
COPY .docker/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
EXPOSE 9001

我已经修改了我的 VScode launch.json :

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "pathMappings": {
                "/": "${workspaceRoot}/"
            },
            "port": 9001
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9001
        }
    ]
}

当我在 Ubuntu 中启动“起航”并在 VSCode 中启动调试器时,它不起作用:调试栏未激活(只有暂停、停止和重新启动按钮处于激活状态,所有其他按钮均未激活)

我该怎么办? 谢谢!

【问题讨论】:

  • 有什么帮助吗?谢谢

标签: php laravel docker visual-studio-code dockerfile


【解决方案1】:

在 php.ini 中添加:

xdebug.idekey="VSCODE"

在 Dockerfile 中添加:

RUN echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

(在我的情况下是 php 7.4 和 xdebug 2.9)在安装 xdebug 行之后。

改变

COPY .docker/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini

COPY .docker/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

最后在 VSCode 配置更改如下:vscode config

P/S:如果您使用 docker-compose,请不要忘记添加类似的内容,因为 docker linux 不会自动将 host.docker.internal 映射到您的主机 ip。

extra_hosts:
      - "host.docker.internal:host-gateway"

【讨论】:

    猜你喜欢
    • 2020-03-23
    • 1970-01-01
    • 2020-09-25
    • 1970-01-01
    • 1970-01-01
    • 2020-06-08
    • 2020-06-10
    • 2017-10-21
    • 1970-01-01
    相关资源
    最近更新 更多