The Absolute Beginner’s Guide to Drush

Drush

Drush is a great tool for quickly managing routine tasks with a Drupal installation.

Drush allows you to search the drupal.org site, install Drupal, install modules, enable modules and much more.

This is going to be a tutorial aimed at Drush beginners. We’ll explain how to install Drush, how to use it and how to perform some common tasks.

Some Notes Before We Start

  • In this tutorial, we’re working with a Drupal site that is already installed. To follow this tutorial, have a Drupal site to practice on and please make sure it’s one you don’t mind breaking!
  • This tutorial explains only of several ways to use Drush. Using PEAR is another recommended method and explained on the Drush download page.
  • Even though Drush is listed as a module on drupal.org, it’s not actually a module. It is something you will need to install on your server, not upload through Drupal’s module management.
  • If you are familiar with using shell access and the command line for doing things like copying, moving, backing up, and installing, you’ll get the hang of Drush right away. If you’re not familiar with either, don’t worry if the concepts in this tutorial are confusing at first. With our help and some persistence, you will get the hang of it quickly.
  • Yes, this tutorial is a simplification, perhaps even an over-simplification. This tutorial is called the Absolute Beginner’s Guide to Drush for a reason. It’s a simple introduction to a complex topic. Those expecting a great level of detail are advised to visit http://drupal.org/node/477684″>this Drupal.org page.

Step 1: Setting up SSH Access

To access the server directly from your computer you will need shell (SSH) access.

What is SSH? Technically, SSH allows you to control another computer (ie, your web server) over the Internet through a command line interface (CLI). SSH is actually included by default on many Mac and Linux computers.

You will probably need to get your hosting company to enable SSH for you. Most hosting companies won’t have this turned on for you.

Step 2: Install PuTTy and Connect

There are many ways that you can connect to your site using SSH, but in this example we’re going to use Putty.

tutuploadsmedia_1340717521170.png
  • As soon as you enter your host name and click Open, you’ll be taken to the command line screen. This will be a black screen with white text as in the image below.
  • Putty will ask you for your login username and password. This will often be identical to your FTP login or hosting account login.
tutuploadsmedia_1340722166971.png
  • You’ll know that you logged in successfully if you get a message like the one below. That means that you’re connected and ready to start work. If you get an Access Denied message, you’ll need to try your details again.
ostraining@ostraining.com [~] #

Step 3: Download Drush

  • Go to http://drupal.org/project/drush.
  • Right-click on the download link for Drush. You want to copy the URL link. It will look like this: http://ftp.drupal.org/files/projects/drush-7.x-5.4.zip
  • Paste this into Putty.
wget http://ftp.drupal.org/files/projects/drush-7.x-5.4.zip
  • That command will run and should tell you that it connected to Drupal.org and saved Drush:
tutuploadsmedia_1340723047979.png

Step 4: Unzip Drush

  • Enter the command below and that will extract the zipped Drush file that’s on your server.
unzip drush-7.x-5.4.zip
tutuploadsmedia_1340723003471.png

Step 5: Change Drush’s Permissions

  • For security reasons, by default you will not have permission to use Drush. The following command will allow your system to use Drush:
chmod u+x ~/drush/drush
  • You can also do this via FTP. Find the file called Drush and set it’s permissions to 744.

Step 6: Tell your System Where Drush is

  • The following command will give your system the information it needs to access Drush.
  • Be careful with the path. You are looking for the path to drush.php. If you have the wrong path, you’ll get an Access Denied error. Try again with a new path.
export PATH="$PATH:/home/example/drush/drush:/usr/local/bin"

Step 7: Flush the Cache

  • The following command will reset your system so that it is ready to use Drush:
source .bashrc

Step 8: Check that Drush is Working

  • Run this command to check if Drush is working:
drush status
  • If Drush is working you will see a result like the one below. If Drush isn’t working, go back and check the earlier steps.
PHP configuration : /usr/local/lib/php.ini
Drush version : 5.4
Drush configuration :

Step 9: Browse to Your Drupal Files

  • In the example below, our Drupal site is in the /shell/ folder. Adjust this command to navigate to the folder where you have Drupal installed:
