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

Automate and Simplify Your Drupal Workflow with Bash Scripts for Shared Hosting

July 19, 2024

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

For the past several years, I've been working with enterprise level marketing Drupal websites. Those sites have several developers and a variety of version control systems and hosting providers. All of these sites have some sort of continuous integration and delivery systems built in as part of the deployment processes. This is great if you have a complex web application that consists of code from different repositories and a DevOps team that knows how these systems work and are set up.

While a more simple website with basic features, such as Drupal Odyssey, the benefits do not out weigh the complexity to use these systems and cost. Especially if you are not familiar with setting them up. I've tried to use a few CI/CD systems and they do work, but for one reason or another, I always come back to what I see is the most simple way to just get the job done ... a shell script.

James Gregory wisdom

If you don't have a lot of fancy-smancy integrations or complicated custom code that needs testing every time you make an update, such as a Drupal core update, CI/CD systems can be overkill in my opinion. In reality, Drupal website release processes overview would look like the following:

  • Merge the dev branch into the master/main branch
  • Pull/checkout the repository changes
  • Run composer install
  • Run database updates
  • Import configuration changes
  • Clear caches

That's it! No build scripts. No unit or functional tests. Below is the script I cobbled together to just get the job done. To be able to use this script in your own deployments, you will first need to ensure you have password less ssh login set up to your server from your local machine.

#!/bin/bash
# Hostname or IP address of your server.
hostName='YOUR_HOSTING_IP_ADDRESS'
# Username with ssh access on the above host
remoteUser='YOUR_HOSTING_USERNAME'
# The ssh port to use.
port=YOUR_HOSTING_SSH_PORT
rootPath="/home/$remoteUser"
# Composer 2 path since hosting default is Composer 1.x
composerPath="$rootPath/bin/composer"
# Where Drupal is installed.
drupalRoot="$rootPath/domains/drupalodyssey.com/public_html"
# Where the Drush command is located.
drushPath="$drupalRoot/vendor/bin/drush"
echo "Connecting to host $hostName ..."
ssh -t -p $port -i $HOME/.ssh/id_rsa $remoteUser@$hostName << EOF
cd $drupalRoot;
echo "Putting website into maintenance mode ..."
$drushPath config:set system.maintenance message "Our servers are getting a quick tune-up. Your patience is appreciated!" -y
$drushPath state:set system.maintenance_mode 1 --input-format=integer
echo "Clearing Drupal caches ..."
$drushPath cr
echo "Pulling latest changes from the repository ..."
git pull
echo "Running composer install ..."
$composerPath install
echo "Clearing Drupal caches ..."
$drushPath cr
echo "Importing configuration changes ..."
$drushPath cim -y
echo "Updating database schema ..."
$drushPath updb -y
echo "Removing website from maintenance mode ..."
$drushPath state:set system.maintenance_mode 0 --input-format=integer
echo "Clearing Drupal caches ..."
$drushPath cr
EOF
echo "---"
echo "---"
echo "Deployment complete."
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.

The bash script is pretty straight forward. The first two blocks simply define some variables to be used later. The third block is where all of the magic happens.

It starts by opening a ssh session to the hosting provider using public/private keys. Once that ssh session is open, several Drush commands are run to put the site into maintenance mode and clear the caches, followed by pulling the changes from the repository. Once that has completed, the composer install runs to ensure all of the dependencies are present. This is followed up by importing the configuration changes and running the database updates before finally disabling maintenance mode and clearing the caches to bring the site back online.

As you can see, this process is pretty simple with no bells and whistles. This script could be modified to be as complex as it needs to be. However, if there are more complex processes in your deployment process and you still don't want to use a CI/CD system, I'd at least try and set it up using Ansible. I was going to use Ansible myself, by my shared hosting plan did not have Python installed.

Drop a comment below and let me know how you handle simple deployments or if you have questions or comments about how I do it. 

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.