Skip to content

Instantly share code, notes, and snippets.

@scottalan
Last active November 10, 2016 18:03
Show Gist options
  • Save scottalan/79e4d28c91cb976988d952da2f8865b7 to your computer and use it in GitHub Desktop.
Save scottalan/79e4d28c91cb976988d952da2f8865b7 to your computer and use it in GitHub Desktop.
PHPStorm | Drush | Vagrant -- Debug

Getting started

I use Drupal VM with php5-fpm and it uses port 9000 so I just set my debug ports to 9001.

  • Set the debug port to 9001 in PHPStorm

  • Create a new server in PHPStorm:

    • Preferences >> Languages & Framworks >> Servers
    • Add a Name: and Host: e.g., mysite.dev (for both)
    • Click the checkbox: Use path mappings...
    • I always map my local DRUPAL_ROOT to my VM DRUPAL_ROOT
  • Now ssh into the VM but we are going to forward a port:

    • ssh -R 9001:localhost:9001 drupalvm
    • The drupalvm in the command above refers to an entry in my ~/.ssh/config file.
    • This is what that looks like:
    Host drupalvm
    HostName 127.0.0.1
    User vagrant
    Port 2222
    UserKnownHostsFile /dev/null
    StrictHostKeyChecking no
    PasswordAuthentication no
    IdentityFile /opt/drupal-vm/.vagrant.d/insecure_private_key
    IdentitiesOnly yes
    LogLevel FATAL
    ForwardAgent yes
    

  • On the VM run:
    • export XDEBUG_CONFIG="idekey=PHPSTORM remote_host=127.0.0.1 remote_port=9001” && export PHP_IDE_CONFIG=“serverName=mysite.dev"

Add Drush as an external library.

  1. In PHPStorm right click on External Libraries and select Configure PHP Includes path...
  2. Click the + button (bottom left corner)
  3. Locate the path to your local copy of Drush e.g., /Users/scott/.composer/vendor/drush/drush
  4. Click Apply
  5. Go back to where you added your server and add a path mapping from you local copy to where Drush is in the VM

Set a breakpoint on the first line of drush.php in the External Libraries

BOOM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment