Drush: The Swiss Army Knife for Drupal
Article
I'm always interested in finding ways to reduce the busy-work and get right to the fun parts of development. Drush has been the tool to help me do that. If the last three articles on Drush haven't convinced you, perhaps it's because I haven't told you about aliases and make files. Both require some setup but after that you will wonder why you didn't use them sooner.
Aliases
A Drush alias is a short name for one of three things: a specific site, a Drush command, or a shell command.
Let’s say you have three Drupal sites sharing the same codebase (multisite). We’ll call them “default”, “example.com”, and “store.example.com”. When executing a command, Drush assumes you want to run the command against the default site. But what if you want to check the status of store.example.com? That's where a site alias becomes useful!
We first need to create an alias file where we can define our aliases for Drush. Although it’s possible to add system-wide aliases in /etc/drush
, for this example we are going to create the file drushrc.php
in our user’s home folder. (If you don't already have a .drush
folder, create one.)
~/.drush/drushrc.php
Now we define our alias within that file. In the example code below, I'm defining the alias "store" by telling Drush where to find the Drupal root and the domain name of this particular site. Copy this example and insert it into your file. Replace the alias, root, and uri with the information that fits your situation.
<?php
$aliases['store'] = array(
'root' => '/path/to/drupal',
'uri' => 'store.example.com',
);
Save the file and you are done! You have just created a site alias. Now you can use this new alias in commands. Prefixed with @
, your alias should be the second thing you type, as in the command below.