简体   繁体   中英

Xdebug ignoring XDEBUG_CONFIG set in docker-compose.yml

I have a docker-compose file that has the XDEBUG_CONFIG environment variable configured, but Xdebug is ignoring it. When I output xdebug_info(); it says "no value" for xdebug.idekey. XDEBUG_MODE is being read correctly though.

If I set the idekey in my.ini file, it works.

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

Here's my full 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

And my 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"]

The docker part seems good. I see that you're using Xdebug with PHP-FPM and according to 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.

You might want to checkout your PHP-FPM config.

Wow, this is frustrating...

I banged my head against the wall for an unreasonable amount of time only to accidentally figure out that the IDE Key was in fact being set.

Here's the kicker though.

If you look here, you'll see that the setting still says the xdebug.idekey value is not set.

在此处输入图像描述

If you look here though, you'll see that there's another area that shows that the IDE Key is set.

在此处输入图像描述

/shrug

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM