Search code examples
symfonyphpstormxdebugremote-debuggingsymfony-3.1

How to remotely debug console commands in Symfony


Problem

I want to debug Symfony console commands on a remote VM server. I can get it to work to debug the bin/console script and all related method calls in the \Symfony\Bundle\FrameworkBundle\Console\Application but as soon as it calls the execute method of the specific command (in symfony/symfony/src/Symfony/Component/Console/Command/Command.php:256) the debugger mapping somehow looses the mapping and does not work anymore. I can not make it break at any breakpoints I set at the specific command.

Setup

On the VM I have the following php settings:

# /etc/php5/cli/php.ini
[xdebug]
zend_extension=/usr/lib/php5/20131226/xdebug.so

xdebug.remote_enable=on
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=on
xdebug.remote_connect_back=on

Before starting the debug session I create a SSH tunnel with

ssh -nNT -R 9000:localhost:9000 [email protected]

In PhpStorm I have the deployment configured using SFTP and set the PHP CLI interpreter to the remote php cli version.

I activate the "Start Listening for PHP Debug Connections". The first time the connection was made, the server debug connection was created and I added the mapping for the root dir of the project:

PHP Server Config

On my local machine the IP 192.168.56.57 is mapped to the domain sa-platform.dev-vm in /etc/hosts.

When I call my command on the VM bin/console sa:events:group I get the connection in PhpStorm stopping at the first line of the related console script.

debug connection breaking at first line of console script

And I can debug until the point where the execute function of my command is called:

debug console application until command execute function is called

But after that no chance to debug my command.

I have tried setting the PHP server mapping in PhpStorm directly to the command files, which did not work.

Any help appreciated.

UPDATE: As suggested I have added the log file and set the accept external debug connections to 5 in PhpStorm.

I have no clue about the log, but maybe someone does?

The complete log of one session can be found here. The last entries look like this:

