2

I'm setting up a Docker development environment for my team. In this environment we want to integrate Xdebug with Docker to allow for debugging. It seems the easiest way to do this is to connect Sublime Text to the Docker instance and then install Xdebug ontop on Sublime Text. I found the following guide for integrating Sublime Text with Docker (http://domeide.github.io/) and this guide for integrating Xdebug with Sublime Text (https://www.sitepoint.com/debugging-xdebug-sublime-text-3/). What I am wondering is if anyone has any experience setting up similar environments? Is there an easier way to do this? Does this seem like the correct way to debug PHP code inside Docker?

1
  • I have discovered that the best way to set up this development environment is to use a Docker shared volume. Any text editor will be viable to use when a shared volume is setup between the container and the host.
    – user2417339
    Jul 13, 2016 at 14:17

2 Answers 2

1

This solution may also work for Sublime Text - For Visual Studio Code, I have just recently got this working. I found these remote_host and other Xdebug settings work for me on both Windows 10 Pro and OS X using the latest versions of Docker Community Edition.

In the Xdebug extension configuration, I set these along with the Xdebug extension installation in the Dockerfile of the image package from docker hub that contains php. There is a link to a post at the bottom of this answer on how this was done in the Dockerfile and how the image was built and then added to the docker-compose file.

  1. The xdebug.remote_connect_back setting needs to be off: xdebug.remote_connect_back=0
  2. Autostart xdebug.remote_autostart=1 it just works.
  3. xdebug.remote_host=127.0.0.1 needs to be changed depending on Windows or OS X as follows:

Windows 10 Professional running Docker Version 17.03.0-ce-win1, open a command prompt and enter ipconfig. The address is listed under DockerNAT. For example:

ipconfig

Ethernet adapter vEthernet (DockerNAT):

    IPv4 Address. . . . . . . . . . . : 10.0.75.1

OS X El Capitan running Docker Version 17.03.0-ce-mac2, create an alias of IP 10.254.254.254 to your existing subnet mask.

sudo ifconfig en0 alias 10.254.254.254 255.255.255.0

Then use the IP for the xdebug.remote_host setting for your host as follows based on the examples above:

  1. Windows 10.0.75.1
  2. OS X: 10.254.254.254

Note, if you run into a conflict in OS X, you can remove the alias like so.

sudo ifconfig en0 -alias 10.254.254.254

I use Visual Studio Code with the vscode-php-debug PHP Debug Adapter to Listen for Xdebug and step through my code. Note the following needs to be included in the project launch.json file in order for VS Code to map the remote server files to the local machine. This is from my project and its typical volume locations, your serverSourceRoot looks to be the same.

"serverSourceRoot": "/var/www/html",
"localSourceRoot": "${workspaceRoot}"

The entire setup for docker-compose, nginx-proxy including how to build the image with Xdebug and more at Docker WordPress Dev Environment - Remote Debugging with Xdebug and VS Code

2
  • I found this surprisingly difficult - because you have to get the local IP into the working container that you are debugging. I find it very distasteful that I have to manually edit my settings depending on the BOX I am working on. Have you improved your solution at this point?
    – ktamlyn
    Dec 13, 2017 at 12:49
  • 1
    @ktamlyn, It is a little easier to manage when passing the remote_host IP as an env variable, docker-compose can also make things a bit easier to manage, where you can comment/uncomment settings depending on the environment. Dec 13, 2017 at 23:29
0

To me, if I not put this:

XDEBUG_START_WITH_REQUEST=yes

the Xdebug under WSL not work.

Your Answer

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