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 guide.

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 below:

Now, add the following code in the file:

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 the complete path of your Drupal deployment on Cloudways server, connect via SSH to your Cloudways Server by following the guide: How to launch an SSH terminal from the Cloudways Platform.
  • 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 such as: /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 the Server Management area in the Master Credentials section.

Master credentials

And for Application URL, click on the Access Detail section under the Application Management area.

Drush application details

Step 3: Performing Basic Tasks via Drush

Below are some basic tasks which you can perform via Drush.

  • Check the status of the remote Drupal installation on Cloudways server.
Basic Tasks via Drush

  • To clear the cache of the Drupal site on the Cloudways server:
  • 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

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):

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

 

Have Questions? You can start a discussion on Community Forum

Comments are closed.

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