简体   繁体   English

Xdebug - 从 docker 内部触发 PhpStorm 中的调试

[英]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.从浏览器打开页面时,我已经能够让我的 PHP 脚本触发我在 PhpStorm 中的侦听器。 I just had to install Xdebug in the docker, and configure it with我只需要在 docker 中安装 Xdebug,并使用

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.现在我希望在从 docker 内的 PHP CLI 调用脚本时触发它。 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.我尝试了一些选项,例如php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=1 -dxdebug.remote_connect_back=1 -dxdebug.idekey=PHPSTORM -dxdebug.remote_port=9000 myscript.php但没有成功。 Am I missing something?我错过了什么吗?

So, thanks to @LazyOne comment I got the answer.所以,感谢@LazyOne 的评论,我得到了答案。 From inside the docker, the script doesn't know to what host debug session should be sent.从 docker 内部,脚本不知道应该向哪个主机调试 session 发送。 I simply needed to find my PC ip from the docker's POV, and use it as host.我只需要从 docker 的 POV 中找到我的 PC ip,并将其用作主机。

Found it with ip addr and looked for docker0 entry, and then used it as host:使用ip addr找到它并查找docker0条目,然后将其用作主机:

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

The Dockerfile needs to have EXPOSE 9000 (opens port :9000 ) Dockerfile需要EXPOSE 9000 (打开端口:9000

... else you won't be able to connect xdebug from the outside world. ...否则您将无法从外部连接xdebug

Putting the IDE into the container is questionable.将 IDE 放入容器是有问题的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM