使用PhpStorm在docker中调试PHP cli应用程序

问题描述 投票:3回答:2

我有设置调试php cli应用程序的麻烦。我在Mac OS上工作,我在这里有Ubuntu的Vagrant,在这个Ubuntu里面我有docker。所以其中一个docker容器运行我的PHP应用程序,PHP解释器存在于其中。

之前(当应用程序完全在Vagrant机器中时)我使用此命令来调试我的cli应用程序,但现在它不起作用:

export XDEBUG_CONFIG =“remote_enable = 1 remote_mode = req remote_port = 9000 remote_host = 192.168.10.10 remote_connect_back = 0”

如何设置PhpStorm来调试我的php cli应用程序?

php docker vagrant phpstorm
2个回答
1
投票

在Docker容器内部不要使用remote_host。此外,您不必在Docker或Vagrant中公开任何其他端口。

这是我的xdebug.ini文件,适用于PHP 5.6

zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=0
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_connect_back=1

确保正确配置了PhpStorm(在我的情况下为2016.1)

  • 语言和框架 - > PHP - >服务器 - > localhost - > localhost:80 Xdebug
  • 语言和框架 - > PHP - >调试 - > Xdebug - >调试端口:9000
  • 语言和框架 - > PHP - >调试 - > Xdebug - >可以接受外部连接
  • 语言和框架 - > PHP - >调试 - > DBGp代理 - >端口9000

完成后,在工具栏的PhpStorm中找到Listen for debugger connections图标,然后单击它。

如果要从命令行调用它,请记住包含XDEBUG_SESSION cookie,即

curl 'http://localhost' -sSLI -H 'Cookie: XDEBUG_SESSION=xdebug'

如果您使用Firefox安装The easiest Xdebug并在工具栏中启用它。


1
投票

在我的例子中,通过Web浏览器进行调试运行良好,CLI调试(phpunit)带来了问题。这是因为xdebug因路径映射而丢失,您需要明确告诉docker。

您需要告诉Docker PHPStorm中的哪个服务器配置应该使用,只需在docker容器中导出该env变量。

export PHP_IDE_CONFIG="serverName=<server-name>"
© www.soinside.com 2019 - 2024. All rights reserved.