Debugging with XDebug, PHPStorm and Docker

To use the full features of debugging tools, you can enable Xdebug in the php containers.

Since the application runs in Docker containers and the debugging tools on the host and Docker isolates the stacks by default, you need a special network setup.


Allow traffic from Docker private IPs in firewall, eg.

sudo ufw allow from proto tcp to any

Create a network which is reserved for debug data.

docker network create --subnet xdebug

To output of the command will be the full ID of the newly created network.

To obtain the ID used for the corresponding bridge device run

docker network ls | grep xdebug

Accept connections for this interface on your host

sudo iptables -A INPUT -i br-<NETWORK_ID_SHORT> -j ACCEPT

It is not recommended to run this operation against the default network of the stack, since this might interfere with other networking operations.

To attach the php container to this network, define it in the docker-composer.override.yml file and attach it to the service.

      name: xdebug

      - default
      - xdebug

To enable Xdebug in the container and to set configuration values for debugging add the following environment variables to the php service

      - PHP_IDE_CONFIG=serverName=phd5
      - XDEBUG_CONFIG=remote_connect_back=0 remote_enable=1 remote_host= profiler_enable_trigger=1

You can now active listening for debug connections in PHPstorm. Restart your application and check if you are able to connect from your container

make bash
$ curl -v

If everything is set up correctly you should see a line like Connected to ( port 9000 (#0) in the output.

For PHPstorm you need to setup path mappings.

If you have issues with Xdebug on the CLI during setup, stop listening for debug connections in PHPStorm and restart when the web-server is fully up and running.


Help us to improve the documentation, fork this page.