To expand Greg answer. Here is my Drush alias for one of my project.
Put this script in your host ~/.drush
folder and rename to something like PROJECT.aliases.drushrc.php
.
<?php
/**
* Requirements:
* Make sure to upload your ssh key to prod and staging.
*
* Uploading of ssh key:
* $ ssh-copy-id username@hostname
*/
// Site stage environment.
$aliases['stage'] = array(
'parent' => '@parent',
'site' => 'PROJECT',
'env' => 'stage',
'uri' => 'STAGING_URL',
'root' => '/path/to/drupal',
'remote-host' => 'STAGING_URL', // hostname
'remote-user' => 'USERNAME', // ssh user
);
// Site prod environment
$aliases['prod'] = array(
'parent' => '@parent',
'site' => 'PROJECT',
'env' => 'prod',
'uri' => 'PROD_URL',
'root' => '/path/to/drupal',
'remote-host' => 'PROD_URL', // hostname
'remote-user' => 'USERNAME', // ssh user
);
// For local
$aliases['local'] = array(
'parent' => '@parent',
'site' => 'PROJECT',
'env' => 'local',
'uri' => 'LOCAL_URL',
'root' => '/path/to/drupal',
'ssh-options' => '-p 2222 -i /home/HOST_USERNAME/.vagrant.d/private_key',
'remote-host' => '127.0.0.1', // hostname or IP of Vagrant, default to loopback
'remote-user' => 'vagrant', // vagrant username, default to vagrant
);
To use this against stage
and prod
servers you need to upload your ssh-key first by doing ssh-copy-id user@hostname
.
The to test if the script is working on your Vagrant machine.
$ drush @PROJECT.local status
where PROJECT
is the actual value of site
.
To test on staging.
$ drush @PROJECT.stage status
And to test on prod.
$ drush @PROJECT.prod status
NOTE: You may need to clear your Drush cache first before running the above commands.
With Drush aliases you don't need to ssh on the target machine and execute Drush.
Hope this helps.