0

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 extract &&\
  pecl install xdebug &&\
  echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
  && 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 &&\
  docker-php-ext-enable xdebug &&\
  docker-php-source delete && \
  apk del build_deps && \
  rm -rf /var/cache/apk/* && \
  rm -rf /tmp/*

ENTRYPOINT ["php-fpm"]

And I run it with the following docker-compose.yml:

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
      image: "myimage/my_symfony_app:dev_php"  
      volumes:
        - "$SOURCE_PATH:/var/www/html:Z"
      environment:
        - PHP_IDE_CONFIG= "serverName=my_symfony_www_dev"
        - XDEBUG_CONFIG="remote_host=10.254.254.254,remote_port=9080"
        - PHP_XDEBUG_ENABLED=1

Also as seen there I run:

sudo ip addr add 10.254.254.254/24 brd + dev enp4s0 label enp4s0:1

And configured the PhpStorm IDE like that:

Remote Debugger PhpStorm settings

Server

Xdebug Config

DBGp Proxy config

Then in Firefox I press the enter image description here button and in PhpStorm I press the enter image description here button I set a breakpoint over the app_dev.php and nothing happens.

My system listens over the port 9080 via netstat -ntlp command where the PhpStorm listens to (PhpStorm is a server according to that answer).

tcp        0      0 0.0.0.0:9080            0.0.0.0:*               LISTEN      4773/java       

Do you have any idea on why that happens and how to fix it?

Edit 1:

The phpinfo() shows:

xdebug phpinfo

I've also set de cocker-compose.yml as:

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
      image: "myimage/my_symfony_app:dev_php"  
      volumes:
        - "$SOURCE_PATH:/var/www/html:Z"
      environment:
        - XDEBUG_CONFIG="remote_host=10.254.254.254,remote_port=9080"
        - PHP_XDEBUG_ENABLED=1

And my dockerfile is:

FROM php:7.0-fpm-alpine

RUN  apk add --update --virtual build_deps gcc g++ autoconf make &&\
  docker-php-source extract &&\
  pecl install xdebug &&\
  echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
  && 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=0" >> /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 &&\
  docker-php-ext-enable xdebug &&\
  docker-php-source delete && \
  apk del build_deps && \
  rm -rf /var/cache/apk/* && \
  rm -rf /tmp/*

ENTRYPOINT ["php-fpm"]

Still Same result.

6
  • 1) Collect phpinfo() output captured via browser (as you are trying to debug a web page) -- top header table + xdebug specific section. This is to confirm currently applied/active settings; 2) Enable and collect xdebug logs for such unsuccessful debug session; 3) You have xdebug.remote_connect_back=1 in your Dockerfile -- with this option xdebug ignores value of xdebug.remote_host. So far it must be wrong IP issue -- xdebug must be trying to connect but to the wrong IP (could be because of #3 for example) Commented Nov 14, 2017 at 12:17
  • 4) You have specified serverName=my_symfony_www_dev. In such case Host field in PHP | Servers should also be using it -- that's how PhpStorm identifies what Server entry to use. Commented Nov 14, 2017 at 12:20
  • I hope this answer might help you Commented Nov 14, 2017 at 12:49
  • 1) Do not silently update the post -- nobody gets notified about that. 2) Where is xdebug log? 3) Your screenshot of xdebug info shows that your XDEBUG_CONFIG from docker_compose file is not getting applied, at very least in a way you were expecting it to be (port and remote_host are still using defaults). Commented Nov 14, 2017 at 15:45
  • Instead of using a breakpoint inside phpstorm, you can also use this function in your code xdebug_break();. If this triggers the debug function in phpstorm, there is probably something wrong with your path mapping Commented Nov 15, 2017 at 13:27

1 Answer 1

2

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:

Setting Servers over phpstorm

XDEBUG settings over phpstorm

Then you are good to go!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.