Putting This in Action: Installing Modules

Want to start playing with Drush? Let’s go back to our D7 Demo site. Once you’ve installed Drush, open Terminal and navigate to the d7-demo folder using the command cd ~/Dropbox/MAMP/d7-demo. Again, this assumes that you’ve set up your MAMP folder inside a Dropbox folder; if you haven’t, the path will be wherever your d7-demo folder is located on your system.

Now that we’re in there, we’re going to start downloading some modules. For this project, we’ll start with a few basic modules:

Pathauto and Token

Modules that help you automatically create sensible URLs for your site’s content.

Views and CTools

Modules that help create dynamic lists of content on your site. I’ve heard that it’s possible to have a Drupal site that doesn’t require the Views module; however, I have yet to see one.

Block Class

Allows you to add custom classes to individual blocks. This is very useful for theming.

Link

Allows you to create Link fields.

Media

Allows you to create fields to accommodate a variety of media, including video uploads, sharing from YouTube, etc.

Devel

This module gives you some quick links to help during development, including letting you generate placeholder content—very useful if you’re trying to prototype quickly.

For now, we’ll stick with Bartik, the theme that comes pre-installed with Drupal 7. If, however, we wanted to download a new base theme along with these modules, we could do that as well, and Drush would install the theme in /sites/all/themes.

To download our modules, we would enter the following into Terminal (remember, we’re in our d7-demo folder):

drush dl pathauto token views ctools block_class link media devel

Click Enter, and you’ll see something like what’s in Figure 3-4.

Now, we can enable the modules that we need—either by checking them off in the Modules screen (admin/modules), or through Drush by adding the code drush en module_name. Let’s try the latter. Enter the following code:

drush en views views_ui ctools media media_internet file_entity devel devel_generate link block_class pathauto token

and press Enter. You should get something along the lines of Figure 3-5.

Note

When doing certain things in Drush, you may end up with an error saying that you’ve exceeded your memory limit. If this happens, I often fix it by going into sites/default/settings.php and adding the code ini_set('memory_limit', '128M'); to the file. Do a search for the term “ini_set” in the text and put the code at the top of all those values.

You may have to change the permissions on settings.php in order to change the file; make sure that you set it back to 444 when you’re done. This ensures that once you’ve made your changes, nobody else can change your file—particularly important when the site is live. Drush also has its own settings file, drushrc.php, which you can adjust in order to give Drush more memory while keeping Drupal’s memory at a reasonable limit.

So now, in about five minutes, we’ve done what it would have taken us over an hour to do manually. This, dear reader, is why you should learn Drush.

Now that we’ve gotten used to the command line, and we’ve started downloading and enabling modules on our d7-demo site, we need to make sure that we can back up our work. For that, we’ll need to learn Git, the open source version control system.