How to update Drupal core with composer

30 / Jul / 2023 by Dharmendra Singh 0 comments

It’s good practice to update the Drupal core and contribute modules to the latest released version. Let’s dive into how to update the Drupal core. There are multiple ways to update the core, but here we are discussing with the composer only. Composer is also the recommended way to manage the dependency of Drupal.

First, try it on the dev/local environment. Don’t try to update directly on the production. Take a backup of the code, database, and files.

also put the site in maintenance mode & rebuild the cache.

drush state:set system.maintenance_mode 1
drush cache:rebuild

 Choose the target Drupal version.

Before starting the update, we need to know the current version of our Drupal core and the newly released version of Drupal. It could be either a minor or major update. To know the updated version, we can run the below command.

composer outdated "drupal/*"
it will list all the available updates we can check drupal/core in the list as shown in the screen below. 
know the latest version

 

We can also check the Drupal release page; it shows all released based on the Drupal major version. We can check the performance and highlights of the update.

In my case, my project is based on Drupal 9.5.5, while the latest released version is Drupal 9.5.8. So, we are planning to update from 9.5.5 to 9.5.8 minorly.

https://www.drupal.org/project/drupal/releases/9.5.8

Verify whether the project uses Drupal/core-recommended or Drupal/core

run composer show drupal/core-recommended in the terminal

(a) If the above command returns “Package drupal/core-recommended not found”, it means drupal/core-recommended is not installed using the Drupal/core only, in that case, we can run the below command to update the core.

composer update drupal/core --with-dependencies

(b)  If the above command (composer show drupal/core-recommended) shows some info about core recommend:core-recommendedAs you can see on the screen, it’s showing the info about the core-recommended, then we can run the below command to update the Drupal core.

composer update "drupal/core-*" --with-all-dependencies

core update drupal

 

Run database update

drush updatedb
drush cache:rebuild
and disable the m

# Disable site maintenance mode
drush state:set system.maintenance_mode 0
drush cr

#verify the update

On the reports->available updates page, you can verify if the Drupal website is updated or not.

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *