首页 > 解决方案 > Xdebug 不适用于 VSCode 编辑器的 Docker 设置

问题描述

我在 Docket 设置中设置 Xdebug。我正在使用 VSCode 编辑器。

我的 VSCode 源代码树如下所示:
在此处输入图像描述

我的 Docker 文件如下所示:

FROM php:7.3-fpm

WORKDIR /var/www/html

RUN docker-php-ext-install mysqli pdo pdo_mysql && docker-php-ext-enable mysqli

RUN apt-get update && apt-get install -y iputils-ping && apt-get install -y vim 

RUN pecl install xdebug

RUN echo 'zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so' | tee /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_enable=1" | tee -a /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_port=9000" | tee -a /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_autostart=1" | tee -a /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_connect_back=0" | tee -a /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.idekey=VSCODE" | tee -a /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_host=host.docker.internal" | tee -a /usr/local/etc/php/conf.d/xdebug.ini

RUN docker-php-ext-enable xdebug

我的撰写文件如下所示:

 php:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: php
    volumes:
      - ./src:/var/www/html
    ports:
      - "9002:9000"
    networks:
      - laravelAdmin
    environment:
      PHP_EXTENSION_XDEBUG: 1

我的 launch.json 文件如下所示:

    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "pathMappings": {
                "/var/www/html": "${workspaceRoot}",
                // "/var/www/html": "${workspaceRoot}/html",
                // "/var/www/html": "${workspaceRoot}/www",
                // "/src": "${workspaceRoot}/src"
                // "/src": "${workspaceRoot}"
            },
            "ignore": [
                "**/vendor/**/*.php"
            ],
            "log": true,
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000
        }
    ]
}

在调试时,断点不起作用。

虽然如果我从 launch.json 中删除“忽略”部分,那么它会显示供应商文件夹中的错误,但它不会破坏我的代码。

你能帮我在这里找到问题吗?

xdebug 日志说。

   [14] Log opened at 2020-09-15 04:37:54
[14] I: Connecting to configured address/port: host.docker.internal:9000.
[14] I: Connected to client. :-)
[14] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="dbgp://stdin" language="PHP" xdebug:language_version="7.3.20" protocol_version="1.0" appid="14" idekey="VSCODE"><engine version="2.9.6"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2020 by Derick Rethans]]></copyright></init>

[14] <- breakpoint_list -i 1
[14] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="1"></response>

[14] <- breakpoint_set -i 2 -t line -f file:///var/www/html/src/app/Http/Controllers/CreateUsers.php -n 16
[14] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id="140001"></response>

[14] <- breakpoint_set -i 3 -t line -f file:///var/www/html/src/app/Http/Controllers/CreateUsers.php -n 27
[14] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="3" id="140002"></response>

[14] <- breakpoint_list -i 4
[14] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="4"><breakpoint type="line" filename="file:///var/www/html/src/app/Http/Controllers/CreateUsers.php" lineno="16" state="enabled" hit_count="0" hit_value="0" id="140001"></breakpoint><breakpoint type="line" filename="file:///var/www/html/src/app/Http/Controllers/CreateUsers.php" lineno="27" state="enabled" hit_count="0" hit_value="0" id="140002"></breakpoint></response>

[14] <- breakpoint_list -i 5
[14] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="5"><breakpoint type="line" filename="file:///var/www/html/src/app/Http/Controllers/CreateUsers.php" lineno="16" state="enabled" hit_count="0" hit_value="0" id="140001"></breakpoint><breakpoint type="line" filename="file:///var/www/html/src/app/Http/Controllers/CreateUsers.php" lineno="27" state="enabled" hit_count="0" hit_value="0" id="140002"></breakpoint></response>

[14] <- breakpoint_set -i 6 -t exception -x *
[14] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="6" id="140003"></response>

[14] <- run -i 7
[14] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="7" status="stopping" reason="ok"></response>

[14] <- stop -i 8
[14] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="8" status="stopped" reason="ok"></response>

[14] Log closed at 2020-09-15 04:37:5

4

标签: dockervisual-studio-codexdebug

解决方案


推荐阅读