gpt4 book ai didi

php - 如何在php:7.4-fpm-alpine docker容器中启用xdebug?

转载 作者:行者123 更新时间:2023-12-02 21:33:13 29 4
gpt4 key购买 nike

我的目标是将Laravel的git repo与php-fpm的xdebug一起使用:
https://github.com/aschmelyun/docker-compose-laravel
在使用此仓库时,我运行:

  • docker-compose up -d-构建站点
  • docker-撰写

  • 这是仓库上方的仓库文件:
    FROM php:7.4-fpm-alpine

    ADD ./php/www.conf /usr/local/etc/php-fpm.d/www.conf
    RUN addgroup -g 1000 laravel && adduser -G laravel -g laravel -s /bin/sh -D laravel
    RUN mkdir -p /var/www/html
    RUN chown laravel:laravel /var/www/html
    WORKDIR /var/www/html
    RUN docker-php-ext-install pdo pdo_mysql
    我还在这里添加了端口(compose.dockerfile):
    php:
    build:
    context: .
    dockerfile: php.dockerfile
    container_name: php
    volumes:
    - ./src:/var/www/html:delegated
    ports:
    - "9000:9000"
    # Added next line:
    - "9001:9001"
    networks:
    - laravel
    我尝试将其添加到php.dockerfile的末尾:
    # Install essential build tools
    RUN apk add --no-cache \
    git \
    yarn \
    autoconf \
    g++ \
    make \
    openssl-dev

    # Install xdebug
    RUN docker-php-source extract \
    && pecl install xdebug \
    && echo "xdebug.remote_enable=on\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_autostart=on\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_port=9001\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_handler=dbgp\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_connect_back=1\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && docker-php-ext-enable xdebug \
    && docker-php-source delete \
    && rm -rf /tmp/*
    这是我在添加上述行时遇到的错误(似乎无关,但我猜想它打破了某些依赖性):
    mysql       | Version: '5.7.29'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
    composer | list [--xml] [--raw] [--format FORMAT] [--] [<namespace>]
    composer |
    npm exited with code 1
    composer exited with code
    我尝试了其他在Google上找到的东西。但是无法使其正常工作(因为我真的不明白自己的工作)。我认为以上感觉就像是我关闭了,但也许我完全错了。
    我在Windows 10上运行它,需要更多信息吗?

    最佳答案

    我找到了有关如何设置的说明here。将其添加到php.dockerfile的末尾:

    # Install base packages
    RUN apk update
    RUN apk upgrade

    # xdebug with VSCODE
    ENV XDEBUG_VERSION=2.9.2
    RUN apk --no-cache add --virtual .build-deps \
    g++ \
    autoconf \
    make && \
    pecl install xdebug-${XDEBUG_VERSION} && \
    docker-php-ext-enable xdebug && \
    apk del .build-deps && \
    rm -r /tmp/pear/* && \
    echo -e "xdebug.remote_enable=1\n\
    xdebug.remote_autostart=1\n\
    xdebug.remote_connect_back=0\n\
    xdebug.remote_port=9001\n\
    xdebug.idekey=\"VSCODE\"\n\
    xdebug.remote_log=/var/www/html/xdebug.log\n\
    xdebug.remote_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini


    # Change TimeZone
    RUN apk add --update tzdata
    ENV TZ=Europe/Bucharest
    编辑:
    您还应该在 docker-compose.yml 中删除 xdebug端口(如果已添加)
    For **Visual Studio Code** Here is the kaunch.json I used:
    {
    // 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": 9001,
    "pathMappings": {
    "/var/www/html/public": "${workspaceFolder}/src/public"
    },
    }
    ]
    }

    关于php - 如何在php:7.4-fpm-alpine docker容器中启用xdebug?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63982010/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com