<- context_get -i 23 -d 0 -c 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="23" context="1"><property name="$_COOKIE" fullname="$_COOKIE" type="array" children="0" numchildren="0" page="0" pagesize="100"></property><property name="$_ENV" fullname="$_ENV" type="array" children="0" numchildren="0" page="0" pagesize="100"></property><property name="$_FILES" fullname="$_FILES" type="array" children="0" numchildren="0" page="0" pagesize="100"></property><property name="$_GET" fullname="$_GET" type="array" children="0" numchildren="0" page="0" pagesize="100"></property><property name="$_POST" fullname="$_POST" type="array" children="0" numchildren="0" page="0" pagesize="100"></property><property name="$_REQUEST" fullname="$_REQUEST" type="array" children="0" numchildren="0" page="0" pagesize="100"></property><property name="$_SERVER" fullname="$_SERVER" type="array" children="1" numchildren="27" page="0" pagesize="100"><property name="COMP_WORDBREAKS" fullname="$_SERVER[&#39;COMP_WORDBREAKS&#39;]" type="string" size="12" encoding="base64"><![CDATA[IAkKIic+PDt8Jig6]]></property><property name="TERM" fullname="$_SERVER[&#39;TERM&#39;]" type="string" size="14" encoding="base64"><![CDATA[eHRlcm0tMjU2Y29sb3I=]]></property><property name="SHELL" fullname="$_SERVER[&#39;SHELL&#39;]" type="string" size="9" encoding="base64"><![CDATA[L2Jpbi9iYXNo]]></property><property name="SSH_CLIENT" fullname="$_SERVER[&#39;SSH_CLIENT&#39;]" type="string" size="21" encoding="base64"><![CDATA[MTkyLjE2OC41Ni4xIDUxODQ2IDIy]]></property><property name="OLDPWD" fullname="$_SERVER[&#39;OLDPWD&#39;]" type="string" size="11" encoding="base64"><![CDATA[L2hvbWUvam9lcmc=]]></property><property name="SSH_TTY" fullname="$_SERVER[&#39;SSH_TTY&#39;]" type="string" size="10" encoding="base64"><![CDATA[L2Rldi9wdHMvMA==]]></property><property name="USER" fullname="$_SERVER[&#39;USER&#39;]" type="string" size="5" encoding="base64"><![CDATA[am9lcmc=]]></property><property name="LS_COLORS" fullname="$_SERVER[&#39;LS_COLORS&#39;]" type="string" size="1422" encoding="base64"><![CDATA[cnM9MDpkaT0wMTszNDpsbj0wMTszNjptaD0wMDpwaT00MDszMzpzbz0wMTszNTpkbz0wMTszNTpiZD00MDszMzswMTpjZD00MDszMzswMTpvcj00MDszMTswMTpzdT0zNzs0MTpzZz0zMDs0MzpjYT0zMDs0MTp0dz0zMDs0Mjpvdz0zNDs0MjpzdD0zNzs0NDpleD0wMTszMjoqLnRhcj0wMTszMToqLnRnej0w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NToqLnF0PTAxOzM1OioubnV2PTAxOzM1Oioud212PTAxOzM1OiouYXNmPTAxOw==]]></property><property name="MAIL" fullname="$_SERVER[&#39;MAIL&#39;]" type="string" size="15" encoding="base64"><![CDATA[L3Zhci9tYWlsL2pvZXJn]]></property><property name="PATH" fullname="$_SERVER[&#39;PATH&#39;]" type="string" size="56" encoding="base64"><![CDATA[L3Vzci9sb2NhbC9iaW46L3Vzci9iaW46L2JpbjovdXNyL2xvY2FsL2dhbWVzOi91c3IvZ2FtZXM=]]></property><property name="PWD" fullname="$_SERVER[&#39;PWD&#39;]" type="string" size="20" encoding="base64"><![CDATA[L3Zhci93d3cvc2EtcGxhdGZvcm0=]]></property><property name="LANG" fullname="$_SERVER[&#39;LANG&#39;]" type="string" size="11" encoding="base64"><![CDATA[ZGVfREUuVVRGLTg=]]></property><property name="GCC_COLORS" fullname="$_SERVER[&#39;GCC_COLORS&#39;]" type="string" size="66" encoding="base64"><![CDATA[ZXJyb3I9MDE7MzE6d2FybmluZz0wMTszNTpub3RlPTAxOzM2OmNhcmV0PTAxOzMyOmxvY3VzPTAxOnF1b3RlPTAx]]></property><property name="SHLVL" fullname="$_SERVER[&#39;SHLVL&#39;]" type="string" size="1" encoding="base64"><![CDATA[MQ==]]></property><property name="HOME" fullname="$_SERVER[&#39;HOME&#39;]" type="string" size="11" encoding="base64"><![CDATA[L2hvbWUvam9lcmc=]]></property><property name="LOGNAME" fullname="$_SERVER[&#39;LOGNAME&#39;]" type="string" size="5" encoding="base64"><![CDATA[am9lcmc=]]></property><property name="SSH_CONNECTION" fullname="$_SERVER[&#39;SSH_CONNECTION&#39;]" type="string" size="35" encoding="base64"><![CDATA[MTkyLjE2OC41Ni4xIDUxODQ2IDE5Mi4xNjguNTYuNTcgMjI=]]></property><property name="_" fullname="$_SERVER[&#39;_&#39;]" type="string" size="11" encoding="base64"><![CDATA[YmluL2NvbnNvbGU=]]></property><property name="PHP_SELF" fullname="$_SERVER[&#39;PHP_SELF&#39;]" type="string" size="11" encoding="base64"><![CDATA[YmluL2NvbnNvbGU=]]></property><property name="SCRIPT_NAME" fullname="$_SERVER[&#39;SCRIPT_NAME&#39;]" type="string" size="11" encoding="base64"><![CDATA[YmluL2NvbnNvbGU=]]></property><property name="SCRIPT_FILENAME" fullname="$_SERVER[&#39;SCRIPT_FILENAME&#39;]" type="string" size="11" encoding="base64"><![CDATA[YmluL2NvbnNvbGU=]]></property><property name="PATH_TRANSLATED" fullname="$_SERVER[&#39;PATH_TRANSLATED&#39;]" type="string" size="11" encoding="base64"><![CDATA[YmluL2NvbnNvbGU=]]></property><property name="DOCUMENT_ROOT" fullname="$_SERVER[&#39;DOCUMENT_ROOT&#39;]" type="string" size="0" encoding="base64"><![CDATA[]]></property><property name="REQUEST_TIME_FLOAT" fullname="$_SERVER[&#39;REQUEST_TIME_FLOAT&#39;]" type="float"><![CDATA[1496314052.1787]]></property><property name="REQUEST_TIME" fullname="$_SERVER[&#39;REQUEST_TIME&#39;]" type="int"><![CDATA[1496314052]]></property><property name="argv" fullname="$_SERVER[&#39;argv&#39;]" type="array" children="1" numchildren="2"></property><property name="argc" fullname="$_SERVER[&#39;argc&#39;]" type="int"><![CDATA[2]]></property></property><property name="$GLOBALS" fullname="$GLOBALS" type="array" children="1" numchildren="17" page="0" pagesize="100"><property name="_GET" fullname="$GLOBALS[&#39;_GET&#39;]" type="array" children="0" numchildren="0"></property><property name="_POST" fullname="$GLOBALS[&#39;_POST&#39;]" type="array" children="0" numchildren="0"></property><property name="_COOKIE" fullname="$GLOBALS[&#39;_COOKIE&#39;]" type="array" children="0" numchildren="0"></property><property name="_FILES" fullname="$GLOBALS[&#39;_FILES&#39;]" type="array" children="0" numchildren="0"></property><property name="argv" fullname="$GLOBALS[&#39;argv&#39;]" type="array" children="1" numchildren="2"></property><property name="argc" fullname="$GLOBALS[&#39;argc&#39;]" type="int"><![CDATA[2]]></property><property name="_ENV" fullname="$GLOBALS[&#39;_ENV&#39;]" type="array" children="0" numchildren="0"></property><property name="_REQUEST" fullname="$GLOBALS[&#39;_REQUEST&#39;]" type="array" children="0" numchildren="0"></property><property name="_SERVER" fullname="$GLOBALS[&#39;_SERVER&#39;]" type="array" children="1" numchildren="27"></property><property name="GLOBALS" fullname="$GLOBALS[&#39;GLOBALS&#39;]" type="array" children="1" recursive="1"></property><property name="__composer_autoload_files" fullname="$GLOBALS[&#39;__composer_autoload_files&#39;]" type="array" children="1" numchildren="9"></property><property name="loader" fullname="$GLOBALS[&#39;loader&#39;]" type="object" classname="Composer\Autoload\ClassLoader" children="1" numchildren="9"></property><property name="input" fullname="$GLOBALS[&#39;input&#39;]" type="object" classname="Symfony\Component\Console\Input\ArgvInput" children="1" numchildren="6"></property><property name="env" fullname="$GLOBALS[&#39;env&#39;]" type="string" size="3" encoding="base64"><![CDATA[ZGV2]]></property><property name="debug" fullname="$GLOBALS[&#39;debug&#39;]" type="bool"><![CDATA[1]]></property><property name="kernel" fullname="$GLOBALS[&#39;kernel&#39;]" type="object" classname="AppKernel" children="1" numchildren="10"></property><property name="application" fullname="$GLOBALS[&#39;application&#39;]" type="object" classname="Symfony\Bundle\FrameworkBundle\Console\Application" children="1" numchildren="14"></property></property></response>

<- context_get -i 24 -d 0 -c 2
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="24" context="2"><property name="RANDOM_COMPAT_READ_BUFFER" fullname="RANDOM_COMPAT_READ_BUFFER" type="int" facet="constant"><![CDATA[8]]></property></response>

<- run -i 25
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="25" status="stopping" reason="ok"></response>

<- run -i 26
Log closed at 2017-06-01 10:48:01

Solution

  • As it turned out, my local version of the SaEventsGroupCommand I was trying to debug was different from the version on the VM. After checking the mapping and trying all suggestions from @LazyOne I did a deployment form my local machine to the VM for the commands bundle. And suprise after that it worked and the debugger was breaking at my break points as intended.

    So conclusion if anyone comes across a similar problem. Make sure you have deployed all your code manually to the remote server or your automatically deployment is set to deploy external changes (e.g. different git branches) to the server.