Ian Hoar – Passion for Technology – Geeking Out - Technology, Web, Toys, Games, Design, Entertainment, Gadgets, & Geeking Out

How to use Drush with Drupal

DrupalI was recently at Drupal Camp Toronto which is a conference on Drupal. It was a fantastic place to learn about what other modules and strategies people are using with Drupal. Having only created a couple of Drupal sites myself, it was great to be around so many people that build Drupal sites for a living. Out of everything I learned at Drupal Camp the single most amazing tool had to be Drush. I still have a lot other modules to research that I learned about from the conference and Drush isn’t even really a module, but it’s still a lot of awesome.

What is Drush?

Drush has been around for awhile now, but if you are like I was only last week and don’t know what it is, and you run a Drupal site, this tool will make your life a lot easier. Drush is a command line PHP script for seeing the status of your Drupal site and updating it extremely fast among other things. If you have a Drupal site, chances are you may have many modules, and one day Drupal pops up a mean warning about the core not being up to date, security and vulnerability issues, and 25 modules are out of date. Done the traditional way this is a nightmare that includes downloading each module from the Drupal site, unzipping them, copying them over to your modules directory and updating your database where needed.

My Drupal site was always out of date, which was not wise. Why did I let it get out of date? The answer is time, it takes a long time to download all the modules, unzip them and then run the database updates, especially through the Drupal admin. This is where Drush comes in. It does all this lightning fast and it’s completely automated. It will download everything that has a problem and like magic, apply all the necessary updates to the Drupal core and modules, and it will do this all with a single command.

I’m interested! Lets get started!

These directions will work on Linux and Mac OS boxes. The first thing to do is download Drush. Go to the Drush download and right click the version you want and select copy link. Then SSH into your account.

ssh -l username yoursite.com

Download the file you copied earlier with wget:

wget http://ftp.drupal.org/files/projects/drush-6.x-3.3.tar.gz

Extract the files:

tar -xvf drush-6.x-3.3.tar.gz

You should now have a drush directory in your home directory. Next create a symbolic link to drush so you can use the script within your Drupal site.

ln -s /home/youruser/drush/drush /home/youruser/bin/drush

Now change directories into the Drupal site you want to play with. To get a list of commands you can type drush, you can also go to the Drush help site.

To test it out try:

drush pm-list

This will list all versions of all your modules and themes. If you wanted to see only your disabled modules and themes you could type:

drush pm-list --status="disabled"

Now for the magic. Before doing this make sure you have a backup of your site, you do make backups before updating your site right? I only ask because some people like to live on the edge.

drush pm-update

This will display update information and prompt you to continue. You can bypass prompts by typing:

drush pm-update --yes

You will not be prompted and everything will be updated. This is useful for when you have a lot of modules to update. The command pm-update has a lot of other options you can check out in the manual. The other great thing about Drush is that it makes backups too. That said I still recommend reading over the documentation before trying anything on a large production site. This tutorial has only scraped the surface of Drush, I hope you find it as fantastic as I have.

Your comments are important, join the conversation