Ravi Sagar | Home | Blog

Update Drupal using composer with a proper development workflow

Table of Contents

Keeping your Drupal site updated is important. Doing it with Composer is easy but it has to be done properly. In this blog let me share the steps I follow to update Drupal using a proper development workflow.

These are the steps. Enjoy.

1 Recommended setup

We all have different ways of working. This setup works really well for me because I am the only developer working on this site.

  • Local site: www.ravisagar.test

This is for significant development work like adding a new module, design changes or some major functionality.

  • Staging site: www.staging.ravisagar.in

Only for testing.

  • Live site: www.ravisagar.in

Always has the most recent content like new blogs, new images. Sometimes I do some small css changes directly on live.

2 Upgrade a Drupal site

These are the steps involed in upgrading a Drupal site.

2.1 Refresh local with production data and configurations

I do lot of small changes and tweaks directly on production and of course production has latest content as well. So from time to time I refresh my local with production but I also do this when I have to upgrade a site.

  1. Take mysqldump of production database and save it in files/database/YYYY-MM-DD.tar.gz
  2. Git push (it won't have files directory). Do this if you installed new module directly on production or done some changes to the theme css.
  3. Go to local and rsync files directory (that has images and latest database). Change the path accordingly.
rsync --dry-run -av user@production:/PATH_TO_LIVE_SITE/sites/default/files/ files/
  1. Now local has files/ directory from live.
  2. Restore database. Now local has live database.
  3. Perform git pull and it will have any modules or theme changes done on production.
  4. Run composer install (if you installed any module on production). I always run this. Just in case.
  5. Clear cache vendor/bin/drupal cache:rebuild all
  6. Now you have local running as same configuration and content from production.

2.2 Update Drupal on local

If you are running on Drupal 8.8.5 and above then this should work.

composer update drupal/core-recommended --with-dependencies
drush updatedb
vendor/bin/drupal cache:rebuild all

Also refer to this page for up to date information on how to update Drupal using Composer.

2.3 Commit your updated Drupal site to the repository

Now you have local running on updated Drupal site with latest content and files from live. Celebrate!

git add .
git commit -m "updating to Drupal 8.8.8"
git push

2.4 Test your newly updated site on staging

Time to test your site on staging. Good opportunity to make sure it works on production environment.

  1. Go to your staging directory and bring the files from the repository by doing git pull
  2. Also bring the new files from production site.
rsync --dry-run -avv user@production:/PATH_TO_LIVE_SITE/sites/default/files/ /PATH_TO_STAGING_SITE/sites/default/files/
  1. From the files/database directory restore the mysql database on staging
  2. At this staging you have latest files from production, latest database from production and latest upgrade code from local which usually in the composer.json and composer.lock files. The last thing you need to do on staging is to use composer to bring new files need for the update.
composer install
drush updatedb
vendor/bin/drupal cache:rebuild all

Now your staging is updated.

2.5 Update your live.

Ready to update live? Lets do it.

git pull
composer install
drush updatedb
vendor/bin/drupal cache:rebuild all

Simple right? Your live already has the latest database and files. We just need to bring the latest updated composer.json and composer.lock, along with any other changes to theme that you may have done on local.

Now time to open a beer and celebrate.

3 Letsencrypt certificate

Just follow this tutorial and you are done: https://linuxhostsupport.com/blog/how-to-install-lets-encrypt-on-centos-7-with-apache/

yum install certbot 
yum -y install certbot-apache

Install certificate using the command.

sudo certbot --apache

It will make changes to the following files for you.

sudo emacs /etc/httpd/conf.d/vhost-le-ssl.conf

It will also add redirect (if you choose) in the following file.