Drupal: Installing multiple contrib modules – the easiest way

Here’s how to quickly extract multiple tar.gz files in a folder using “find” or a loop. It’s easy, it’s simple, and it gets your drupal install up and running in less time than it takes to say “Upload via FTP”. If you want the solution right away, scroll down to the bottom if this post.

I’ve recently had to install drupal a number of times in a span of a few days. The way I usually do it – download tarballs, extract, create file structure, upload via ftp – was just too slow. Fortunately I have shell access to my shared hosting account on DreamHost, so here’s what I’ve been doing recently.

Fire up a terminal window in Mac OS and SSH to my wonderful DreamHost linux webserver (you can do the same in Linux, but you need some software SSH in windows) – Here’s the command I use:ssh username@servername.com
and enter the password when the server asks you for it. Do note that the characters that you type in for your password may not appear on the screen, but they’re still being entered.

Change to the directory that you’re going to install drupal into. Alongside this, navigate over to drupal.org, and to their download page. At the time of writing this, Drupal 6.20 is the latest version, so the path to the .tar.gz file looks like this: http://ftp.drupal.org/files/projects/drupal-6.20.tar.gz I just right click in Firefox and select “Copy Link Location”.

Now, skip back over to the terminal window. Remember, I’ve navigated to the folder I want to install drupal to. Then type in wget http://ftp.drupal.org/files/projects/drupal-6.20.tar.gz. This downloads the drupal core tarball to the server directly.

Extract it using tar -xzvf drupal-6.20.tar.gz. You’ll see a screen ful of paths as the files are extracted to a folder called drupal-6.20.

I go ahead and start off the install in a browser, and get the settings file renamed and database hooked up, and everything else until it becomes time to get the contrib modules installed.

On any given install of drupal, I usually have atleast 10 or so contrib modules installed, and very often it goes up quite a bit. Like I said before, FTP just does not cut it for this, so, like our drupal core tar.gz file, I find the paths to every single contrib module that I want installed. And here’s a little secret – They’re all at the Modules page of Drupal.org!!! and happily listed in descending order of the modules most used. This is a quick process. I wget them to the sites/all/modules/ folder, so that I have about 20 GZipped Tar files; and that’s where I hit a snag.

You see, the tar command does not use wildcards happily. In fact it does not use wildcards. – (period) So I had to find an alternative, to get all these .tar.gz files extracted without having to repeat the same command again and again manually. I found a solution. In fact, I found two solutions

find -name '*.tar.gz' -exec tar -xzvf '{}' ';' – This piece of code extracts all .tar.gz files in the current folder, and all subfolders, making it ideal if you have all the tar files ready and waiting extraction in the sites/all/modules/sites/all/themes/ and sites/all/libraries/ folders. Just run it in the sites/all/ folder, and then run back and rm -R *.tar.gz each folder to remove the tar files.

for i in *.tar.gz; do tar -xzvf $i; done – This piece of code extracts all .tar.gz files in the current folder. Leaving you to cleanup all the tar.gz files in the directory with a simple rm -R *.tar.gz

That’s it, done! Head over to http://yoursite.com/admin/build/modules and tick the check box next to the names of all the contrib modules you want to activate, save, and they’re ready to do your bidding!

I hope you find this time saving shortcut useful. The code is not mine. I found it on WebHostingTalk.com in a thread titled How do you untar multiple .tar.gz files? I was also helped along by a good friend who does not want to be named. Experiment and see what works best for you.