Docker Community Forums

Share and learn in the Docker community.

Xdebug on docker with PhpStorm doesn't work

docker

(Ksiamro) #1

Hello,

Im quite new in Docker.
I can’t connect xdebug on docker container to phpstorm ide.

My PhpStorm is v 8.0.3

I spend a lot of time for searching how to solve with negative result.
I’m pretty sure I tried everything I found and bit more solution.

My actual docker-compose snip:

ports:

  • “8081:8081”
  • “80:80”
  • "443:443"
    expose:
  • "9001"
    links:
  • magedb_m1
    environment:
    XDEBUG_CONFIG: "remote_host=172.17.0.1"
    PHP_IDE_CONFIG: "serverName=docker"
    XDEBUG_CONFIG: "idekey=PHPSTORM"
    PHP_XDEBUG_ENABLED: 1
    volumes:
  • ./project/:/var/www/html/

xdebug.ini:

[xdebug]

zend_extension=xdebug.so
xdebug.idkey = “PHPSTORM”

xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
; This is the default Docker gateway
xdebug.remote_host=172.17.0.1
xdebug.remote_port=9001
xdebug.remote_autostart=1
xdebug.remote_connect_back=0

Phpstorm PHP settings:
http://img.ctrlv.in/img/16/10/02/57f0d57039ac8.png

ip a from my local:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp4s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 14:dd:a9:0b:ee:74 brd ff:ff:ff:ff:ff:ff
inet 192.168.2.104/24 brd 192.168.2.255 scope global dynamic enp4s0f1
valid_lft 315356022sec preferred_lft 315356022sec
inet6 fe80::16dd:a9ff:fe0b:ee74/64 scope link
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 52:54:00:d5:ef:9c brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
link/ether 52:54:00:d5:ef:9c brd ff:ff:ff:ff:ff:ff
5: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 02:42:b4:ad:cc:ab brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:b4ff:fead:ccab/64 scope link
valid_lft forever preferred_lft forever
6: br-c2e824564ce6: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 02:42:44:61:39:53 brd ff:ff:ff:ff:ff:ff
inet 172.18.0.1/16 scope global br-c2e824564ce6
valid_lft forever preferred_lft forever
34: veth29f09f2@if33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP
link/ether da:96:0c:3e:78:bd brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::d896:cff:fe3e:78bd/64 scope link
valid_lft forever preferred_lft forever
36: vethddad676@if35: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP
link/ether 2e:26:7c:1b:7c:0b brd ff:ff:ff:ff:ff:ff link-netnsid 1
inet6 fe80::2c26:7cff:fe1b:7c0b/64 scope link
valid_lft forever preferred_lft forever

ip a from container with xdebug

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
35: eth0@if36: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.17.0.3/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:3/64 scope link
valid_lft forever preferred_lft forever

On container xdebug.ini exist in:
etc/php/5.6/mods-available/xdebug.ini

I tried different remote host address (172.17.0.3 / 172.17.0.2 / 172.17.41.1 / much more).
Different xdebug.ini options

Can You give me a tip how to solve it?

Regards,
Konrad


(Elmudo) #2

The problem is with Docker for Mac. All you need to do to get xdebug working is to use:
xdebug.remote_host=docker.for.mac.localhost
The issue is documented here:


My xdebug.ini is:

xdebug.remote_enable=1
xdebug.remote_connect_back=0
; remote_host:
;   You can use 172.17.0.1 if you don't use a Mac or when Docker/Apple fix the network problem.
xdebug.remote_host=docker.for.mac.localhost
; remote_port:
;   Yes, this can be the same port number as PHP-FPM uses to *listen* on - they are on different servers
xdebug.remote_port=9000
; idekey:
;   Anything you want. Just make sure the same value is sent from the browser or CLI.
xdebug.idekey=phpstorm
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so

Good luck,
Conor


(Cytopia) #3

For general info about configuring PHP and your IDE in a dockerized environment, have a look at this documentation: https://devilbox.readthedocs.io/en/latest/intermediate/configure-php-xdebug.html