Drupal Shared Hosting Site Installer

Update: I added a cleaned up copy of my script, in case it comes in handy for anyone. Read the end of this post for more info...

I just finished whipping up a workable bash script to automate installing and (basically) configuring a new site on a shared Drupal hosting server.

Here's the basic scenario. First, you set up a "template" site, and configure it however you want all new sites to start. Add common accounts. Enable modules. Twiddle bits. Etc... Then, you export a mysqldump of that template site's database, and will use that to create new sites.

Now, whenever you want a new site, you just run this bash script and give the short site name as a parameter on the command line. It will create a symbolic link from the shared Drupal codebase to a location within the web directory, then create a new database and populate it using the freeze dried mysqldump. It will then make sure that the files directory in the new site's "site" directory is writable, and insert some settings into settings.php to tell it to use the proper database and file_directory_path.

Initial tests show it's working like a charm. I can now set up a new site in roughly 10 seconds. Very cool.

After I've cleaned up the script some more, and tested it a bit more (i.e., on a machine other than my Powerbook), I'll post it online somewhere. It's really a pretty simple script, now that it's working. Including comments and liberal whitespace, it's a whopping 52 lines of code (18 lines that actually do stuff).

I'll also be doing some more playing around with the shiny new Drupal installer (part of the CVS branch of Drupal now) to see if that might be a better long term solution. Not sure how it handles tweaked settings. It handles enabling modules and themes, though...

Update: I've cleaned up the script, done some more testing, and it seems to work fine. So, here it is in case it comes in handy for anyone.

To make the automatic configuration of settings.php work, you need to modify your "template" settings.php to have "database_name_goes_here" where the database name goes (line 87 in my copy), and you can also have it set the files directory for the site if so desired, by editing the variable override array at the end of the file. Mine looks like this:

$conf = array(
	'file_directory_path' => 'sites/file_directory_path_goes_here/files',
	'clean_url' => '1'

See Also

comments powered by Disqus