Skip to content

Drupal composer update: updating core and modules the right way

· The AYT team · 5 min read

Wooden library shelves with neatly arranged books

A Drupal composer update has three steps: see which updates exist with composer outdated "drupal/*", update with composer update "drupal/core-*" --with-all-dependencies (for core) or composer update drupal/modulename --with-all-dependencies (for a module), then run drush updatedb and drush cache:rebuild. Take a backup first, and on the live server upload only the tested composer.json and composer.lock.

Why you update with Composer

Since Drupal 8, a Drupal site is a Composer project: core, contributed modules and the PHP libraries they depend on are packages described in composer.json, with the exact versions pinned in composer.lock. If you update a module by copying files over the old ones, composer.lock no longer tells the truth, and the next composer install puts the old version back. That's why, on a Composer project, updates are done with Composer too.

Step 1: backup

The official drupal.org guide starts with a backup, and drush does it in two commands:

drush sql:dump --result-file=../backup.sql
drush archive:dump

The first saves only the database, the second code, files and database together. If the project is in Git, commit first so you can go back to the old composer.lock.

Step 2: see what needs updating

composer outdated "drupal/*"
composer audit

composer outdated lists the Drupal packages that have new versions. Those marked in red (!) have a new semver-compatible version, which composer update brings in. Those in yellow (~) have a new version that may break compatibility (usually a new major), which your constraint doesn't allow. If no line starts with drupal/core, there is no core update.

composer audit checks the installed packages against security advisories, including libraries that aren't Drupal modules.

Step 3: update core

For a project created from drupal/recommended-project (the usual layout, with a web/ folder):

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

The drupal/core-recommended package pins exact versions for core's dependencies, tested together, and --with-all-dependencies lets them change along with core. Without this flag, Composer may refuse the update.

If your project uses only drupal/core, without core-recommended (older projects), the command is:

composer update drupal/core --with-dependencies

Update drush now and then too: composer update drush/drush.

Step 4: update modules

A single module:

composer update drupal/pathauto --with-all-dependencies

All contributed modules and themes:

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

Add --dry-run to either command to see what would change without touching any files.

For a new major version of a module (for example from 1.x to 2.x), composer update isn't enough, because composer.json only allows ^1. Require the new version explicitly, after reading its release notes:

composer require 'drupal/modulename:^2.0' --with-all-dependencies

Step 5: update the database

drush updatedb
drush cache:rebuild

drush updatedb runs the schema updates. Without drush, you can open /update.php in a browser with an administrator account. Then check Reports → Status report and a few important pages.

Step 6: on the live server

Don't run composer update on production; reproduce exactly what you tested:

composer install --no-dev
drush updatedb
drush cache:rebuild

composer install reads composer.lock, so it installs the same versions as your test copy. --no-dev leaves out development packages.

Common errors

"Your requirements could not be resolved to an installable set of packages"

One package requires a version another package doesn't allow. Read the message from the bottom up: it tells you which module is blocking. Run the command with -W (short for --with-all-dependencies) or update the blocking module first.

Composer runs out of memory

A composer update on a Drupal project can need far more than PHP's usual memory limit. Locally, lift the limit with COMPOSER_MEMORY_LIMIT=-1 composer update. On hosting with strict limits, run the update locally and upload the result.

The site shows errors after the update

Run drush cache:rebuild, then read the log with drush watchdog:show --count=20. If the problem comes from a new module version, go back to the previous composer.lock and run composer install.

How often to run a Drupal composer update

Check for updates at least once a week. The Drupal security team releases fixes in fixed windows: every Wednesday for contributed modules and one Wednesday a month (usually the third) for core. Thursday is therefore a good time for composer outdated and composer audit. Apply security updates the same week; you can batch the rest.

Without SSH

Without a command line on the server, you run steps 2–5 on a local copy of the site, then upload composer.json, composer.lock, vendor/ and the web/ folder (without web/sites/default/files) via FTPS. Finally, open /update.php on the live site to run the database updates. It works, but every security update means a full round trip, and vendor/ usually holds thousands of files.

On AYT hosting

AYT has no SSH, but the Drupal Toolkit runs Composer and drush for you. A core update starts from a button on the site's page: the toolkit saves the database, then runs composer update drupal/core-* with --with-all-dependencies, drush updatedb and drush cache:rebuild. Updates stay within the same major version.

Drupal Toolkit: the site overview with an update available

The toolkit checks for core updates daily and notifies you, and if you switch it on it applies patch releases by itself (11.3.4 → 11.3.5, for example), again after a database backup. It also runs composer audit daily and tells you when a package in the project has a known vulnerability. On the Extensions page you see the list, turn a module on or off, install another by its Composer package name (drupal/token, for example) and remove what you no longer use. Contributed modules you already have are updated with the steps above, on a local copy. The Commands page runs drush commands such as updatedb:status or pm:list --status=enabled, for up to 120 seconds. For jumping between major versions, see the Drupal 10 to 11 upgrade. Details on the features page and plans on hosting.

More articles

All articles