Drush

Last modified: June 20, 2008 - 02:09

Introduction

drush is a command line shell and Unix scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those of us who spend most of our working hours hacking away at the command prompt.

drush.module itself doesn't provide any actual tools or commands but the API for those. There are several modules that provide drush utilities included in the drush download. These include Package Manager, SQL Tools, and Toolbox.

Installation

Linux/Unix/Mac

  1. Untar the tarball into your module directory (sites/all/modules)
  2. Enable drush.module and any submodules you want to use. You must enable the CVS or wget modules if you want to install modules (you do).
  3. (optional, but recommended:) To ease the use of drush, - create a link to drush.php in a directory that is in your $PATH, e.g.: $ ln /path/to/drush.php /usr/bin/drush OR - create an alias to drush.php: $ alias drush='php modules/drush/drush.php' (this goes into .profile or .bash_aliases in your home folder)
  4. Start using drush by running "drush" from your Drupal root directory. (or, if you did not follow step 3, by running "./sites/all/modules/drush.php" or navigating to sites/all/modules/drush and running "./drush.php" ) If you have troubles, try using the -l and -r flags when invoking drush.php. See below.

Windows (experimental!)

  1. Untar the tarball into your module directory (sites/all/modules)
  2. Enable drush.module and any submodules you want to use. You must enable the CVS or wget modules if you want to install modules (you do).
  3. Use drush by navigating to sites/all/modules/drush and running 'drush.bat'. If drush.bat is not working for you, either add the directory in which your php.exe resides to your PATH or edit drush.bat to point to your php.exe.

Usage

Once installed and setup (see above), you can use drush as follows while in any Drupal directory:

$ drush [options] <command> <command> ...

Use the 'help' command to get a list of available options and commands:

$ drush help

Please note that drush requires a working drupal setup in order to function correctly. So for multisite installations, you might need to use the -l or other command line options just to get the help command to work:

$ drush -l http://association.drupal.org/drupal help

Related Options: -r <path>, --root=<path> Drupal root directory to use (default: current directory) -l <uri> , --uri=<uri> URI of the drupal site to use (only needed in multisite environments) -v, --verbose Display all available output If you get tired of typing options all the time, you can add them to your drush.php alias or create a drushrc.php file. These provide additional options for your drush call. They provide great flexibility for a multi-site installation, for example. See example.drushrc.php.

drush Commands

Here are some of the commands you can use with drush:

  help                  View help. Run "drush help [command]" to view command-specific help.
  pm install            Install one or more modules

  pm refresh            Refresh update status information

  pm update             Update your modules

  sql url               Print database connection details.

  sql version server    Print database server version number.

  sql version client    Print database client library version number.

  sql dump              Exports the Drupal DB as SQL using mysqldump or pg_dump.

  sql query             Execute a query against the site database.

  sql load              Copy source database to target database.

  cache clear           Clear all caches

  cron                  Run cron

  watchdog show         Show the most recent watchdog log messages

  watchdog delete       Delete all messages of a certain type

  sync                  Rsync the Drupal tree to/from another server using ssh

Requirements

To use drush from the command line, you'll need a CLI-mode capable PHP binary. The minimum required PHP version is 4.3.0 (PHP 5.x is OK, too). drush should also run on Windows, however, drush modules might make use of unix command line tools, so to use it effectively, you have to install some of them, e.g. from GnuWin32 (http://gnuwin32.sourceforge.net/). The READMEs of the individual modules should state which binaries are required.

FAQ

Q: What does "drush" stand for?
A: The Drupal Shell.

Limitations

Due to reliance on PHP's tokenizer, drush may not work well in situations where the PHP code for the Drupal code base is encrypted (refer to API.txt for more information). This is unlikely to change.

 
 

Drupal is a registered trademark of Dries Buytaert.