Drupal: Lather, rinse, repeat – Cleaner development with installation profiles and Makefiles

I’m beginning to really like Drupal, a PHP-based content management system. Working with Drupal feels almost like working with Emacs because of the number of hooks that people have designed into the system. =) So here’s a Drupal tip for fellow newbies.

When you’re developing a site in Drupal, it’s a good idea to make sure that you can reproduce your setup on a different system. One way to do that is to periodically do a fresh install of Drupal with your modifications, and see if everything still works.

For example, on my system, I have an installation profile that enables and sets up Drupal the way I want. I also have a script that deletes and recreates the database, then restores the default settings.php. To refresh my system, all I have to do is type “make clean”, then open my Drupal site in the browser. After I specify the installation profile for my project and the database connection details, Drupal sets everything else up. Because I use installation profiles and source code control (svn on this project), I can commit my changes, update the copy on the test server, and easily reproduce my system there. Using installation profiles saves me the time that I would’ve spent setting up and configuring all the modules (and in the right order!), and this practice can help you too.

Here’s how to get started:

  1. Make a copy of sites/all/default/settings.php before you configure your system, or get the settings.php from a clean (never-installed) Drupal directory. I like putting this copy in sites/all/default/settings_default.php.
  2. Create an installation profile for your system. The easiest way is to use the install_profile_wizard module to generate a base installation profile, then modify it as needed. Put this profile somewhere in your profiles directory.
  3. Create a Makefile, shell script, or batch command that drops the database you’re using, recreates the database (granting any permissions necessary), and copies sites/all/default/settings_default.php to /sites/all/default/settings.php

Then, when you’re developing code, you can just call your Makefile/script/batch command to start from a (relatively clean) database.

Lather, rinse, repeat.

2 Pingbacks/Trackbacks

  • Sacha! I *love* that you’re getting into Drupal… this is a great tip too!

    Lemme know how you’re liking PHP dev in Emacs – I’ve ended up switching to using Komodo IDE primarily these days largely ’cause I never had enough time to tweak my .emacs to where I really felt good about it.

    Keep the posts comin!

  • Walkah! =D Thanks for all those lovely podcasts and tips on Lullabot, and for the code I keep running into! =)

    Drupal is a lot of fun. As I said, it makes me feel like I’m playing with something like Emacs. It also makes me feel like Bruce Lee (wooooooo… WHAPACK!).

    My current makefile looks like this:

    	cp sites/default/settings-default.php sites/default/settings.php
    	mysql -u root --execute='DROP DATABASE IF EXISTS drupal_sacha; CREATE DATABASE drupal_sacha';
    	chmod ugo+w sites/default/settings.php
    local: clean
    	firefox http://SITENAME/install.php?profile=PROFILE_NAME

    make local takes one more step out of the testing process! =)

  • Pingback: Drupal: Adding lines to settings.php in an installation profile | sacha chua :: enterprise 2.0 consultant, storyteller, geek()

  • Pingback: Drupal: Adding lines to settings.php in an installation profile | sacha chua :: enterprise 2.0 consultant, storyteller, geek()

  • Sandy

    It would have been great if the installation profile documentation contained the bit of code above on how to, you know, use the damn things.

    Sacha’s comment above is the first actual example I’ve seen anywhere on the web. If it exists elsewhere, it’s hidden from the Google hivemind.

    • The Install Profile Wizard gives you a decent starting point from your current Drupal configuration. =)