ā³Ā 2 min read.
Still running Craft 3.5.x? Checkout outĀ How I Update Craft CMS 3.5.x and Craft CMS Plugins.
Update apnea: the temporary cessation of breath when updating Craft and Craft plugins.
This article describes the steps I follow to update Craft 3.6.x and plugins in a stress-free and reliable manner.Ā š§
Assumptions
Craft 3.6.x is installed in local development and production environments.
Composer 1.3.0 or later is installed in local development and production environments.
Access to a command line interface (CLI) in local development and production environments.
The exact versions of Craft and all plugin packages are specified in
composer.json
to avoid unintended updates/upgrades when runningcomposer update
in your local development environment. The one exception I make is for thevlucas/phpdotenv
package.
Changes in Craft 3.6.x
TheĀ
migrate/all
Ā command now outputs all pending migrations, and if the shell is interactive, it will prompt the user for confirmation before running them (just likeĀmigrate/up)
. This change doesnāt affect most deployment tools, as they will typically run terminal commands via non-interactive shells, however thatās not always the case.
Source:Ā Upgrading to Craft 3.6
In Local Development Environment
Updating Craft
Confirm the latest version of Craft by visiting theĀ UpdateĀ utility in the Craft control panel atĀ http://example.test/admin/utilities/updates.
Edit theĀ
craftcms/cms
Ā line in theĀcomposer.json
Ā file to change the Craft Composer package to the latest version.From the command line in the Craft project root, run:
./craft db/backup
Ā to backup the Craft database.composer update
Ā to update the Craft Composer package to the version specified inĀcomposer.json
. See step 2../craft --interactive=0
Ā to run Craft database migrations. TheĀ--interactive=0
Ā flag forces the command to run without user input../craft project-config/apply
Ā to apply Craft project config file changes../craft clear-caches/all
Ā to clear all the caches.
Verify that Craft has been updated to the specified version and is still working as expected.
Updating a Craft Plugin
Confirm the latest version of the plugin by visiting theĀ UpdateĀ utility in the Craft control panel atĀ http://example.test/admin/utilities/updates.
Edit theĀ
vendor/package-name
Ā line in theĀcomposer.json
Ā file to change the plugin Composer package to the latest version.From the command line in the Craft project root, run:
./craft db/backup
Ā to backup the Craft database.composer update
Ā to update the plugin Composer package to the version specified inĀcomposer.json
. See step 2../craft migrate/all --interactive=0
Ā to run plugin database migrations. TheĀ--interactive=0
Ā flag forces the command to run without user input../craft project-config/apply
Ā to apply project config file changes../craft clear-caches/all
Ā to clear all the caches.
Verify that the plugin has been updated to the specified version and is still working as expected.
Repeat steps 1-4 for all other plugins that I want to update.
In Production Environment
Installing Updated Craft CMS and/or Plugins
From the command line in the Craft project root, run:
./craft db/backup
Ā to backup the Craft database.composer install
Ā to install the Craft and/or plugin Composer packages that I previously updated in my local development environment../craft migrate/all --interactive=0
to run all database migrations. TheĀ--interactive=0
Ā flag forces the command to run without user input../craft project-config/apply
Ā to apply project config file changes../craft clear-caches/all
Ā to clear all the caches.
Verify that Craft and/or plugins have been updated to the specified versions and are still working as expected.
Automating the Craft CLI Commands
To avoid running the above Craft CLI commands manually, I've added the following ComposerĀ command eventsĀ with the relevant Craft CLI commands to theĀ scripts
Ā section of my Craft project'sĀ composer.json
Ā file.
"pre-update-cmd": [
"@php craft db/backup"
],
"post-update-cmd": [
"@php craft migrate/all --interactive=0",
"@php craft project-config/apply",
"@php craft clear-caches/all"
],
"pre-install-cmd": [
"@php craft db/backup"
],
"post-install-cmd": [
"@php craft migrate/all --interactive=0",
"@php craft project-config/apply",
"@php craft clear-caches/all"
]
By following the steps described above, I can calmly and confidently update Craft and plugins in my local development and production environments.
ā¹ā°(ā£Źā£)āÆā¹
Thank you for the great article Andrea!
I didn't know about the interactive setting, will add that to our deploy script.