Xdebug 忽略在 docker-compose.yml 中设置的 XDEBUG_CONFIG

Xdebug ignoring XDEBUG_CONFIG set in docker-compose.yml

我有一个 docker-compose 文件,其中配置了 XDEBUG_CONFIG 环境变量,但 Xdebug 忽略了它。当我输出 xdebug_info(); 时,它说 xdebug.idekey“没有价值”。 XDEBUG_MODE 不过读取正确。

如果我在我的 .ini 文件中设置 idekey,它就可以工作。

PHP 7.4
Xdebug 3.1.2

services:
    app:
        build:
            context: ./docker
            args:
                WWWUSER: ${WWWUSER:-1000}
                WWWGROUP: ${WWWGROUP:-1000}
        environment:
            PHP_IDE_CONFIG: "serverName=${PHP_IDE_CONFIG:-localhost}"
            XDEBUG_CONFIG: "idekey=VSCODE"
            XDEBUG_MODE: '${XDEBUG_MODE:-debug,develop}'
        volumes:
            - .:/var/www/html
            - ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
            - ./docker/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
            - ./docker/php/php.ini-development:/usr/local/etc/php/php.ini
        depends_on:
            - mysql
            - redis
            - nginx

这是我的完整 docker-compose.yml

version: '3.9'

services:
    app:
        build:
            context: ./docker
            args:
                WWWUSER: ${WWWUSER:-1000}
                WWWGROUP: ${WWWGROUP:-1000}
        environment:
            PHP_IDE_CONFIG: "serverName=${PHP_IDE_CONFIG:-localhost}"
            XDEBUG_CONFIG: "idekey=VSCODE"
            XDEBUG_MODE: '${XDEBUG_MODE:-debug,develop}'
        volumes:
            - .:/var/www/html
            - ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
            - ./docker/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
            - ./docker/php/php.ini-development:/usr/local/etc/php/php.ini
        depends_on:
            - mysql
            - redis
            - nginx

    mysql:
        image: mysql:8.0
        environment:
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
        volumes:
            - mysql-data:/var/lib/mysql
            - ./docker/mysql:/docker-entrypoint-initdb.d
        ports:
            - ${FORWARD_DB_PORT:-3306}:3306
        healthcheck:
            test: ["CMD", "mysqladmin", "ping"]

    redis:
        image: redis:alpine
        volumes:
            - redis-data:/data
        ports:
            - ${FORWARD_REDIS_PORT:-6379}:6379
        healthcheck:
            test: ["CMD", "redis-cli", "ping"]

    nginx:
        image: nginx:alpine
        volumes:
            - .:/var/www/html
            - ./docker/nginx/conf.d:/etc/nginx/conf.d
        ports:
            - ${NGINX_PORT:-80}:80

volumes:
    mysql-data:
        driver: local
    redis-data:
        driver: local

还有我的 Dockerfile

FROM php:7.4-fpm

# Install extensions
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && \
    install-php-extensions \
    gd \
    xdebug \
    memcached \
    imagick \
    @composer \
    pdo_mysql \
    exif \
    pcntl \
    zip

WORKDIR /var/www/html

# Install dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    libzip-dev \
    zip \
    unzip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    git \
    curl

RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - \
    && apt-get install -y nodejs \
    && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
    && echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
    && apt-get update \
    && apt-get install -y yarn

# Clean
RUN apt-get -y autoremove \
    && apt-get clean

ARG WWWUSER
ARG WWWGROUP

RUN groupadd --force -g $WWWGROUP theusergroup \
    && useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u $WWWUSER theuser

USER $WWWUSER:$WWWGROUP

# Expose port 9000 and start php-fpm server
EXPOSE 9000

CMD ["php-fpm"]

docker 部分看起来不错。我看到您正在使用带有 PHP-FPM 的 Xdebug,并且根据 Xdebug:

XDEBUG_MODE environment variable

Some web servers have a configuration option to prevent environment variables from being propagated to PHP and Xdebug.

For example, PHP-FPM has a clear_env configuration setting that is on by default, which you will need to turn off if you want to use XDEBUG_MODE.

您可能想要检查您的 PHP-FPM 配置。

哇,这真令人沮丧...

我用头撞墙了一段不合理的时间,结果不小心发现 IDE 键实际上已被设置。

但这是关键。

如果您查看此处,您会发现设置仍然显示 xdebug.idekey 值未设置。

不过,如果您看这里,您会看到另一个区域显示 IDE 密钥已设置。

/耸肩