Drush Tutorial

Drush – Drupal Command Line interface

Drush is a command line interface that allows to manage your Drupal web sites fast and easy. This scripting shell should be additionally installed on your hosting server in order to benefit from its features. It is pre-installed on the SiteGround servers and you can use it with your Drupal Hosting package.

First, you need to have a Drupal installation under your hosting account. It can be completed in several mouse clicks through cPanel -> Softaculous.

Second, you need SSH access to your account in order to run Drush commands.

This tutorial explains how to use Drush in order to backup and update your script, install and activate Drupal extensions, remove them and clear the script’s cache. Note that if you are using Druapl 8.3 or below, you should replace drush with drush8 in the command examples below.

Backup Website with Drush

In order to create a backup of your Drupal web site using Drush, you should first log in your account via SSH. Detailed instructions on how to use SSH can be found in our SSH tutorial. After you login to your account via SSH, navigate to the Drupal installation’s home folder.

Then run the following command:

Replace USER with your actual cPanel username. You can pick a different location for the backup and different backup file name. Executing the command above will create an archive with all the website files and a copy of your Drupal database. The output would be similar to the following one:

After the process is successfully completed, you will be able to find the backup in the specified location - /home/USER/backup/site.tar.gz.

Restore Website with Drush

If you need to restore a backup of your website use the following command:

The output will be similar to:

Upgrade Website with Drush

To upgrade the Drupal core, use the command below:

After the application's core is upgraded, you should make sure to update the database as well:

Update entity, if any required entity updates are needed:

Install, Enable and Uninstall Plugin with Drush

To install a chosen plugin you should download and enable it. Check the example listed below:

The output would be similar to:

To enable the installed module, you should run the command below:

Instead of AddToAny you can pick a different Drupal plugin or module. To skip the Do you really want to continue? prompt modify the command in the following way:

A chosen extension can be disabled and removed with the command below:

Clear Cache with Drush

Often you would need to clear the script’s cache. It can be easily completed with the following command:

If you prefer to clear all types of cache at once, the following command is available:

Drush Help

To get help on the Drush commands run the following command:

If you want to learn how to use a specific command enter the following line in the shell:

Replace the command string with the chosen one. For example:

More about Drush may be found in the official documentation of the project: http://drush.ws/