[Drupal] What is the need of drush in Drupal

By | 24th Apr 2015 | 3 min read

Imagine if your Drupal site has more than 30-50 modules and you wanted to update them all or you want clear all Drupal cache. If you do it manually just by unzipping and run update.php or just click the clear cache it may takes more time. Hence if you can do this all process in one single command it will be easier for a developer. Here we can use drush commands to do all work with a single command and in few seconds.

  • drupal.org says a "Drush is a command line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those of us who spend some of our working hours hacking away at the command prompt".
  • You can also view thing s like downloading a new module, installation location, site activity.
  • When it comes to module you can enable, disable, install and uninstall.
  • You can update the Drupal core and run update.php as well as you can upgrade to a newer version very easily.
  • Drush can also be used to run cron, clear cache and creating a search index.

Here are some useful drush commands

  1. drush cron : Run cron
  2. drush cc all : Clear all caches
  3. drush cc : cache clear
  4. drush dis : disable module eg: drush dis profile2
  5. drush dl : download project or module eg: drush dl profile2
  6. drush vset maintenance_mode 1 --yes Put a site into maintenance mode (D7 only)
  7. drush vset preprocess_js 0 --yes : Turn off JavaScript caching
  8. drush vset maintenance_mode 0 --yes Take a site out of maintenance mode (D7 only)
  9. drush vset site_offline 1 --yes : Put a site into maintenance mode (D6 only)
  10. drush vset preprocess_css 0 --yes : Turn off CSS caching. This is useful when developing themes.
  11. drush en : enable module eg: drush en profile2
  12. drush vset site_offline 0 --yes Take a site out of maintenance mode (D6 only)
  13. drush status or drush st: Provides a bird's eye view of current Drupal install.
  14. drush up : Check for available updates, download updated modules, and run update.php
  15. drush sql-dump--result-file=db-backup.sql : Dump the entire Drupal database into a file called db-backup.sql.
  16. drush sql-cli < db-backup.sql : Connect to the database server and run the commands in db-backup.sql.

To download and install.

  1. In your Linux machine type the following command.
  2. sudo apt-get install drush

Some other useful tips regarding drush are, to download a Drupal you can use "drush dl drupal" or " drush dl drupal-7.x" to download a particular version.

To install a site you can use.

  1. drush dl drupal --drupal-project-rename=example
  2. cd example
  3. drush site-install standard --db-url=mysql://[db_user]:[db_pass]@localhost/[db_name] --site-name=Example

It will create the database for you if the db_user above has the privileges to. For more information you can go to drush.org.Thank you for reading!.