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. See just a lot less issues, more verbose language on errors, and the ability to skip the backup phase. As we will take a manual full image before we start. In a LAMP/LEMP configuration this is ideal.

Warning: DO NOT upgrade composer to 2.x! Currently Magento does NOT support it.

Note: If you need to upgrade from 2.3.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

Run ./ or the long way …

sudo redis-cli flushall

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

sudo php bin/magento setup:upgrade

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

sudo php bin/magento setup:di:compile

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

sudo php bin/magento cache:enable

sudo php bin/magento maintenance:disable

sudo php bin/magento cache:clean


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. All of our G3 and G4 Magento stacks support PHP 7.3, PHP 7.2, and PHP 7.1. This makes upgrading to 2.3.0 a breeze as the latest PHP is already pre-installed 😉

Better – Stronger – Faster!