Update Magento 2 via CLI
First thing is to back up the server / data before driving in
Put the site in maintenance mode
If you do not have composer installed, no would be a good time 🙂 – To install the plugin:
composer require magento/composer-root-update-plugin=~1.0 --no-update
If the composer runs out of memory you can try
COMPOSER_MEMORY_LIMIT=-1 composer update
We now need to make a backup of the composer json file by running this command
cp composer.json composer.json.bak
We now need to install the version of magento we are updating too, in our case its 2.4 so we run this command
composer require magento/product-community-edition=2.4.0 --no-update
To see the full list of magento 2.4 versions available we can use the following
composer show magento/product-community-edition 2.4.* --all | grep -m 1 versions
Right, lets get the update installed and fingers crossed there isnt any minor issues.
Remember if the composer runs out of memory use the following command to overwrite this: COMPOSER_MEMORY_LIMIT=-1 composer update
Allow the the update to run through all the checks and then updates – keep an eye out for anything that fails.
Once the composer has finished updating without any issues we can then proceed to the clean up the install and start running the new Magento 2 version:
rm -rf var/cache/*
rm -rf var/page_cache/*
rm -rf generated/code/*
Next to update the database schema to work with the new M2 version
If the following error pops up like the composer php error we can run
php -d memory_limit=-1 bin/magento setup:upgrade
If you have the elasticsearch error you can follow this guide to install: https://devdocs.magento.com/guides/v2.4/install-gde/prereq/elasticsearch.html
Also checkout the official elasticsearch install – this is for Linux servers: https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html#rpm-repo
and relax, well done you have completed the magento 2.3 to 2.4 upgrade 🙂
If your frontend is still showing the error you can try and clear all the cache files again as this has happened to us a few times.
Also if you do not receive the 2 factor email and you are locked out of the admin panel please run the following command.
bin/magento module:disable Magento_TwoFactorAuth
php -d memory_limit=-1 bin/magento module:disable Magento_TwoFactorAuth