Docker + xdebug, zero thinking, screenshot only, 5 minutes guide.
In collaboration with Luciano.
Important For the time of writing, this is valid for Windows or MacOS only, because of host.docker.internal and this issue.
However, a workaround exists for Linux users. Add extra_hosts setting to the docker-compose.override.yml like this:
And execute the following command on the host machine:
export DOCKER_HOST_IP=$(ip route | grep docker0 | awk ‘{print $9}’)
This will make the hostname host.docker.internal resolvable to your host IP address. You can now restart the container and have the hostname resolvable to your host machine’s IP from inside the container.
Let’s continue with the configuration.
Just enable/disable the debugging via Chrome extension, and keep the debug configuration always ON in PHPStorm. That’s it!! It works! 🧨
Xdebugging CLI scripts
Debugging dockerized CLI script is also possible, and everything is in place already if you did the previous steps. Just pass the proper configuration values as options of PHP when you run the script, and you are done:
php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=1 -dxdebug.remote_host=”host.docker.internal” -dxdebug.idekey=IDEKEY -dxdebug.remote_port=9008 yourscript.php