Video tutorials

Drush Site Aliases and Interactive Shell

In this new Drupal tutorial see how to set up and use Drush site aliases. They allow you to quickly administer your sites or save even more time with Drush interactive shell. Finally, we'll look at the common "gotcha" when using the interactive shell with aegir (or other non-root users).

Watch the Screencast

See video

Tutorial In a Nutshell

Assigning aliases to sites is convenient for site administration because you don't have to be in the site directory any more (it's especially helpful for multisites). In addition to that, it also helps with the interactive shell. For examples:

$ drush core-cli

$ use @yoursitealias

Drush interactive shell

After that, you can run commands on your site without using the word "drush" or the actual alias.

@yoursitealias> $ pm-update

To see the aliases on your server, use 'drush sa'. Additionally, 'drush status' will show you the location of the aliases file if you have one set up.

If you change to the drush directory and list contents, you'll see the examples directory. Among other files, it contains the example aliases file. Let's copy it to the drush root and rename it (from drush directory):

$ cp examples/example.aliases.drushrc.php aliases.drushrc.php

Open the aliases file to edit it. It's well documented with various examples. For starters, we'll be using a very simple setup with root (the directory of your drupal installation) and uri (the url of the site).

Aliases file - add sites

You can run 'drush status' and 'drush sa' to check if drush has loaded the new file and site aliases.

At this point, you can use aliases to administer your site like this:

$ drush @alias command

You can use aliases file to set up default command options by using 'command-specific' array:

Specifying commands

Open interactive shell and choose one of the sites to use. If you run 'status' now, it should show the passwords:

Drush interactive shell

Drush interactive shell is actually a wrapper for the standard shell, so all the same commands apply. Sometimes bash commands would take priority (for example, status on some systems) - in that case, use the prefix drush.

A note on Aegir users (or anyone who uses root and then switches to the user who owns Drupal directory) - it's best practice to be logged in as the user before activating drush shell, or you're going to run into permission issues.

Interactive shell permissions issues

Check /etc/passwd to make sure the user has a shell and that the user has a password (you can, of course, use the RSA keys instead).