Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Drush Made Simple

Parent Feed: 

The word Drush is a combination of two words: drupal + Shell.
A shell is a command line tool that lets us manage our website by writing commands.

Why should you use it?

Drush is a Drupal developer's best friend, it makes your life easier.
Instead of hovering around the interface, Drush is an excellent alternative tool for doing various tasks with Drupal using commands. Save yourself from all those page clicks and more!

Here are some of the main reasons why you should use Drush.

  • Drush is faster to use. Using the interface you need to load pages, click on menus, look for the information. With Drush, you look for a command using drush help, and that’s it. 
  • Drush is faster for PHP to execute. No need to load the website interface, it goes straight to PHP, no browser needed.
  • You can automate things. With drush you can make a script to enable ten modules in a row, apply some updates, clear the cache … etc. Any command from drush, can be make as part of a script.
  • Avoid mistakes. A wrong click? Not possible with Drush.

Still not convinced? 

A quick example of a task is downloading and enabling a Drupal module.
Without drush:

  • Download the module in drupal.org,
  • Go to your website in home > admin > module, click choose file,

Choose the downloaded module from the ‘Downloads’ folder in your computer’ and then click install.

Screen Shot 2017-08-19 at 12.16.11 AM.png
With Drush: you just have to write two lines of code in the command line tool to do this task.

$ drush pm-download modulename

In the command, "pm-download" can be shortened to "dl".
 

$ drush pm-enable modulename

Note that the “modulename” is refereing to the module’s machine name, as in the module’s URL. Example: the machine name of the “Chaos tool suite” module is ctools, it’s URL is https://www.drupal.org/project/ctools.
In the command, “pm-enable” can be shortened to “en”.

​​​​​Two commands and some minutes saved!

Drush is really pupular and stable. As of July 6 2015, the Drush project had already been downloaded 1,531,560 times.

Install Drush

Install Drush using Composer:

The recommended way to install Drush is to use Composer, because it will be easier to keep Drush up to date. Composer will manage Drush as a dependency. Read more about composer on: https://getcomposer.org/doc/.

Also, installing with Composer will be the only option moving forward, as noted on Drush’s website (http://docs.drush.org/en/master/install/): “Note: Drush 9 (coming soon!) only supports one install method. It requires that your Drupal 8 site be built with Composer and Drush be listed as a dependency”.

If you project is not using Composer:

$ drush pm-enable modulename


If your project is already using composer:

$ drush pm-enable modulename


Then install the Drush launcher: https://github.com/drush-ops/drush-launcher.

To test if you had successfully downloaded and installed drush, open your terminal, type drush help and hit enter. You should see a long list of drush commands along with descriptions on what each of the commands do. You can shorten the list of drush commands and target specific result with the help of “grep” and keywords.
For example, if you are looking for the command to enable modules, you can use “enable” as your keyword:

$ drush pm-enable modulename


What about Drupal Console?

A tool became popular with Drupal 8 and it’s called Drupal Console. It can do a lot of things in a similar way as Drush, but it has a different focus. 

Drush has been around for a very long time and has a lot of options available. Drush aim at helping the site builder into regular maintenance or administration tasks. On the other hand, Drupal Console is more modern and came for the version 8 of Drupal (if you know Symfony, you won’t be lost with Drupal Console). 

Drupal Console focuses more on helping the Developers. You can do some administration tasks like enabling a module, but not as many as Drush. But Drupal Console can, for example, generate PHP code for you. This is more helpful for Developers than for maintenance tasks. Both can work together, so you can always install Drupal Console as well. But this will be another article ;)
 

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web