Can't connect PhpStorm with xdebug with Docker

前端 未结 1 625
轻奢々
轻奢々 2020-12-12 05:56

I have the following Dockerfile:

 FROM php:7.0-fpm-alpine

RUN  apk add --update --virtual build_deps gcc g++ autoconf make &&\\
  docker-php-source          


        
相关标签:
1条回答
  • 2020-12-12 06:15

    In the end I had to do put the following over my Dockerfile:

    FROM php:7.0-fpm-alpine
    
    VOLUME /var/log/xdebug
    
    ARG XDEBUG_HOST="172.17.0.1"
    ARG XDEBUG_PORT=9021
    
    RUN  apk add --update --virtual build_deps gcc g++ autoconf make &&\
      docker-php-source extract &&\
      pecl install xdebug &&\
      docker-php-ext-enable xdebug &&\
      && echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
      && echo "xdebug.remote_autostart=0" >> /usr/local/etc/php/conf.d/xdebug.ini &&\
      echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/xdebug.ini &&\
      echo "xdebug.remote_handler = dbgp" >> /usr/local/etc/php/conf.d/xdebug.ini &&\
      echo "xdebug.remote_mode = req" >> /usr/local/etc/php/conf.d/xdebug.ini &&\
      echo "xdebug.remote_host=${XDEBUG_HOST}" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini &&\
      echo "xdebug.remote_port=${XDEBUG_PORT}" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini &&\
      docker-php-source delete && \
      apk del build_deps && \
      rm -rf /var/cache/apk/* && \
      rm -rf /tmp/*
    
    ENTRYPOINT ["php-fpm"]
    

    The XDEBUG_HOST build arg contains the ip of docker0 network interface over GNU/Linux systems (use ifconfig to find out).

    And over my docker-compose.yml I provide the following:

    version: '2'
    services:
      nginx_dev:
        image: nginx:alpine
        ports:
          - "5092:5092"
        links:
          - "my_symfony_www_dev"
        volumes:
          - './conf/nginx/nginx_dev.conf:/etc/nginx/nginx.conf:ro'
          - './logs/dev:/var/logs'
        volumes_from:
          - 'my_symfony_www_dev'
    
        my_symfony_www_dev:
          build:
            context: .
            dockerfile: Dockerfile_dev
            args:
              XDEBUG_HOST: 172.17.0.1
              XDEBUG_PORT: 9021
          image: "myimage/my_symfony_app:dev_php"  
          volumes:
            - "$SOURCE_PATH:/var/www/html:Z"
    

    Over the ./conf/nginx/nginx_dev.conf mapped over the volume I put the following setting on server section:

    server_name 0.0.0.0;
    

    Then on phpstorm use the following settings:

    Then you are good to go!

    0 讨论(0)
提交回复
热议问题