2 min read

What Can Drush Do For You? Part 1 of 4

What Can Drush Do For You? Part 1 of 4

Drush is a command line interface tool used to help manage and maintain Drupal installations. Even novice Drupal developers soon realize how much of a benefit Drush can be. From creating aliases, to gathering important information about a client's site, to automating the syncing of multiple environments, Drush has many ways to boost your productivity.

Drush, Drupal, CodeThe developers of Drush have done a great job of maintaining documentation of all of their commands. It's easy to read and follow, and is a great resource if you lose track of which options you need. Be sure when looking for information, to select the correct Drush version for the site you will be working on.

This series of blogs will describe the ways Drush can greatly benefit your productivity and efficiency with your daily workload.

Drush Site Aliases

Drush has the ability to use Site Aliases to store information for a particular client, which can then be referenced by commands. This is a great way to keep all your clients organized. The aliases will have to be generated by hand, but once they are created, your efforts will be rewarded.

For any Drupal developer who seems to be always switching between environments simply to run a single command, you will appreciate the concept of Site Aliases. When you are working on multiple environments, a Site Alias makes it easy to execute commands to a specific environment without ever having to change a directory, thus immediately reducing the time needed to complete tasks.

Begin by creating the alias in your .drush/ directory. Name the file SITENAME.aliases.drushrc.php. Be sure to replace SITENAME. This file naming convention is something that Drush recognizes. The following is a template alias for a production environment:

$aliases['production'] = array (
'uri' => 'default',
'root' => /path/to/site,
'remote-user' => '$USER',
'remote-host' => '$REMOTE_HOST',
'ssh-options' => '-A',
'path-aliases' => array(
'%dump-dir' => '/path/to/dump/dir',
'%files' => '/path/to/files/dir'
'source-command-specific' => array (
'sql-sync' => array (
'no-cache' => TRUE,
'structure-tables-key' => 'common',
// No need to modify the following settings
'command-specific' => array (
'sql-sync' => array (
'sanitize' => TRUE,
'no-ordered-dump' => TRUE,
'structure-tables' => array(
// You can add more tables which contain data to be ignored by the database dump
'common' => array('cache', 'cache_filter', 'cache_menu', 'cache_page', 'history', 'sessions', 'watchdog'),

Here you can see the command specific settings and source command specific settings. These are useful to customize the behavior of commands as pertaining to the specified alias. This blog does not dive too deeply into how Drush aliases are configured but more information is available on the Drush Site Aliases.

Once all of your clients are established, you can run a command that will report all of the Site Aliases that Drush will recognize. Using different flags on the same command will determine how much or how little output goes to the screen.

drush sa

If the structure of a client's installation is changing, it's as easy as opening the alias and modifying the lines as needed. The alias file is a template for all the information a Drush command would need about a site. It is worth noting that Drush aliases are capable of environment specific command circumstances.

Hopefully this gives you a basic understanding of how aliases work and how they can help maintain and organize multiple sites in a way that makes life easier for any Drupal developer. Keep an eye out for the next part in the Drush micro-series.

Photo credit: txmx 2 / Foter / CC BY-NC-ND

Related Posts

1 min read

Syncing Environments Using Drush

Now that you have learned what a helpful tool Drush can be for all Drupal developers, let's think about how this, in combination with other command line tools, can make your jobs even easier. Any...
2 min read

How to use Drush to Maintain Modules

We've seen how Drush Site Aliases can save any Drupal developer time in multiple environments. Now, we'll discuss how Drush can also be used to maintain a site's readiness. Part of the way a Drupal...
2 min read

Using Drush to Check Site Status

We recently discussed how you can use Drush to maintain modules on your site. You can also use Drush to learn important configuration information, or discover errors that have been logged, without...
2 min read

New Cron Multi-Threaded Module for Drupal

Update: Here's a link to the project page on drupal.org