我有设置调试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)
完成后,在工具栏的PhpStorm中找到Listen for debugger connections图标,然后单击它。
如果要从命令行调用它,请记住包含XDEBUG_SESSION cookie,即
curl 'http://localhost' -sSLI -H 'Cookie: XDEBUG_SESSION=xdebug'
如果您使用Firefox安装The easiest Xdebug并在工具栏中启用它。
在我的例子中,通过Web浏览器进行调试运行良好,CLI调试(phpunit)带来了问题。这是因为xdebug因路径映射而丢失,您需要明确告诉docker。
您需要告诉Docker PHPStorm中的哪个服务器配置应该使用,只需在docker容器中导出该env变量。
export PHP_IDE_CONFIG="serverName=<server-name>"