Capistrano Meets Drupal

There are some very trivial administration tasks that I find myself doing over and over again in Drupal which can't currently be done from the admin interface. As of right now, these include installing a theme or module from drupal.org or adding a new site to an existing Drupal install. So, I've built a tiny Capistrano file that allows me to automate these tasks.

The tasks that I've setup are:

cap drupal:install:theme
cap drupal:install:module
cap drupal:install:site

cap drupal:install:theme

All this task requires is a path to the tar file of the theme that you want to install. What I do is browse over to the list of Drupal themes, find one that I want to try out, and copy the location of the "Download" link for the correct theme. In Firefox and Safari its as simple as right clicking the link and selecting "Copy Link Location". Make sure the version of the theme corresponds to the version of Drupal you have installed.

Once you've got the location to your theme copied, run the task with cap drupal:install:theme. It will ask you for the path to the theme location which you can then paste in. That's it. You should be able to browse to admin/build/themes and see your newly installed theme.

Currently this task assumes that you want all your themes to be downloaded in /var/www/drupal/sites/all/themes/. This is very easy to change in the capfile.

cap drupal:install:module

This is very similar to theme installation task and it just requires the path to the module you want installed. Again, browse to the list of modules find the one you want installed, copy its tar location and enter in the prompt after you run cap drupal:install:module.

This also assumes you want all your modules to be downloaded into /var/www/drupal/sites/all/modules. Another easy change.

cap drupal:install:site

This task creates a new site and its database from parameters you can specify. It creates the necessary folder in the sites directory and creates the settings file with the correct database name, username, and password. One thing you might want to change here is my use of mysqli vs. mysql.

Besides the ones listed above, the other big assumption I make is that you have curl installed (an easy apt-get install curl in Debian). I'm using curl to grab the tar files from Drupal.org. I could have easily used wget, but I like curl better. Just a preference that you can easily change in the file if you don't like it.

There you have it. Now installing a theme, module, or new site is only a cap drupal:install away.

AttachmentSize
capfile2.4 KB
Comments on this post
  1. By Jamis Buck (not verified) on Sat, 12/15/2007 - 20:26

    Excellent use of capistrano! My only suggestion would be to put the tasks in a "drupal" namespace, since "install" is pretty generic and could easily conflict with other modules. Thanks for sharing this!

  2. By jhuckabee on Sat, 12/15/2007 - 22:01

    Thanks for the tip Jamis. I've updated the file and instruction with the drupal namespace.

  3. By Anonymous (not verified) on Fri, 12/21/2007 - 10:23

    Good thinking young padwan. Very pragmatic, and helpful.

  4. By moshe weitzman (not verified) on Sat, 05/03/2008 - 02:16

    capistrano is way cool, but drush module is what you really want for this. it is the comamnd line interface for drupal. it hooks into the update information for drupal so you can get the latest released version or other version if you want. it does other stuff too.

  5. By rimian (not verified) on Thu, 08/27/2009 - 01:10

    I've used drush and apache ant for automating tasks and in the process of setting up capistrano to automate deployment. This looks interesting.

  6. Post new comment

    The content of this field is kept private and will not be shown publicly.
    • Web page addresses and e-mail addresses turn into links automatically.
    • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
    • Lines and paragraphs break automatically.

    More information about formatting options