Drush aliases on your Vagrant dev environment

Note: This blog post is intended for members of the U of L web team and has some details specific to our own working environment. These instructions won’t work for everybody.

Drush aliases provide a handy way to run Drush commands on remote servers without having to ssh into that machine and navigate to the Drupal environment in which you want to work. When working in our Vagrant-controlled development environment, vagrant ssh isn’t a huge barrier, but if you want to be able to just reference your dev environment from your local Drush interface, this is how I’ve gone about it.

First of all, you need to make sure you have Drush running locally. If you try running drush at the command line and get -bash: drush: command not found, you need to install it. Homebrew will handle that quickly and easily with a simple brew install drush

Next, make sure that your virtual machine is running. If not, give it the ol’ drush up. Once you’ve done that, you’ll need to copy an SSH key over to your virtual machine with this command (You will need to repeat this step on each virtual machine that you are doing development on):

scp ~/.ssh/id_rsa.pub vagrant@

Now, create a Drush alias file on your local machine in the ~/.drush folder. Mine is ~/.drush/dev.aliases.drushrc.php. Copy and paste this code block in there:

$aliases['dev'] = array(
'root' => '/vagrant/public',
'remote-host' => '',
'remote-user' => 'vagrant',

(Remember to start that file with an opening php tag … WordPress seems to think I’m doing something fishy and keeps stripping it out.)

Now, you can run Drush commands and include @dev to specify the Vagrant development environment as the target of your command, like so:

$ drush @dev status Drupal version : 7.26
Site URI : http://default
Database driver : mysql
Database username : root
Database name : drupal
Database : Connected
Drupal bootstrap : Successful
Drupal user : Anonymous
Default theme : bartik
Administration theme : seven
PHP executable : /usr/bin/php
PHP configuration : /etc/php5/cli/php.ini PHP OS : Linux
Drush version : 6.0-dev
Drush configuration :
Drush alias files :
Drupal root : /vagrant/public
Site path : sites/default
File directory path : sites/default/files
Temporary file directory path : /tmp

For more information on Drush aliases, check out the inline documentation in this example file: http://drush.ws/examples/example.aliases.drushrc.php