No image

Upgrade Magento 2 using Composer

Upgrade Magento 2 to the latest version using Composer

[aMiSTACX] Upgrading Magento to another version is not for the faint of heart, really. One of the tricks, is to forgo the GUI upgrade wizard, and use CLI and Composer; just a lot less issues, more verbose language on errors, and the ability to skip the backup phase.

We will take a manual full image before we start.

Warning: DO NOT upgrade composer to 2.x! Magento only supports 2.x in version 2.4.2+. You can install both versions of Composer.

Note: If you need to upgrade from 2.2.0 to 2.3.x, please follow the steps in this article:

So here we go in my example I will update from 2.4.0 to 2.4.1:

cd /var/www/magento

sudo php bin/magento deploy:mode:set developer

sudo php bin/magento maintenance:enable

sudo php bin/magento cache:clean

sudo systemctl stop elasticsearch.service

sudo composer require <product> <version> –no-update

e.g sudo composer require magento/product-community-edition 2.4.1 --no-update

sudo composer config --global discard-changes true

sudo chown -R www-data:www-data /var/www/magento

sudo chmod -R u+rwX,go+rX,go-w /var/www/magento

sudo composer update

Note: If you get a prompt saying: “Discard changes [y,n,v,d,s,?]?” Normally you would select “y”, or you can run composer update with -n [No Interaction]

Error or Prompts – at this point hopefully you will not get any errors, and if so you’ll have the ability to resolve by accepting composer’s versioning. By no means can we cover all of the potential issues here :/

If you made it past update, then it should be clear sailing.

sudo systemctl start elasticsearch.service

sudo ./ #Should be version 1.1+ for Magento G5 stacks.

Test in Prod mode or Dev mode

sudo php bin/magento deploy:mode:set production

sudo chown -R www-data:www-data /var/www/magento

Advanced Troubleshooting

If you get a message like this on your homepage:

Amazon_Core db schema version: defined in codebase – 2.1.2, currently installed – 2.2.10
Amazon_Core db data version: defined in codebase – 2.1.2, currently installed – 2.2.10

You need to connect to the database, go to the setup_module table, and LOWER the number to match what is defined in the codebase for each module that throws the exception.

Switch PHP Versions

Please see your stack guide on how to switch PHP versions. Our G5F and G5SP stacks support PHP 7.2 ~ 8.0. All of our G4 Magento stacks support PHP 7.3 ~ 7.1. This makes upgrading to 2.3 or 2.4+ a breeze as the latest PHP is already pre-installed 😉

Weaponize your Business with aMiSTACX!