Skip to content

Instantly share code, notes, and snippets.

@ademers
Last active March 18, 2024 09:44
Show Gist options
  • Save ademers/a3b9e7e207774100c3c7c78dc560aaa3 to your computer and use it in GitHub Desktop.
Save ademers/a3b9e7e207774100c3c7c78dc560aaa3 to your computer and use it in GitHub Desktop.

How I Update Craft CMS 3.5.x and Craft CMS Plugins

⏳ 2 min read.

Update apnea: the temporary cessation of breath when updating Craft and Craft plugins.

This article describes the steps I follow to update Craft 3.5.x and plugins in a stress-free and reliable manner. 🧘

Photo of blue and pink sea by Harli Marten Photo by Harli Marten on Unsplash

Assumptions

  • Craft 3.5.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. This prevents unintended updates when running composer update in your local development environment. However, I make an exception for the vlucas/phpdotenv package.

In Local Development Environment

Updating Craft

  1. Confirm the latest version of Craft by visiting the Update utility in the Craft control panel at http://example.test/admin/utilities/updates.
  2. Edit the craftcms/cms line in the composer.json file to change the Craft Composer package to the latest version.
  3. From the command line in the Craft project root, run:
    1. ./craft backup to backup the Craft database.
    2. composer update to update the Craft Composer package to the version specified in composer.json. See step 2.
    3. ./craft migrate/all to run Craft database migrations.
    4. ./craft project-config/apply to apply Craft project config file changes.
    5. ./craft clear-caches/all to clear all the caches.
  4. Verify that Craft has been updated to the specified version and is still working as expected.

Updating a Craft Plugin

  1. Confirm the latest version of the plugin by visiting the Update utility in the Craft control panel at http://example.test/admin/utilities/updates.
  2. Edit the vendor/package-name line in the composer.json file to change the plugin Composer package to the latest version.
  3. From the command line in the Craft project root, run:
    1. ./craft backup to backup the Craft database.
    2. composer update to update the plugin Composer package to the version specified in composer.json. See step 2.
    3. ./craft migrate/all to run plugin database migrations.
    4. ./craft project-config/apply to apply project config file changes.
    5. ./craft clear-caches/all to clear all the caches.
  4. Verify that the plugin has been updated to the specified version and is still working as expected.
  5. Repeat steps 1-4 for all other plugins that I want to update.

In Production Environment

Installing Updated Craft CMS and/or Plugins

  1. From the command line in the Craft project root, run:
    1. ./craft backup to backup the Craft database.
    2. composer install to install the Craft and/or plugin Composer packages that I previously updated in my local development environment.
    3. ./craft migrate/all to run all database migrations.
    4. ./craft project-config/apply to apply project config file changes.
    5. ./craft clear-caches/all to clear all the caches.
  2. 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 backup/db"
],
"post-update-cmd": [
    "@php craft migrate/all",
    "@php craft project-config/apply",
    "@php craft clear-caches/all"
],
"pre-install-cmd": [
    "@php craft backup/db"
],
"post-install-cmd": [
    "@php craft migrate/all",
    "@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.

⊹╰(⌣ʟ⌣)╯⊹

@zenbug
Copy link

zenbug commented Feb 17, 2021

Oh I see, so you don't execute any specific commands then. They just run when you run composer update.

I'm getting an error on @php craft backup/db but I'll have a look.

Thanks for posting this!

@terryupton
Copy link

@ademers is there a reason you manually update the packages in the composer.json and then run composer update rather than using the ./craft update command line?

@ademers
Copy link
Author

ademers commented Dec 22, 2021

Hi @terryupton ! composer update has been the most reliable way for me to update Craft & Craft plugins. I had issues with ./craft update that I don't remembers exactly, but I think it may have been PHP memory limit issues even when disabling limit via memory_limit = -1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment