Search code examples
phpdockerdebuggingphpstormxdebug

Xdebug - trigger debug in PhpStorm from inside a docker


I have been able to get my PHP scripts to trigger my listener in PhpStorm when opening a page from the browser. I just had to install Xdebug in the docker, and configure it with

xdebug.remote_connect_back = On
xdebug.remote_enable = On
xdebug.remote_autostart = Off

Now I wish to trigger it when calling a script from the PHP CLI inside the docker. I tried a few options like php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=1 -dxdebug.remote_connect_back=1 -dxdebug.idekey=PHPSTORM -dxdebug.remote_port=9000 myscript.php but without success. Am I missing something?


Solution

  • So, thanks to @LazyOne comment I got the answer. From inside the docker, the script doesn't know to what host debug session should be sent. I simply needed to find my PC ip from the docker's POV, and use it as host.

    Found it with ip addr and looked for docker0 entry, and then used it as host:

    export PHP_IDE_CONFIG="serverName=localhost"
    
    php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=1 -dxdebug.remote_connect_back=1 -dxdebug.idekey=PHPSTORM -dxdebug.remote_port=9000 -dxdebug.remote_host=172.17.0.4 myscript.php