Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Drush pro for the lazy: Aliases

.Drush aliases allow us to execute commands on a remote site from the local console. It is the perfect tool for the lazy drupal developer. With drush aliases I rarely login to a remote server, I execute all the drush commands from my local console. It is also a great for workflow automation. Here is an example command using an alias: drush cc @dev.site This command will execute the cc (clear caches) on the @dev.site as it is defined in the alias. For this to work, you will have to:

  1. Have passwordless login in the target system
  2. Set up the site alias

Passwordless login

For passwordless login, we need to copy our public key to the remote machine: ssh-copy-id [email protected] Then try to login to the ssh server without a password. Once this is set up, we can set up our aliases.

Set up a drush alias

A drush alias is an array that defines a site. It includes things like the remote site address, the db user etc. Drush reads this array so that it can login to the remote site and execute drush commands via ssh. Here is a sample alias array:

$aliases['dev.site'] = array (
 
'remote-host' => 'dev.site.com',
 
'remote-user' => 'devsite',
 
'root' => '/home/devsite/public_html',
 
'uri' => 'http://dev.site.com',
);
?>

Or, use the following snippet if drush is not installed in the target server:

$aliases['dev.site'] = array (
 
'remote-host' => 'dev.site.com',
 
'remote-user' => 'devsite',
 
'root' => '/home/devsite/public_html',
 
'uri' => 'http://dev.site.com',
 
'databases' =>
  array (
   
'default' =>
    array (
     
'default' =>
      array (
       
'driver' => 'mysql',
       
'database' => 'dev_db',
       
'username' => 'dev_db_user',
       
'password' => 'dev_db_pass',
       
'host' => 'localhost',
       
'prefix' => '',
       
'collation' => 'utf8_general_ci',
      ),
    ),
  ),
);
?>

This array must be placed in a file with the following name: example.aliases.drushrc.php Put this file in your ~/.drush or in the sites/all/drush folder. You can obtain the alias definition above by logging into the target site and executing the command: drush site-alias --with-db --show-passwords --alias-name=dev.site @self

Have fun

You can perform cool actions like copying the database from the live site to the dev from your local console: drush sql-sync @live.site @dev.site

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web