Search code examples
phpsymfonydockerphpstormxdebug

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. 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.

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.

My question is how to properly set this up and debug it from PhpStorm? I tried to create a new debug configuration (PHP Remote Debug) but breakpoints are not trigged.


Solution

  • 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:

    docker exec -ti ^container_id^ /bin/sh
    

    Or if running a debian/ubuntu based one (or you installed manually 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. If running on a small window just pipe int into less -S resulting the command:

    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:

    Phpstorm settings

    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.