What Can Drush Do For You? Part 1 of 4

by | May 6, 2015 | Development

Share this post

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

Insights

Helping B2B leaders use technology to drive business

2026 B2B Content Marketing Trends

2026 B2B Content Marketing Trends

What Mid-Market Leaders Need to Do Right Now Over the past year, my team and I have been doing something that’s become surprisingly rare in digital business: meeting face-to-face with our clients. Whether it's healthcare technology, B2B manufacturing, nonprofits, or...

The Cost of Not Doing Anything

The Cost of Not Doing Anything

Why B2B and Nonprofits Should Invest in Their Websites and Portals In today’s digital first world, a website or customer portal isn’t just a “nice to have” ,  it’s the foundation of your organization’s success. Yet, many B2B companies and nonprofits fall into the trap...

A Guide To The Difference Between GEO, AIO and SEO

A Guide To The Difference Between GEO, AIO and SEO

For years, we built websites to earn authority with search engines.  Recent research outlines how AI summaries replacing traditional search results and are having a tremendous negative effect on website traffic.  Since SEO is no longer driving customers to your site,...