繁体   English   中英

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

[英]Debug PHP cli application inside docker with PhpStorm

我有设置调试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应用程序?

在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安装最简单的Xdebug并在工具栏中启用它。

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

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

export PHP_IDE_CONFIG="serverName=<server-name>"

暂无
暂无

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

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