Last updated 2 May 2016. Created on 23 July 2010.
Edited by mr.ashishjain, ashish_nirmohi, attheshow, xurizaemon. Log in to edit this page.

There is a lot of information about drush in various places around drupal.org and elsewhere; this page is an attempt to pull some of it together.

Drupalize.Me has a quick video overview of Drush and why all Drupal developers can benefit from using it. What is Drush?

If you have questions about drush that are not answered here, the best thing to do is to check the drush issue queue, and ask there if you can't find an existing issue that addresses your problem. There is also a lot of information available in the drush help command, and a great deal of information can also be found in the drush topic command.

Installing and Troubleshooting Drush

  1. Where do I start?

    A: Look at the README.md for installation and usage instructions. You might also find additional information directly relevant to your system on the page specific instructions for installing Drush on different platforms.

  2. Drupalize.Me has a free video that offers detailed, step-by-step instructions for installing Drush on machines running some flavor of UNIX (including OSX)... Installing Drush on Unix Systems

  3. My Drupal site is working, but I get out-of-memory errors when I use Drush. What is wrong?

    A: Separate php.ini files may be used for your web server and command-line installations of php. Make sure that the memory configuration settings in your cli's php.ini match the values in the webserver php.ini.

  4. How can I determine which php.ini file Drush is using?

    A: This information is shown by the drush status command.

  5. Can I tell Drush to use a specific php.ini file?

    A: Yes; copy the php.ini file that you would like to use to $HOME/.drush or /etc/drush. See the README.txt for more information.

  6. How can I force Drush to use a specific version of php, e.g. when there are multiple versions of php installed?

    A: In your .bashrc, put: export DRUSH_PHP=/usr/bin/php-cli, then run source .bashrc. See also Modifying the PHP

  7. I have installed a Drush command and I know it's there, but Drush reports that the command cannot be found. Why is that?

    A: Try clearing the Drush command cache with drush cc drush.

Using Drush on Shared or Managed Hosting plans

  1. I am getting an error: /bin/uname: Permission denied

    A: Drush only uses the uname script to determine if you are running on cygwin. If uname is not available, or if you cannot run it, you could always provide your own placeholder uname script. See: http://drupal.org/node/1784174

Installing Drupal

  1. Does site-install work with Drupal 6.x?

    A: Yes. It even supports install profiles in drush 4.5 and drush 5.x-dev.

Using drush with Windows

  1. Does drush work on Windows?

    A: For the most part it does, but there are some issues. See the list of open windows issues.

Using drush to update / upgrade Drupal

  1. Do I need to disable all of my non-core modules before doing a minor update of Drupal with drush?

    A: No. See #859426: process of upgrading core. (there is a better reference)

  2. Can pm-update be run on a multisite?

    A: Yes, but it is better to run pm-update on each site individually, and test thoroughly. You should do the update on a test site, not the live site, and you must deploy the updated code to all sites at the same time. See #1842816: Best practice for multiple servers.

  3. Why does updatecode fail with "rename(): The first argument to copy() function cannot be a directory"?

    A: Upgrade to Drush 4 or later. See #803386: updatecode requires modules dir and backup dir to be on the same volueme (updatecode.pm.inc on line 210) for history.

  4. Will pm-updatecode always remove a module's external dependencies?

    A: Yes. See #487584: drush update causes modules' external dependencies to be removed.

  5. Can I force pm-updatecode to always skip certain modules that I do not want to update, then?

    A: Yes, by using update_advanced, see Excluding projects from updatecode. Drush also has internal support via "--lock". See #446736: Have drush update be told to ignore a module/theme -- simple solution.

  6. Will pm-updatecode drupal preserve custom installation profiles?

    A: Yes. See #827404: drush up drupal does not preserve custom profiles.

  7. Can pm-updatecode be used to update the modules in a custom installation profile?

    A: No. See #827404: drush up drupal does not preserve custom profiles.

  8. Can I use pm-updatecode to update to a non-recommended release?

    A: No. See #1880362: drush up for updating distributions.

  9. Do I need a Drupal site with a valid database to upgrade modules?

    A: Yes. See #830572: Package management outside of a Drupal install.

  10. Can I use drush to update drush?

    A: Yes, with drush pm-download drush --select.
    You can also use drush selfupdate in Drush 4 to have Drush update itself. This does not work in Drush 5.
    If you used pear to install drush, update with: pear upgrade drush/drush

  11. Can I use drush to do a major version upgrade, e.g. from Drupal-6 to Drupal-7?

    A: Yes, with the drush_sup project.

