Setting up Drush Remote Aliases for Drupal Sites on CloudwaysMay 12, 2015

 

In this KB:

  • What is Drush?
  • How to set up Drush remote aliases
  • How to perform actions using Drush

 

Drush remote aliases enable the users to execute ‘drush’ commands on their local system which would actually execute the same command(s) on a remote server with a Drupal installation/site. Since drush is already supported on Cloudways servers with drush remote command capability, Cloudways users can also use any of the created drush remote aliases in their local system to access and perform certain tasks on their Drupal sites/apps hosted on Cloudways server(s).

Here, we explain how you can set up drush remote aliases capable of performing drush tasks remotely on Cloudways Drupal deployments from your local computer.

Step 1: Enabling SSH Key Authentication

The drush remote aliases configuration requires SSH public/private key authentication be set for user’s local system and Cloudways server. Steps are as follows:

1) Generate SSH pub/private key pair on your local system.

2) Upload the public key (id_rsa.pub) on your Cloudways server via console

The complete process for generating the key pair and uploading the public key to Cloudways server is explained in this KB.

Step 2: Creating Drush Remote Alias File on Local System

  • We assume that you have drush already installed on your local system. In the drush installation, (here for example we have drush installation in /etc/drush) create an alias file. Filename must be in the form ‘alias name.alias.drushrc.php’ (here, for example, we have defined ‘drupal’ as the alias name) as seen in the screenshot above:

root@08518-12524:/etc/drush# vi drupal.aliases.drushrc.php

  • Now, add the following code in the file:

<?PHP
// Define the environment. We have defined ‘live’ here as an example so any commands we will be executing on our local system will be making changes to live Drupal site on Cloudways server.
$aliases[‘live’] = array(
‘remote-host’ => ‘178.62.5.135’,
‘remote-user’ => ‘rvgjzgyeht’,
‘root’ => ‘/home/08518-15517.cloudwaysapps.com/rvgjzgyeht/public_html’,
‘uri’ => ‘drupal-77-15517-35896.cloudwaysapps.com’,
);
?>

  • Save this file: Type ‘Esc’ then ‘:wq’ to save this file.
  • Similarly, we can define/add similar code in the alias file for dev and staging environments (just replace the ‘live’ for ‘dev’ or ‘staging’ and related details).

Creating Drush Remote

  • For complete path of your Drupal deployment on Cloudways server, SSH to your Cloudways Server by following the KB How to launch an SSH terminal from the Click&Go console
  • In the public_html folder execute command ‘pwd’ which will show the full path of the Drupal installation which needs to be added as the ‘root‘ variable:

/home/08518-15517.cloudwaysapps.com/rvgjzgyeht/public_html

Note: Cloudways server/app information seen in the remote alias file above is to be extracted from the Cloudways console as shown in the next screenshot.

You can find “Public IP” and “Username” under “Server Management” page.

Master credentials

And for “Application URL”, open “Access Detail” under “Application Management”.

drush application details

Step 3: Performing Basic Tasks via Drush

  • Check the status of the remote Drupal installation on Cloudways server.

root@localuser:~# drush @drupal.live status

Basic Tasks via Drush

  • To clear the cache of the Drupal site on the Cloudways server:

root@localuser:~# drush @drupal.live cc all

  • This command will download the entire web root from the remote site (hosted on Cloudways server) to your computer. This may take quite some time depending on data size.

Basic Tasks via Drush

root@08518-12524:~# drush rsync @drupal.live:%files/ @drupal.dev:%files

However, before running this command make sure the alias of a local Drupal site is also added in the drush alias file. We can see this definition in the next screenshot.

Basic Tasks via Drush

  • Here we can see the definition of the dev site on the local system. In this way, the drush rsync will properly copy the production content from the remote Drupal live website to the development environment on our local file system.

Basic Tasks via Drush

Step 4: Updating Drupal via ‘drush pm-update’ Command

  • Cloudways users can also update their Drupal installation on their Cloudways servers. This is done by connecting via SSH to the target server  and executing the following command in the Drupal installation folder (public_html folder):

drush pm-update –backup-dir=/home/08518-15517.cloudwaysapps.com/rvgjzgyeht/tmp

  • As a safety measure, this command also takes a backup of the Drupal installation before running the update (via a backup switch in the command as seen above).

Updating Drupal via 'drush pm-update' Command

 

Leave a Reply

Still need help? Our support team is waiting to help you. Ask them now