fromMarch 2013
Article:

Drush: The Swiss Army Knife for Drupal

Part One: The Can Opener
0

Part One: The Can Opener

If MacGyver were a Drupal developer, Drush would be his Swiss Army Knife.

For the record, "Drush" is a mash-up of the "Dru" from Drupal and "sh" from shell. Functionally, Drush marries Drupal to the world of the command line. Even if you are not a command line junkie, you will find Drush very easy to use; in fact, you'll wonder how you ever managed without it.

Installation

Swiss Army KnifeDrush itself isn't a module; it is installed on your server independently of any Drupal site. Though it's designed for a *nix flavor OS, it can still be installed on Windows — although some functionality will be missing. (To use Drush on Windows, follow these instructions: http://www.drush.org/drush_windows_installer.)

For the rest of us, there are a couple of installation methods available, but my personal favorite is Pear. I like using Pear to install and update Drush because, like Drush, it takes a lot of the labor out of the task of maintaining it. Assuming you already have Pear installed on your server, here's what to do:

pear channel-discover pear.drush.org
pear install drush/drush

Drush will also need Console Table to run. If you need it, just run the command below to install it.

pear install Console_Table

To check to see if Drush installed, try the following:

which drush

This should return something like this:

/usr/local/bin/drush

If you don't have Pear available or are on a shared host, you will want to refer to the readme.txt file1 for other install methods.

Usage

Now that we have Drush installed we can start the fun. Let's assume you want to install a new site. Change directory to your web root or where you'd like the site to live on the server. Issue the following command:

drush pm-download drupal

In the above command, you asked Drush to download the latest version of Drupal via the command "pm-download". If you're anything like me, you're thinking, "That's too much typing." But don't worry, there's an alias: Next time, instead of typing "pm-download" just type "dl" instead.

Drush has now placed the current version of Drupal in a directory relative to your location. So, if the current version of Drupal is 7.18, then the directory will be named "drupal-7.18". Rename the directory or move its contents to the desired location.

Now, change directory to the Drupal root, the same directory that contains install.php. I'm going to assume you're planning on using MySQL and have already setup an empty database and user. The DB user and password are the very minimum you need to install a new site.

drush site-install –-db-url=mysql://dbuser:<a href="mailto:password@localhost">password@localhost</a>/dbname

The above command will install your site using the "minimal" install profile and give you the username "admin" for the user 1 account. After install, the results on screen will provide you with a randomly generated password so you can log in with the newly created user.

But let's say you want a little more control over the install. Okay, this time, let's provide a different username, site name, install profile, and an e-mail address. The command will now look something like this:

drush site-install standard –-db-url=mysql://dbuser:<a href="mailto:password@localhost">password@localhost</a>/dbname -–account-name=jeremy -–account-mail=<a href="mailto:myname@example.com">myname@example.com</a> –-site-name="My Awesome Site"

Now that we have a site installed we can extend core by downloading and installing some contributed modules. To download them you only need their project names. For example, if you want to install the Admin Menu module you can find its project name by going to the project's Drupal.org page (http://drupal.org/project/admin_menu) and using everything after "project/": in this case the project name is "admin_menu".

To download this module and additional modules in the same command, you separate the project names with a space, like this:

drush pm-download admin_menu views ctools

The result will show you a list of all the downloaded modules available in each package and now you can enable the modules you want to use:

drush pm-enable admin_menu admin_menu_toolbar ctools views views_ui

Notice that I didn't just enable Views; I enabled both Views and Views UI. Projects that come packaged with multiple modules are downloaded with a single project name, but to enable all the modules in the same package you will need to type out each module's machine name (e.g.: views_ui for Views UI). I also want to point out that the command "pm-enable" has an alias too. Try using "en" next time.

You can always find out more information about any available command right in the console using help. Just run a command similar to this:

drush help pm-download

Drush will return a description, the available options and arguments, and often an example. Find help on any command by replacing the above "pm-download" with any command you want to learn about. You can also find out more about these commands at drush.org.

You might not be a Drush master at this point, but you are right on track. Don't worry, young MacGyver, this was just enough to get you started — only one blade in your Swiss Army Knife. There is more to come in the next issue. Until then take what you learned here and give it a try.

Image: http://istockphoto.com/in.focus

Advertisement

From our blog

Entity Storage, the Drupal 8 Way

In Drupal 7 the Field API introduced the concept of swappable field storage.

The Drupal 6 to 8 Upgrade Challenge - Part 2

Having concluded the readiness assessment, we turn next to migrating the content and configuration. In reality, there’s little chance that we would migrate anything but the blogs from our old site. For the sake of giving Migrate in Core a workout with real conditions, however, we’re going to upgrade with core’s Migrate Drupal module rather than rebuilding.

The Drupal 6 to 8 Upgrade Challenge - Part 1

Nathaniel Catchpole , the Drupal 8 release maintainer and Tag1 Senior Performance Engineer, suggested that Drupal shops everywhere could support the

DrupalCon Austin

The entertainment industry is not for the faint of heart.

Drupal Watchdog Joins the Linux New Media Family
Drupal Watchdog 6.01 is the first issue published by Linux New Media.

Drupal Watchdog 6.01 is the first issue published by Linux New Media. Come see the Drupal Watchdog team at DrupalCon 2016!

Drupal Watchdog was founded in 2011 by Tag1 Consulting as a resource for the Drupal community to share news and information. Now in its sixth year, Drupal Watchdog is ready to expand to meet the needs of this growing community.

Drupal Watchdog will now be published by Linux New Media, aptly described as the Pulse of Open Source.

Welcome to DrupalCon Barcelona - The Director's Cut

For all you schedule-challenged CEOs – and ADHD coders – this Abbreviated Official Director’s Cut is just what the doctor ordered.

Welcome to DrupalCon - The Barcelona Edition

Did we have fun in Barcelona?
OMG, yes!

Did we eat all the tapas on the menu and wash them down with pitchers of sangria?
Yes indeed!

Recursive Closures and How to Get Rid of Them

This came up while manipulating taxonomy children and their children recursively, so it’s as not far from Drupal as you’d think.