Using drush to synchronize Drupal installations

  1. Does sql-sync work with table prefixes?

    A: NO. See #625870: drush sql dump and table prefixes.

  2. Can I use wildcards to tell sql-sync and sql-dump which tables to include or skip?

    A: Not always. This feature is native in Postgres, but not in Mysql. See #698264: Better handling of structure-tables and skip-tables options (including cache_* support!).

  3. How can I sanitize the database after a sync from live to dev, for example, to remove user email addresses?

    A: Drush 4 and later can do this with --sanitize option on sql-sync command. Commandfiles can add custom sanitize routines. See #861822: Add an option to sanitize email addresses and passwords from user table post sql-sync..

  4. Can I use sql-sync to copy one kind of database to another, e.g. to copy a Drupal site using mysql to a postgresql database?

    A: No, but you can use the dbtng_migrator project to do the conversion.

  5. How can I stop a developer from accidentally syncing over the sql database of the live site?

    A: See #854722: Protecting a site from having it's database overwritten..

  6. Does Drush provide a comprehensive mechanism for deploying sites that handles code, database and files with rollbacks?

    A: Yes, see the drush_deploy project.

  7. I am getting an error: bash: drush: command not found with drush sql-sync, but I can use Drush on the same machine when remotely logged in.

    A: Make sure that the path to Drush exists in your PATH, and that the command that sets the path is executed in non-interactive shells. You can also set the path to Drush inside your site alias. See: http://drupal.org/node/955882

  8. Why do I see the message stdin: is not a tty when using sql-sync or other Drush commands with my remote server?

    A: This can happen when your .bashrc or other shell configuration file is not set up correctly for non-interactive shells. See: http://drupal.org/node/1783330

Extending Drush

  1. How do I write a new Drush command?

    A: Check the COMMAND section in the README.txt file, and look at the sandwich.drush.inc example. Also, the core commands in drush are good models for your own commands.

