Updating Drupal 8 with Composer : a step by step tutorial

9 August 2017

I finally got around to launching the alpha of my personal website last week using Drupal 8, which I’d been planning to get around to for quite some time. I’ve managed to migrate my blog posts across and just need to work on adding the images, this time using the power of the Paragraphs module for all content.

In the past 8 days since launching, a few updates have become available. As many Drupal friends are a little anxious of Composer, I thought it would be good to document my steps for everyone to see.

Prerequisites

Composer project template

To create this website I used the drupal-project composer template, which is the recommended way of setting up a new Drupal 8 project. To start my project I ran composer create-project drupal-composer/drupal-project.

Knowledge of configuration management

Importing configuration with drush cim and exporting with drush cex.

For more information on this, read my other medium articles Easy Drupal 8 configuration management with fellow developers & Drupal 8 Configuration Management -dealing with import issues.

1. Check what needs updating with the UI

Thumbnail

As you can see from the image above, I need to update Drupal core and 2 contrib modules. I can now proceed to open my site in terminal (iTerm 2 to be exact) so I can run composer.

1. Check what needs updating with Composer

You can also run the command composer outdated which gives you a full list, including the Symfony components that Drupal 8 is now dependent on. Don’t worry, all you need to pay attention to are the items starting drupal/.

Thumbnail

Along with Drupal core, you’ll notice that entity_browser and metatag are there as expected, but we also see entity_browser_form and views_bulk_operations have updates too.

2. Updating Drupal core

Before you do anything, I would recommend importing configuration as a fellow developer may have added some new config that you haven’t yet imported to your local environment with drush cim.

You can update Drupal core by running the command composer update drupal/core.

I would recommended you use composer update drupal/core --with-dependencies in case your composer.lock file references a particular version.

Thumbnail

I finalised this update to core by updating the database, exporting any new configuration & clearing all caches by running drush updbdrush cexdrush cr. It is important to remember to export config as database updates can add, remove or update your config files.

I then looked through the site to see if all looked well and it did.

Before committing I checked the git diff and saw the below in part of it.

Thumbnail

It is good to have this as a separate commit from any other updates so it is easier to see what changed, but also giving you the ability to revert just that if needed later.

3. Updating Drupal contrib modules

This is super easy, you just need to run composer update drupal/MODULENAME. I would recommend that you use composer update drupal/MODULENAME --with-dependencies.

We saw earlier that the Metatag module needed updating, so I ran composer update drupal/metatag.

Thumbnail

I finalised this update to core by updating the database, exporting any new configuration & clearing all caches by running drush updbdrush cexdrush cr.

Before committing I checked the git diff and saw the below in part of it.

Thumbnail

I hope you found this tutorial useful. Did you get into any interesting adventures when updating your Drupal 8 site with Composer? I’d love to hear your experiences so please comment below, or drop me an email at [email protected]