猿问

在 VSCode 中使用 Docker 调试 PHP

看起来一切正常,但 VSCode 并没有停止调试。我有一个运行 PHP 映像的 docker 容器。

我需要做什么才能在断点处停下来?

我在日志中看不到错误,恰恰相反,他们似乎在说断点配置得很好,并且代码运行正确。

  • 容器的 IP为 172.22.0.2,我的主机的 IP为 172.22.0.1

  • 文件xdebugo.so存在于容器内: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so

  • 主机host.docker.internal已正确设置。

  • 我使用以下方法构建了我的图像:docker build -t phpdebug:5 .

  • 该文件/usr/local/etc/php/conf.d/xdebug.ini存在于正在运行的容器中。

http://img3.mukewang.com/634294010001e40b07950240.jpg

http://img2.mukewang.com/6342940b000120c409510398.jpg

启动.json


{

    "version": "0.2.0",

    "configurations": [

        {

            "name": "Listen for XDebug",

            "type": "php",

            "request": "launch",

            "port": 9000,

            "log": true,

            "externalConsole": false,

            "pathMappings": {

                "/": "${workspaceRoot}/"

            }

        }

    ]

}

码头工人-compose.yml


version: '2'


services:

  app:

    restart: 'no'

    image: phpdebug:5

    command: php -S 0.0.0.0:8000

    ports:

      - "8000:8000"

    volumes:

      - phpdata:/app

    environment:

      PHP_EXTENSION_XDEBUG: 1


volumes:

  phpdata:

    driver: local

    driver_opts:

      type: 'none'

      o: 'bind'

      device: '/home/element/php/tuto'

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


zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so"

xdebug.default_enable=1

xdebug.remote_enable=1

xdebug.remote_port=9000

xdebug.remote_handler=dbgp

xdebug.remote_connect_back=0

xdebug.remote_host=host.docker.internal

xdebug.idekey=VSCODE

xdebug.remote_autostart=1

xdebug.remote_log=/usr/local/etc/php/xdebug.log

/etc/hosts


127.0.0.1   localhost

::1 localhost ip6-localhost ip6-loopback

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

172.22.0.2  d484e93eed2a

172.22.0.1      host.docker.internal

Dockerfile:


FROM php


RUN pecl install xdebug


RUN ip -4 route list match 0/0 | awk '{print $3 "host.docker.internal"}' >> /etc/hosts


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


繁星coding
浏览 288回答 1
1回答

长风秋雁

日志显示在<init数据包中:file:///app/index.php所有断点的配置如下:file:///home/element/php/tuto/result.php这表明您所做的路径映射不正确:"pathMappings": {&nbsp; &nbsp; "/": "${workspaceRoot}/"}在您的情况下,我认为应该是以下内容,前提是这两个目录都有一个index.phpandresult.php文件。如果没有,您需要调整第二个路径,使其成为包含index.php和result.php文件的路径。"pathMappings": {&nbsp; &nbsp; "/app": "/home/element/php/tuto"}
随时随地看视频慕课网APP
我要回答