Miscellaneous questions

  1. How do I use variable-set with arrays?

    A: See #664452: use variable-set with arrays and objects. Accept JSON via STDIN like cache-set.

  2. Can I use drush to read release notes from drupal.org?

    A: Yes; use the pm-releasenotes command.

  3. Can I use drush to generate release notes?

    A: Yes; use the grn (git release notes) project. n.b. grn does not have a 7.x release; use drush dl grn-6.x to download it. It will work with git repositories for any Drupal version.

  4. Can I use drush to apply patches from the project's issue queue on drupal.org to my local projects?

    A: Yes; use the drush_iq project.

  5. Can I use drupal.org git with drush?

    A: Yes. Set --package-handler=git_drupalorg.

  6. Does drush have any unit tests (to test itself)?

    A: Yes. See the /tests subdirectory in drush 4+. The tests use the PHPUnit framework.

  7. Is bash autocompletion available for Drush?

    A: Yes; see drush.complete.sh in Drush 5+.

  8. Shouldn't Drush output errors to stderr instead of stdout?

    A: Yes, and on Drush 4+ it does. See #639204: drush_log() should write to stderr, not stdout, and $green should actually be green..

  9. Can Drush help me move enabled projects from one location to another (e.g. from sites/all/modules to an installation profile, or from a site-specific modules folder to sites/all/modules)?

    A: Yes; use the registry_rebuild project to fix up Drupal's registry afterwards.

  10. Can I run Drush from cron?

    A: Yes; see drush topic docs-cron and #715480: Can't run drush from cron.

  11. Can I use Drush to reset the Drupal admin user's password?

    A: Yes; use the drush user-login command.

  12. Can I use Drush to run arbitrary php code on a Drupal site?

    A: Yes; use the drush php-eval or drush php-script commands; also, see drush topic docs-scripts and #600556: Interactive PHP Shell.

  13. Can I use Drush to run the cron task of a specific module?

    A: Yes; use drush php-eval 'MODULENAME_cron()'.

  14. Can I make my own shortcuts for Drush commands?

    A: Yes, using the Drush shell alias feature. See drush topic docs-shell-aliases

  15. Is there a way to know bootstrap is from Drush in my modules?

    A: function_exists('drush_main') may be used by modules to detect whether they are being called from drush. See http://drupal.org/node/1181308 and http://drupal.org/node/827478

  16. How can I save the --debug output from Drush to a file?

    A: Use the GNU "tee" command. drush status --debug 2>&1 | tee /path/to/debug.txt. See http://drupal.org/node/1896846

  17. How to keep admin/reports/updates still working when using Drush & GIT?

    A: This has two steps:

    1) For downloading you need the --package-handler=git_drupalorg and --gitinfofile options

    e.g. > drush pm-download MODULE_NAME --package-handler=git_drupalorg --gitinfofile


    2) For updating you need the --package-handler=git_drupalorg, --gitinfofile and --gitcheckoutparams=-f options plus a hook implementation and a small drush hack.

    e.g. > drush pm-update MODULE_NAME --package-handler=git_drupalorg --gitinfofile --gitcheckoutparams=-f



    If you always want to use git for your site do the following:

    Put the following in sites/all/drush/drushrc.php

    $options['package-handler'] = 'git_drupalorg';
    $command_specific['pm-download'] = array('gitinfofile' => TRUE);
    $command_specific['pm-update'] = array('gitinfofile' => TRUE, 'gitcheckoutparams' => '-f');
    $command_specific['pm-updatecode'] = array('gitinfofile' => TRUE, 'gitcheckoutparams' => '-f');
    

    Put the following in sites/all/drush/MYSITE.drush.inc

    /**
    * Implements HOOK_pm_post_update().
    * NOTE: Bottom section of package_handler_post_download($project, $release) 
    *       from file PATH-TO-PEAR/pear/drush/commands/pm/package_handler/git_drupalorg.inc
    */
    function MYSITE_pm_post_update($project) {
      $release = $project['releases'][$project['candidate_version']];
      if (drush_get_option('gitinfofile', FALSE)) {
        $matches = array();
        if (preg_match('/^(.+).x-dev$/', $release['version'], $matches)) {
          $full_version = drush_pm_git_drupalorg_compute_rebuild_version($project['full_project_path'], $matches[1]);
        }
        else {
          $full_version = $release['version'];
        }
        drush_pm_inject_info_file_metadata($project['full_project_path'], $project['name'], $full_version);
      }
    }
    

    Modify the file PATH-TO-PEAR/pear/drush/commands/pm/updatecode.pm.inc

    /**
     * Run the post-update hooks after updatecode is complete for one project.
     */
    function pm_update_complete($project, $version_control) {
      drush_print(dt('Project !project was updated successfully. Installed version is now !version.', array('!project' => $project['name'], '!version' => $project['candidate_version'])));
      //MOD drush_command_invoke_all('pm_post_update', $project['name'], $project['releases'][$project['candidate_version']]);
      drush_command_invoke_all('pm_post_update', $project);
      $version_control->post_update($project);
    }
    

    And with that you can do the following without breaking the updates report page.

    > dl <MODULE_NAME>
    > up <MODULE_NAME>
    

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

lelizondo’s picture

Servers who have multiple users using drush commands would need a central location to install drush commands and made them available for everybody. Since installing commands at /path_to_drush/commands is not a very good idea, you should install commands at other directory, like /etc/drush/commands or /usr/local/drush_commands

It took me a while but this should work:

1. Copy example.drushrc.php from the drush/examples directory to /etc/drush/commands
2. Rename example.drushrc.php to drushrc.php and edit it.
3. Add this line $options['i'] = '/etc/drush/commands';

What is doing is that you're telling drush to look for command files (*.drush.inc) at that directory.

Test your new command.

Luis

janekD7’s picture

For anyone in the future having sql-sync error (during sync from remote to local):
bash: mysqldump: command not found
Check the .bashrc file on remote server and try to add line:

export PATH="/usr/local/mysql/bin:$PATH"

