I need to debug a drush command in a ddev project, but I don't know how to do it. In ddev v0.18.0, the PhpStorm debugger breaks at the beginning, but it can't find the associated code.
PHPStorm provides a very nice way to do this, and ddev makes it super easy with the automatic debugging setup.
This technique works best for a Drupal 8 site with drush vendored in, like you get with drupal-composer setups. It assumes that drush is vendored into vendor/drush/drush.
This PHPStorm blog post explains the technique.
Click a breakpoint at a place you know should be hit by your drush command.
Inside the container (ddev ssh
), export PHP_IDE_CONFIG="serverName=d8composer"
- Yours will be named something other than d8composer of course.
/var/www/html/vendor/drush/drush/drush uli
(or whatever command you want). PHPStorm will break at your breakpoint. (Of course you could execute that command many ways, but the point is you need to execute the version of drush that's vendored into the repo.On earlier versions of drupal you can actually just put a copy of drush into your repo temporarily to solve the mapping problem in the same way.
Note that Matt Glaman also wrote a blog post on Xdebug Over the Command Line with DDEV
Also check PHPStorm and uncheck “Ignore external connections through unregistered server configurations."