Drupal - Can Xdebug be triggered by Drush commands?

you have to remember that with drush you are (most supposedly) in cli, so this should help :

https://stackoverflow.com/questions/1947395/how-can-i-debug-a-php-cli-script-with-xdebug

also, try running the command with the option -d (--debug) - it should give you quite a lot of info about what is going wrong.


You may use xdebug_start_trace() and xdebug_stop_trace() XDebug functions to kick off the debugger on demand. Make sure that you've configured XDebug in CLI first (php -i | grep xdebug).

Then create new one-liner PHP file as follows (e.g. drush_xdebug_start.inc):

<?php xdebug_start_trace();

Then run the drush as:

drush --early="$PWD"/drush_xdebug_start.inc whatever_command_you_need

I use XDebug on drush requests all the time.

  1. Make sure XDebug is loaded in your CLI php by running php -i
  2. Make sure your client is listening for XDebug connections, and is doing so on the right port. I have successfully debugged using PHPStorm, Netbeans, and Komodo IDE as clients.