Skip to main content
info@drupalodyssey.com
Thursday, June 5, 2025
Contact

Main navigation

  • Home
  • Blog
    • all
    • Development
    • Community
    • Management
    Aluminum Cans Passing Through the Assembly Line by cottonbro studio on Pexels
    Automate and Simplify Your Drupal Workflow with Bash Scripts for Shared Hosting
    Jul 19, 2024
    Binoculars resting on newspapers.
    Evaluating Search and Replace Scanner: The Ultimate Tool for Drupal Bulk Content Edits?
    Jun 29, 2024
    People looking at a computer screen
    S3 File System Module Not Working with Media Entity Download Module? Here's the Fix
    Jun 18, 2024
    Mechanic hands working on an engine.
    Setting Up the Etsy OAuth2 Client For Use With The Etsy Shop Integration Module
    May 10, 2024
    Fashion designer sketching new garments.
    Crafting Your Online Store: Drupal's Role in Your Etsy Success
    May 09, 2024
    Socket toolbox
    Beginner's Guide: Getting Started With Drush for Efficient Drupal Development
    May 08, 2024
    Stargazing over mountians.
    Drupal-Powered Stargazing: A Module for NASA's Astronomy Picture of the Day
    Sep 15, 2023
    Computer screen with code.
    Learn How To Script Drupal Installations Using Drush
    Dec 08, 2014
    Scuba diver with Drupal mask.
    Scuba: Drupal Style
    Oct 16, 2014
    Woman frustrated with laptop.
    5 Reasons Your CMS Sucks
    Jul 24, 2013
    Two young men having a discussion in front of a computer.
    Deployment Module XSRF Patch Committed
    Jul 05, 2013
    Two young men having a discussion in front of a computer.
    Deployment Module XSRF Patch Committed
    Jul 05, 2013
    Application settings.
    Using PHP To Disable Internet Explorer Compatibility Mode
    Jun 04, 2013
  • Resources
  • About
  • SPACER
  • SPACER
  • SPACER
  • SPACER
  • SPACER
Search
Development

Learn How To Script Drupal Installations Using Drush

December 08, 2014
This article is depreciated as of Drupal 8 in favor of a Composer workflow.

Drupal Odyssey is supported by it's readers. When you purchase products or services using the links on this site, we may earn a small commission at no additional cost to you. Learn more

I've been using Drupal for several years now and love the content management system. It seems that every day I find something else about Drupal or a specific custom module or add-on that makes it better and better. Recently, I discovered the power of using a shell script along with the Drush command line utility to install and set up an entirely new site in a matter of minutes.

I've known about Drush, the command-line utility for Drupal, for awhile now but only recently starting using it and digging through the docs to see what it's actually capable of. Today was the day I unlocked the golden door to consistent and simplified installations — the site-install or si command with shell scripts.

The reason I started looking into this is that at my job, we use Puppet to control our system builds so they are predictable. Our Drupal skeleton worked, but someone still had to open the new site in a browser and run the Drupal installation manually. Ugh! There had to be a better way! That's when I started researching Drush installations.

I'm not a shell script guru by any means, but with what I do know and some help from the Drush documentation, I was able to throw together a working script that simulates closely what our Puppet manifest does when creating a new Drupal site in less than an hour.

Feel free to use and extend the following shell script (written for OS X Yosemite‎). Just substitute the variable values with values for your system.

#!/bin/sh # 
# This is a basic shell script to install a previously downloaded tarball 
# of Drupal core to create an entirely new site. The settings variable is set 
# because I have a pre-configured "default.settings.php" file with 
# configuration variables pre-set with values that I use most often for new 
# Drupal sites which is stored in a known location on my file system. The 
# default.settings.php file is removed from the extracted Drupal core archive 
# and replaced with my customized file BEFORE the Drush installation runs. 
# 
# Drupal core source file. 
source=/Users/ronald/Downloads/drupal-7.34.tar.gz 
# Target directory for the installation
target=/Users/ronald/sites/dev/drupaltest.com/htdocs 
# Pre-edited 'default.settings.php' file location 
settings=/Users/ronald/drupal/config/default.settings.php 
# Database configuration string. 
db_settings=mysql://dbuser:dbpass@dbhost:3306/dbname 
# Drupal super user to create (UID 1) 
user=admin 
# Drupal super user password 
pass=xxxxxx 
# The site name sitename="Drush Install Test" 
# The site email address 
sitemail=support@somedomain.com 
# First - untar the archive file into the target directory. 
/usr/bin/tar -xf $source -C $target --strip-components=1 
# Second - Remove the file sites/default/default.settings.php from the 
# the extracted files. 
rm "$target/sites/default/default.settings.php" 
# Third - Copy the edited version of 'default.settings.php' into the 
# sites/default folder so Drush will have that file available 
# to copy to settings.php when the installation runs. 
# 
cp $settings "$target/sites/default/default.settings.php" 
# Fourth - Change to the $target directory and use Drush to install the 
# Drupal site in that directory. 
# 
cd $target; drush si standard --db-url=$db_settings --account-name=$user --account-pass=$pass --clean-url=1 --site-name=$sitename --site-mail=$sitemail --locale=en -y
NOTICE: The above script is provided as-is with no warranty. I am not responsible for system damage or data loss. Use the above script at your own risk.
Author

Ron Ferguson

Previous Blog

Next Blog

0 Comments

Login or Register to post comments.

Categories

Categories

  • Development
    (8)
  • Community
    (9)
  • Management
    (3)

Trending Blog

Trending Blog

Woman frustrated with laptop.
5 Reasons Your CMS Sucks
24 Jul, 2013
Mechanic hands working on an engine.
Setting Up the Etsy OAuth2 Client For Use With The Etsy Shop Integration Module
10 May, 2024
Stargazing over mountians.
Drupal-Powered Stargazing: A Module for NASA's Astronomy Picture of the Day
15 Sep, 2023
People looking at a computer screen
S3 File System Module Not Working with Media Entity Download Module? Here's the Fix
18 Jun, 2024
Computer screen with code.
Learn How To Script Drupal Installations Using Drush
08 Dec, 2014

Tags

Tags

  • Drupal 10
  • Drupal 9
  • Drupal 8
  • Drupal 7
  • Drush

Ad - Sidebar (300 x 250 AD)

Ad - Sidebar (300 x 600 AD)

Newsletter

Subscribe my Newsletter for new blog & tips Let’s stay updated!

Categories

  • Development
  • Community
  • Management

Useful Links

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Disclaimer
  • Cookies

Must Read

Aluminum Cans Passing Through the Assembly Line by cottonbro studio on Pexels
Automate and Simplify Your Drupal Workflow with Bash Scripts for Shared Hosting
19 Jul, 2024
Binoculars resting on newspapers.
Evaluating Search and Replace Scanner: The Ultimate Tool for Drupal Bulk Content Edits?
29 Jun, 2024
Mechanic hands working on an engine.
Setting Up the Etsy OAuth2 Client For Use With The Etsy Shop Integration Module
10 May, 2024
Socket toolbox
Beginner's Guide: Getting Started With Drush for Efficient Drupal Development
08 May, 2024

© 2024 All Rights Reserved.

Proud supporter of active military, veterans and first responders.