简体   繁体   English

在 Docker 容器中使用 PhpStorm 调试 Symfony CLI 应用程序

[英]Debug Symfony CLI application with PhpStorm inside Docker container

My current setup involve PhpStorm IDE in which I have imported Symfony 3 projects which is basically CLI tool.我当前的设置涉及 PhpStorm IDE,我在其中导入了 Symfony 3 项目,它基本上是 CLI 工具。 On the host machine I don't have PHP installed so I'm running the application from Docker container which has PHP and Xdebug installed.在主机上,我没有安装 PHP,所以我从安装了 PHP 和 Xdebug 的 Docker 容器运行应用程序。

I don't have issues to debug web applications from Docker containers but with Symfony and this CLI tool it seems a little bit more tricky.我从 Docker 容器调试 Web 应用程序没有问题,但是使用 Symfony 和这个 CLI 工具似乎有点棘手。

My question is how to properly set this up and debug it from PhpStorm?我的问题是如何正确设置它并从 PhpStorm 调试它? I tried to create a new debug configuration (PHP Remote Debug) but breakpoints are not trigged.我试图创建一个新的调试配置(PHP 远程调试),但没有触发断点。

Suppossing you have followed into the instructions mentioned into the following links:假设您已按照以下链接中提到的说明进行操作:

Or similar questions或者类似的问题

Then you need to follow theese steps:然后您需要按照以下步骤操作:

Step1: Get shell access to your container via running:步骤 1:通过运行获取对容器的 shell 访问权限:

docker exec -ti ^container_id^ /bin/sh

Or if running a debian/ubuntu based one (or you installed manually bash ):或者,如果运行基于 debian/ubuntu 的(或者您手动安装bash ):

docker exec -ti ^container_id^ /bin/bash

The ^container_id^ can be found via docker ps command it is the first column of the table. ^container_id^可以通过docker ps命令找到,它是表的第一列。 If running on a small window just pipe int into less -S resulting the command:如果在一个小窗口上运行,只需将 int 管道传输到less -S产生以下命令:

docker ps | less -S

Then export the following enviromental variables:然后导出以下环境变量:

export PHP_IDE_CONFIG="serverName=0.0.0.0:5092"
export XDEBUG_CONFIG="idekey=PHPSTORM"

Please keep in mind to setup the correct value specified into Servers section as you see in the image:请记住设置在Servers部分中指定的正确值,如图所示:

phpstorm 设置

It is important in order not to run into the problem specified in this question.为了不遇到此问题中指定的问题, 这一点很重要。

Then just enable debugger listentin into the phpstorm and spawn the cli as you do when you run a symfony application.然后只需在 phpstorm 中启用调试器监听并像运行 symfony 应用程序时一样生成 cli。

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

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