but add it BEFORE line:

[ -z "$PS1" ] && return

and not at the end of the file. This is because lines after [ -z "$PS1" ] && return are not executed for non-login shells which Drush uses.
Maybe it's obvious but wasn't for me at the time when I needed it.

brycefisherfleig’s picture

After typing in any drush command in the context of my drupal 6 site, drush would print out the html for the site maintenance page on the command line.

I spent a few hours today before I figured out my customized settings.php file was to blame for this. The issue I ran into was that the /sites/default/settings.php uses IP detection to figure out which environment it is running in, and load the appropriate database and php settings.

This approach works really well for loading the one database on during development on my computer, and another one on my production server. However, my IP sniffing logic didn't handle php running CLI (as Drush requires), so drush had no database settings whatsoever.

I updated my IP sniffing logic to explicitly check for php running CLI:

if ( $_SERVER['SERVER_ADDR'] == '127.0.0.1' || php_sapi_name() == "cli") {
//Load database credentials here
}

However, the above code only allows Drush to run locally. It won't work on my production server. Another possible approach would be to create a persistent environmental variable for all servers that the code will run. Then check for the CLI near the top of settings.php, and set a php variable to the value of an environmental variable (ex: DRUPAL_ENV="LOCAL"). Then you could run drush in any server context (local, stage, live, etc). Here's some untested code for doing something like that:

$CLI_ENV = "";
if (php_sapi_name() == "cli") {
    $CLI_ENV = getenv('DRUPAL_ENV');
}

//
//MORE OF SETTINGS.PHP...
//

if ( $_SERVER['SERVER_ADDR'] == '127.0.0.1' || $CLI_ENV == 'LOCAL') {
    //Load in LOCAL database credentials here

} elseif ($_SERVER['SERVER_ADDR'] == '1.2.3.4' || $CLI_ENV == 'STAGE') {
    //Load in LOCAL database credentials here

}

//
//REST OF SETTINGS.PHP ...
//

Hopefully this is helpful to someone!

escoles’s picture

The PEAR install instructions used to be posted on the drupal.org project home page. They no longer are.

This is the most recent version I've been able to find:

https://drupal.org/node/97249/revisions/2791475/view

[note: this will be 'access denied' if you're not logged-in to drupal.org]

littletiger’s picture

What about "drush site-install" for drupal 8?
I run into some problems. WSOD!

apache2 error.log :
"[Thu Dec 11 07:42:15.691003 2014] [:error] [pid 17280] [client 192.168.200.70:58507] PHP Fatal error: Class '__TwigTemplate_ee01b0367cb74bffe41756684bc429e00909240c4ef9dd1d831f5f93568e749a' not found in /var/www/html/projects/tv5m.drupal8b3.dev/core/lib/Drupal/Core/Template/TwigEnvironment.php on line 152"

If I try "drush cr" or "drush cr all" :
exception 'RuntimeException' with message 'Missing $settings['hash_salt'] in settings.php.' in /var/www/html/projects/tv5m.drupal8b3.dev/core/lib/Drupal/Core/Site/Settings.php:130

Permission problems was my first idea.. Set chmod -R 777 ./ for now... Still same problem!! Arrghhhh

littletiger’s picture

Tried installing via the web interface, after specifying database details I also get a WSOD!!

Apache error.log :

[Thu Dec 11 08:47:37.296120 2014] [:error] [pid 17280] [client 192.168.200.70:60509] PHP Fatal error: Class '__TwigTemplate_3e49e312492e90cc90cc9d2146140bd04185fe773f057bdf86c0e2d9e86a16c2' not found in /var/www/html/projects/tv5m.drupal8b3.dev/core/lib/Drupal/Core/Template/TwigEnvironment.php on line 152, referer: http://192.168.200.244/projects/tv5m.drupal8b3.dev/core/install.php?lang...

What is going on? Temporarily broken would be surprising.. Rather something wrong with permissions maybe?
My user owns everything, and apache and my user are in the same group. Because of those problems, I tried with chmod -R 777 *
But still it's like this...

What could be wrong? Please advize... I tried installing Drupal 7.34 and it didn't have any problems installing from command line!...