Linode VPS Hosting, Starting at $19.95/month!

Get 2GB of Free Space from Dropbox

You are here

Drush

Drupal Shell do doo doo do. The Drupal Shell do doo doo do. The Drupal Shell doo doo do doo doo do, do do do do do do do do do do MORE DRUPAL!

Ok, aside from that cool song I just wrote, Drush is officially known as the Drupal shell. It allows you to control many aspects of your Drupal website through command line. Drush is simply a PHP file that allows command line access to many of Drupal's administration features. Drush used to only be available for Linux based operating systems, but now Windows users can enjoy using Drush with the Drush Windows Installer. Drush greatly simplifies and reduces the time it takes to build and administer Drupal websites.

This simple Drush guide assumes that you are running a Debian Linux based operating system such as Ubuntu or Debian Linux, and you have already installed your LAMP stack and have SSH access or command line access to your server. You will also want the PEAR PHP extension installed. If you cannot get PEAR, please see Install Drush the Old Fashioned Way below.

Install/Update - Unix/OSX

The easiest way to install the latest release of Drush on Unix/Linux systems is via our custom PEAR channel. (See below for Windows-specific instructions)

pear channel-discover pear.drush.org
pear install drush/drush

Tip: Use sudo to overcome permission problems. If the channel-discover fails, try running the following sequence of commands:

pear upgrade --force Console_Getopt
pear upgrade --force pear
pear upgrade-all

To update Drush to a newer version later, run: 

pear upgrade drush/drush

Install Drush the Old Fashioned Way

sudo apt-get install php5-cli or

sudo apt-get install php4-cli

set your php5-cli PHP.ini memory limit. In most cases you will run out of the 32MB fairly quickly. Change this to a higher value such as 64MB on smaller servers, or possibly 128MB if you have a larger server.

wget latest stable release from http://drupal.org/projects/drush to a folder on your server. I usually go with an apps folder inside my home directory. Extract the tarball and you should be left with a folder called drush in the folder you chose. For security purposes, we will hide this folder by renaming it to .drush. To do this type mv drush .drush in your command line.

Next you have to create an alias in your .bashrc to drush='/path/to/.drush/drush'. This makes your shell able to call the drush PHP file by just typing drush and then your command. Otherwise, you will have to type the full path for each command, and who wants to do that?

Test to see if your Drush is installed properly by typing drush in the command line. You should receive a list of Drush commands on your screen. If so, you have installed Drush properly and can move on to how to use Drush below.

Using Drush - How to Use Drush

The best feature of Drush is that all of the commands are very simple. In order to download a project to your server, unpack the archive, and delete the archive, all you have to type is drush dl project_name, where project_name is the project you are looking to download. You can also include a string of projects as one command.

Drush dl examples:

  • drush dl cck
  • drush dl cck views admin_menu

Once you have your projects downloaded, you can also enable them through the Drush command line. All you have to type is drush en project_name, where project_name is the project you are looking to enable. In some cases, modules are made up of several smaller modules, and you have to enable each of these modules by name. You can also enable multiple projects at a time by combining them into the command.

Drush en examples:

  • drush en admin_menu
  • drush en admin_menu views

There are many other advanced tasks you can perform with Drush that we will cover later in this article when we have used them more. For now, this should give you some excellent info to get started with Drush. Believe me, you will not turn back to downloading, extracting, and uploading Drupal modules ever again. You might not even want to travel back to the module administration page within the Drupal UI either.

Common Drush Commands

drush dl project_name - Download a Drupal module or Drupal theme to the proper sites/all folder.

drush en project_name - Enable a Drupal module or Drupal theme through command line.

drush dis project_name - Disable a Drupal module or Drupal theme through command line.

drush up - Update Drupal core and contrib projects and applies any pending database updates.

drush up drupal - Updates Drupal core and applies any pending database updates.

drush updb - Applies any database updates.

To see a full list of Drush commands check out the Drush.org.

Each Version of Drush Brings in Some New Commands

Drush was already awesome, but Drush 3 opened a whole new can of whoopass on managing your Drupal website through command line. I happened to catch a sesson at Drupalcon SF 2010 about the upcoming features that were going to be released with Drush 3, and I was thoroughly impressed. Since then, there have been even more commands added that allow you to perform full web server installations, do full backups and restores of your site with database, and more. If you are a command line junky and look for ways to reduce your work overhead, then Drush is for you. Your mind will be blown with how much more power you have over your Drupal websites with Drush. Drush is currently in it's 5th version now, and has more features than ever. You can truly command almost any aspect of your Drupal website from command line at this point.

Drush Make

If you have enjoyed Drush, than you are really going to love Drush Make. Drush Make is a Drush addon that allows you to provision full Drupal installations with a single configuration file called a Drush make file. This make file allows you to setup all aspects of your Drupal site including downloading modules, themes, and setting up configuration of installed modules. Several installation profiles require Drush make to install them properly. Drush make used to be a separate file that you had to install, but is now included with Drush out of the box. Good call Moshe!

More Information on Drush

Here are some other great guides to using Drush.

More Beer, Less Effort - Simple comparison video between installing and enabling modules manually vs. with Drush.

Drush Features Integration - Cool ways to package Drupal site configurations with command line.

All Development Seed Articles Tagged Drush - More Drush information from Development Seed.