Docker Community Forums

Share and learn in the Docker community.

IP address for xdebug

(Tomas Bartkus) #16

Try IP from here as xdebug.remote_host : cat /Users/<YOUR_USERNAME>/Library/Containers/com.docker.docker/Data/database/com.docker.driver.amd64-linux/slirp/host

(Attrox) #17

This works! Thank you.
I just modified
xdebug.remote_host=[IP ADDRESS FROM host mentioned above]

And everything works now. Thank you again, it took me days to get this working.

(Milkmedia) #18

I set the xdebug.remote_host and set PhpStorm to listen for connections but still not seeing anything. The new xdebug settings show up in a phpinfo page, so they are defiantly in effect.

(Raeesiqbal) #19

I have got it working with following configuration:

; xdebug options for HHVM/PHP
xdebug.remote_host="" ; My local network IP, which is accessiable inside the container
# NGINX config, set this where you have put other FastCGI configuration
fastcgi_param REMOTE_ADDR ""; #My local network IP

Make sure to restart the containers after these.

Now goto PHPStorm Preferences -> Languages and Frameworks -> PHP -> Debug:
In the Xdebug section, set Debug port to 9089 and Can accept external connections should be checked. Now, click on the phone icon in top right corner in PHPStorm that has caption of Start listening for PHP debug connections.
You may want to restart PHPStorm and should have XDebug Helper installed and its IDE Key set to PHPSTORM.

Happy debugging :slight_smile:

(Dimitar Dinchev) #20

+1. I’ve tried unsuccessfully to make it work with 1.12.0-rc3 using the internal container IP where connections come from - The solution using the local IP address works but is extremely annoying when working from several different places and changing IP.

(Pgosselin82) #21

That’s how I do it:

  • sudo ifconfig lo0 alias (create an alias for your mac loopback interface)
  • xdebug.remote_host= in your xdebug.ini
  • configure your ide as usual.

I’ve been using this through several beta versions, never had a problem. Beware of port 9000 conflicts.

(Ralphschindler) #22

A startup script to standardize on using

(Claudiu Creanga) #23

Are you using docker for mac or toolbox? Those settings work for me if I use toolbox, but don’t work on docker for mac.

(Achretien) #24

You can use as xdebug.remote_host in the xdebug.ini file

(Nonsenz) #25

still broken in 1.12.1-beta24 . setting a remote host works, but i think it is important to use remote connect back, so this will work on different environments like toolbox-mac, docker mac, linux …

(Ttorgeson) #26

I tried doing this… but then what IP/interface do you listen on inside the IDE? (In this case, PhpStorm)

(Toozick) #27

Man I have looked through so many Docker forum and StackOverflow posts but can’t seem to get it to work. Does somebody mind looking at our setup and finding the problem?

(Adam Biggs) #28

Try IP from here as xdebug.remote_host : cat /Users/<YOUR_USERNAME>/Library/Containers/com.docker.docker/Data/database/com.docker.driver.amd64-linux/slirp/host

This used to work for me using the Docker for Mac beta, but after updating to v1.12.1 stable, the mentioned file no longer exists…

Is there any way to get this IP without setting up a loopback IP? If not, there should be.

(Mickaelperrin) #29

I used to use the loopback alias. It works great but if you don’t have any network connection (no wifi), the connection between xdebug and the host can’t be established.

Has someone an idea on how to resolve this ? and ensure that the connection will work even if you work offline ?


(Vrann) #30

Instead of creating loopback workaround, you can also use ssh tunnel with this configuration:
xdebug.remote_connect_back = 0
Posted full solution here

(James Cowie) #31

After much pain I got this working with the following:

RUN apt-get update && apt-get upgrade -y && apt-get autoremove -y \
    && apt-get install -y git curl \
    && pecl install xdebug \
    && rm -rf /tmp/pear \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name\n"
       >> /usr/local/etc/php/conf.d/xdebug.ini


xdebug.idekey = PHPSTORM
xdebug.default_enable = 0
xdebug.remote_enable = 1
xdebug.remote_connect_back = 0
xdebug.profiler_enable = 1

sudo ifconfig en0 alias

I wrote up and recorded my workflow here: Debugging PHP apps

Hope this helps someone.

(Georald Camposano) #32

On a windows host, I got this to work by using the IPv4 address used by the vEthernet (DockerNAT) connection. Just check your network connections, view that specific connection’s details to get the ip address and plug that into your xdebug.remote_host. I also had to enable remote_autostart (for some reason, I could never get xdebug to trigger using GET/POST/cookies)

(Bmagrys) #33

Thank you for suggestion about DockerNAT address on Windows 10 host. Also, for me following configuration was enough:

(Jorge) #34

I wrote that for our company php image, it can be useful for someone:

(Enderandpeter) #36

Alright, I’d like to add my two cents to this excellent thread.

So, normally, you could set xdebug.remote_connect_back=on in order for Xdebug to connect to any client that makes a request to the server regardless of hostname/IP. When this is on, the xdebug.remote_host setting is ignored.

For whatever reason, Docker for Mac prevents Xdebug from allowing such unrestricted connections. One reason could be because when you enable xdebug.remote_connect it tries to connect to, which is the IP of the request according to the container, probably due to how Docker for Mac integrates the networking of the host and container. As a result, it thinks that the request is coming from the container rather than the host. I’m not totally sure if this is what’s happening, but it’s my best guess.

I, like pretty much everyone else here, could not get Xdebug to work with such a Docker for Mac container until I disabled xdebug.remote_connect_back.

It would appear that you can set xdebug.remote_host to any hostname/IP that your host computer is identified by, not the IP that the container uses to identify your host, which typically starts with 172. You can set an alias IP on your host if you want, but it would appear that you can likewise use an IP already assigned to the host on the local network. In fact, Docker has a brief Xdebug tutorial where they do this. I was confused by their instructions to use the host’s private IP because in other containers, like Vagrant and Docker via VirtualBox, you do have to set xdebug.remote_host to the IP that the container identifies the host with, which is typically the the gateway IP of the container, or the one seen in the access logs.

And so, my working Xdebug config on a Docker for Mac container is simply the following:

xdebug.remote_host= # My host's IP on en1
xdebug.remote_port=9001 # 9000 is already in use on my host and therefore unavailable for the container