> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using Drush for your Drupal site

> Discover how to use Drush for Drupal tasks like backups and restores in this informative article.

This article describes how to use the Drush command-line tool to do common Drupal administrative tasks.

<Warning>
  **Important**

  Before you can use Drush, you must install it on your account. For information about how to do this, please see [this article](/docs/installing-drush-manually).
</Warning>

## About Drush

Drush is a tool for Drupal that enables you to do common administrative tasks and basic scripting from the command line. For example, you can back up and restore Drupal sites, install modules, and more.

<Tip>
  Drush is a command-line tool, so it helps if you already have some basic familiarity with the Linux command-line environment. If you have never worked in the Linux command-line environment before, you can learn the basics by reading [this article](/docs/introduction-linux-commands).
</Tip>

## Verifying the Drush installation

To verify that Drush is installed and functioning correctly on your account, follow these steps:

1. Log in to your account [using SSH](/docs/using-ssh-secure-shell).

2. Change to the directory where Drupal is installed. For example, if you installed Drupal in the document root directory, type the following command:

   ```bash theme={null}
   cd ~/public_html
   ```

   Alternatively, if you installed Drupal in a subdirectory, change to that directory instead.

   > 📘 Note
   >
   > All of the following commands in this article assume that you are running Drush in the directory where Drupal is installed. Most of these commands will not work if you run Drush from a different directory.

3. Type the following command:

   ```bash theme={null}
   drush status
   ```

   Drush should display information about your Drupal installation that resembles the following output (specific values will vary):

   ```
   Drupal version:  7.26                             
   Site URI:  http://default                   
   Database driver:  mysql                            
   Database hostname:  localhost                        
   Database username:  user_drup502                 
   Database name:  user_drup502                 
   Database:  Connected                        
   Drupal bootstrap:  Successful                       
   Drupal user:  Anonymous                        
   Default theme:  bartik                           
   Administration theme:  seven                            
   PHP configuration:  /usr/local/lib/php.ini           
   Drush version:  5.8                              
   Drush configuration:                                   
   Drupal root:  /home/username/public_html/drupal
   Site path:  sites/default                    
   File directory path:  sites/default/files              
   Temporary file directory path:  /tmp
   ```

## Configuring Drupal modules

A common Drupal administration task is module configuration. This is often done through Drupal's web administration interface. However, you can also quickly and easily work with Drupal modules on the command line.

For example, if you need to download and enable several modules, it is much quicker to do this on the command line with Drush than it is to click through the various Drupal web administration pages.

### Downloading modules

To download a Drupal module, type the following command in the directory where Drupal is installed. Replace ***module*** with the name of the module that you want to download:

```bash theme={null}
drush dl module
```

<Tip>
  * To download several modules at once, just add them to the end of the command. For example, to download the *views* and *token* modules at the same time, type `drush dl views token`.

  * To view the Drupal module project page and search for modules, please visit [http://drupal.org/project/project\_module](https://drupal.org/project/project_module).

  🚧 Important

  Some Drupal modules, such as *composer\_manager*, have additional PHP configuration requirements (for example, **allow\_url\_fopen** must be enabled). On some servers, you may receive an error message when you try to download or enable these modules. To resolve this problem, follow these steps:

  1. [Create a custom php.ini file](/docs/custom-php-ini-files) in the *public\_html* directory that enables the required settings.

  2. Add the following line to the */home/username/.bashrc* file, where ***username*** represents your hosting.com account username:

  ```
  export PHP_INI=~/public_html/php.ini
  ```

  3. To make the new settings take effect immediately, type the following command:

  ```bash theme={null}
  source ~/.bashrc
  ```
</Tip>

### Enabling modules

To enable a Drupal module that you have downloaded, follow these steps:

1. In the directory where Drupal is installed, type the following command. Replace ***module*** with the name of the module that you want to enable:

   ```bash theme={null}
   drush en module
   ```

2. If the module has dependencies, type `y` to install them, and then press Enter.

3. When Drush successfully enables the module, it displays **\[ok]**.

### Disabling modules

To disable a Drupal module, follow these steps:

1. In the directory where Drupal is installed, type the following command. Replace ***module*** with the name of the module that you want to disable:

   ```bash theme={null}
   drush dis module
   ```

2. At the **Do you really want to continue?** prompt, type `y` and then press Enter.

3. When Drush successfully disables the module, it displays **\[ok]**.

## Checking for Drupal updates

To check for available updates for your Drupal site, follow these steps:

1. In the directory where Drupal is installed, type the following command:

   ```bash theme={null}
   drush up
   ```

2. Drush checks if there are updates available:

   * If there are no updates available, Drush displays **No code updates available** and exits.

   * If there are updates available, at the **Do you really want to continue?** prompt, type `y` and then press Enter. Drush updates the Drupal installation.

## Backing up and restoring a Drupal database

Drush makes it easy to quickly back up and restore Drupal databases. To do this, follow these steps:

1. In the directory where Drupal is installed, type the following command:

   ```bash theme={null}
   drush sql-dump --result-file=db-backup.sql
   ```

   Drush saves the Drupal database to the *db-backup.sql* file. (You can name the file anything you want.)

2. To restore the database backup, type the following command:

   ```bash theme={null}
   drush sql-cli < db-backup.sql
   ```

   > ❗️ Warning
   >
   > Be careful! This command completely overwrites the existing Drupal database with the database contained in the backup file.

## Backing up and restoring a Drupal site

Backing up and restoring entire Drupal sites is easy with Drush. A backup includes all Drupal site files, databases, and code in one compressed file.

To do this, follow these steps:

1. In the directory where Drupal is installed, type the following command:

   ```bash theme={null}
   drush archive-dump
   ```

   Drush backs up and compresses the Drupal site. When Drush completes the backup, it indicates the path and filename where the backup file is located.

   > 🚧 Important
   >
   > We strongly recommend you copy the backup file to a location that is not on the server. It is a sound administrative practice to maintain multiple backups in multiple locations.

2. To restore the site backup, type the following command in the directory where Drupal is installed. Replace */path/filename.tar.gz* with the complete path and name of the Drupal backup file:

   ```bash theme={null}
   drush archive-restore /path/filename.tar.gz
   ```

## Clearing Drupal caches

There are times, particularly during site development, when you may want to clear out Drupal's caches. To do this, type the following command in the directory where Drupal is installed:

```bash theme={null}
drush cache-clear all
```

## Rebuilding the Drupal search index

Drupal rebuilds its search index at fixed times according to a cron job schedule. However, you can instruct Drupal to immediately rebuild the search index. To do this, type the following command:

```bash theme={null}
drush search-reindex
```

When you are prompted, type `y` to continue.

<Warning>
  **Important**

  Depending on the size of your site, rebuilding the search index may take some time. You should try to limit index rebuilding to off-peak times.
</Warning>

## More information

For more information about Drush, please visit [http://drush.org](http://drush.org).

## Related articles

* [Installing Drush manually](/docs/installing-drush-manually)

* [Configuring Drush site aliases for Drupal](/docs/configuring-drush-site-aliases-for-drupal)