cd /home/public_html/shell/
  • You will know you’re not in the root any more because the next line will read:
[~/public_html/shell]#

Step 10: Download a Module

  • Now let’s test out our Drush install by trying to install a module. This command will download the Token module:
drush dl token
tutuploadsmedia_1340724253007.png

Step 11: Enable a Module

  • Now let’s try to enable that Token module:
drush en token
tutuploadsmedia_1340724233092.png

More Common Drush Commands

Congratulations. If the download and enable commands work for you, then you’re ready to use Drush.

We have seen several common Drush commands above. There is an entire list of the Drush commands at http://drush.org. Here are some of the most popular:

  • drush dl     Download and install a drupal module. This defaults to the sites/all/modules directory.
  • drush en     Enable a module
  • drush dis     Disable a module
  • drush up    Check for available updates, download updated modules, and run update.php
  • drush up     Check to see if the specific module needs updating, and if so, download it and run update.php
  • drush sql-dump –result-file=db-backup.sql    Dump the entire Drupal database into a file called db-backup.sql. In other words, backup your database.
  • drush sql-cli < db-backup.sql    Connect to the database server and run the commands in db-backup.sql. In other words, restore the database from db-backup.sql
  • drush cc all    Clear all caches
  • drush vset preprocess_css 0 –yes    Turn off CSS caching. This is useful when developing themes.
  • drush vset preprocess_js 0 –yes    Turn off JavaScript caching
  • drush cron    Run cron
  • drush vset site_offline 1 –yes    Put a site into maintenance mode (D6 only)
  • drush vset maintenance_mode 1 –yes    Put a site into maintenance mode (D7 only)
  • drush vset site_offline 0 –yes    Take a site out of maintenance mode (D6 only)
  • drush vset maintenance_mode 0 –yes    Take a site out of maintenance mode (D7 only)

Author

0 0 votes
Article Rating
Subscribe
Notify of
9 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Guest
Guest
11 years ago

hello everyone !

can anyone tell me how can i create our theme in drupal 7….

plz help me….plzzzzzz…i m new in drupal cms developement

picturina
picturina
11 years ago

Hi Guest #1.

I’m a casual visitor, and it sounds like you are posting your request in the wrong place. If you have a Photoshop file that you want to translate into a working Drupal website, try Googling “Photoshop to Drupal.” Good luck!

sakhmedbayev
11 years ago

Hello,

Thanks for the great tutorial. However, I have question.

What would be instruction for VPS? I have root access to the VPS. Where should I install Drush?

Heidi89
Heidi89
10 years ago

Thankyou for the very clear tutorial – is there information about using this process from behind a proxy server?

eVagabond
eVagabond
10 years ago

Thanks a lot for this immensely helpful resource.

Rafayel
Rafayel
10 years ago

Hello all

Thanks for a good post

I am new in Drush,

so, I installed Drush-5.8 on Windows, it works. But when I want download new project (drush dl), I am getting “Could not download project status information from [url=http://updates.drupal.org/release-history/drupal/7.x]http://updates.drupal.org/r…[/url]”

Cam anyone help me?

Thanks and sorry for my bad English:)

Shashank Kankar
Shashank Kankar
6 years ago

Drush command terminated abnormally due to an unrecoverable error.
[urlcomment image]https://uploads.disquscdn.c…[/url]

Bala
Bala
5 years ago

Hii Everyone!
 I am in a need of conversion of a webpage that was created using Drupal to AEM(Adobe Experience Manager) i.e content migration from Drupal to AEM and my requirement is that content migration has to be done using Drush scripts. Please Let me know If anyone know how to do the content migration

Pendres
Pendres
3 years ago

what should be the export path if it’s installed under /drush folder?
I followed all the steps twice, with different paths and finally when I do [b]drush status[/b], it says:

[code]wwwzacks@mi3-sr17 [~]# export PATH=”$PATH:/home/drush”[/code]
[code]wwwzacks@mi3-sr17 [~]# drush status[/code]
[code]-bash: drush: command not found[/code]

9
0
Would love your thoughts, please comment.x
()
x