Search code examples
phpstormxdebug

PhpStorm & Xdebug - cant get to work debugger with CLI script


This is my first post here, I post because after reading through X articles googling can't get PhpStorm, Xdebug work with CLI scripts.

Already tried to follow advices from:

I had it working, but after destroy vagrant recently and now can't fully restore this feature.

SETUP:

  • I'm running Symfony project on Vagrant.
  • Debugging of "webpages" on my server works just perfectly.
  • When I try debug CLI Command I prequisite it with:

    export XDEBUG_CONFIG="XDEBUG_SESSION=1"
    export PHP_IDE_CONFIG="serverName=vagrant"
    

XDEBUG.INI (on Vagrant):

zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=192.168.0.133 (ip I get from ifconfig -a on Vagrant)
xdebug.remote_port=9000
xdebug.max_nesting_level=2500
xdebug.remote_handler=dbgp
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.idekey="PHPSTORM"

Any help much appreciated. Digged through X articles on web but in my eyes all configurations look ok, no idea what to do...


Solution

    1. Set xdebug.remote_connect_back to be 0.

      This option prevents you from using right IP address when you are doing Remote CLI debugging. Since it's a CLI debug, the IP will always be local (vagrant machine) while you need another one.

      This option works OK when debugging over browser as request comes from your "real" computer. But when doing CLI debug .. request will be local to Vagrant machine.

      When this option is set to 1 (as it is done now) it ignores the setting from #2 below.

    2. xdebug.remote_host=192.168.0.133 (ip I get from ifconfig -a on Vagrant) -- this should be an IP of your computer where PhpStorm is running as seen from Vagrant machine.

    Combination of those 2 above will do the job for you.