Skip directly to content

Drush site aliases

on Wed, 05/25/2011 - 10:28

You may already know that Drush is a great tool for maintaining your Drupal install or project. We are going to make things a bit easier through the use of aliasing. Aliasing allows us to go from
drush --uri="mydrupalsite.com" --root="/var/www/mds" status
to something simple like
drush @mds status
by keeping all the configurations in a central place. There are a few places actually that your alias files can be placed:

  1. /etc/drush
  2. In the drush installation folder
  3. In the 'aliases' folder in the drush installation folder
  4. $HOME/.drush

Keeping the aliases in /etc/drush or in the installation folder will make them accessible to anyone using Drush on the server, which is a good setup for a development team. Keeping the aliases in your home directory will make them available only to you by default. You can also set the alias-path in the drushrc.php file (but we will save that for another time) to use a file located in a different location.

For our purposes we will be using our home directory as to not effect any other users until we have a nice working set of aliases. We will create a file called aliases.drushrc.php and add the information to shorten our command above.

~/.drush/aliases.drushrc.php

$aliases['mds'] = array(
'uri' => 'mydrupalsite.com',
'root' => '/var/www/mydrupalsite.com',
);

Just that quick and easily we can now use @mds in our drush commands. This is great but really only useful for a couple commands such as pm-download or status. What if we would like to see the status of a remote server (yeah drush can do that) or dump the database out to a file. Let's look at that layout.

~/.drush/aliases.drushrc.php

$aliases['mds'] = array(
'uri' => 'mydrupalsite.com',
'root' => '/var/www/mydrupalsite.com',
'db-url' => 'mysql://username:password@dbhost.com:port/mydrupalsite',
'remote-host' => 'mydrupalsite.com',
'remote-user' => 'superdev',
);

So here we've added our remote host and the user to ssh into that host. For this to work without continuously asking for your password you can setup an ssh key (Linux, Mac OSX). This now means that when typing in drush @mds status you are checking the status of the remote server. We can now do quite a bit of remote work from the local command line, you want to clear cache on your remote server, drush @mds cache-clear all. Another line we added here was the db-url definition. This will now allow us to easily dump the database for the purpose of backups or pulling it for a staging or dev server by typing drush @mds sql-dump > mydrupalsite.sql. That's pretty cool.

Next time we will look at grouping aliases together so you can keep information for your dev, staging, and production server in the same file and use drush @mds status to get the status of all three sites at the same time.

More information can be found in the aliases documents.

Post new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or class="OPTIONS" [title="the title"].
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.