4

I've read some posts about this but none helped in my case or simply overlooked the missing piece.

I cannot get xdebug to work on PhpStorm using a Docker container.

Docker-compose.yml

version: '2'

services:
  web:
    image: nginx:latest
    volumes:
    - .:/usr/share/nginx/html
    - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    - ./nginx/logs:/var/logs/nginx
    - ./nginx/site-enabled/default.conf:/etc/nginx/sites-enabled/default.conf
    ports:
    - "80:80"
    depends_on:
    - php

  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: 1234
      MYSQL_DATABASE: local_db
      MYSQL_USER: root
      MYSQL_PASSWORD: 1234
    ports:
    - "3306:3306"

  php:
    build: images/php
    volumes:
    - .:/usr/share/nginx/html
    - ./config/docker/php/php.ini:/usr/local/etc/php/php.ini
    - ./config/docker/php/ext-xdebug.ini:/usr/local/etc/php/conf.d/ext-xdebug.ini
    - ./config/docker/php/php-fpm.conf:/usr/local/etc/php-fpm.conf
    user: www-data
    depends_on:
    - db

config/docker/php/ext-xdebug.ini

zend_extension="/usr/lib/php7/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.overload_var_dump=1
xdebug.default_enable=1
xdebug.remote_autostart=1
xdebug.idekey=PHPSTORM
xdebug.remote_connect_back=1
xdebug.remote_host=172.20.0.1 # ip of host inside docker container
xdebug.remote_log=/usr/share/nginx/html/xdebug.log

error from xdebug.log

Log opened at 2017-05-31 11:01:14
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
I: Remote address found, connecting to 172.20.0.1:9000.
W: Creating socket for '172.20.0.1:9000', poll success, but error: Operation now in progress (29).
E: Could not connect to client. :-(
Log closed at 2017-05-31 11:01:14

In PhpStorm I'm using remote debugger with following settings:

server

Host - 127.0.0.1  
Port - 80 

Absolute path on server

/usr/share/nginx/html

IDE session key

PHPSTORM
2
  • kill phpstorm, and check on your host if port 9000 is used by another process. If it is, you may need to change the xdebug port in both the php settings, and in your phpstorm. Commented May 31, 2017 at 11:18
  • there is no process which uses this port, except phpstorm when started Commented May 31, 2017 at 11:57

2 Answers 2

3

Ok I got the solution in here

https://forums.docker.com/t/ip-address-for-xdebug/10460/9

I had to set my internal ip to xdebug.remote_host and disable xdebug.remote_connect_back=0

Seems this is a osx thing. Hope this helps someone here

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

3 Comments

How do I find the internal ip? Thx
In windows, to get the internal IP, type ipconfig in cmd and check the DockerNat IP
I had the similar problem on Windows 10 and this was also the solution
3

I've found that the following config on ext-xdebug.ini works for Docker for Mac

xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal

Docker automatically defines host.docker.internal within containers. So we simply point xdebug to think host.docker.internal is the IP of host machine (which obviously is). This way, we don't have to rely on ever changing internal IP between docker container and host.

More information can be found here https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds

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.