Stepholt News

Update Magento 2 via CLI

News Categories: MagentoServer HelpTech

This article was published on: 06/26/21 6:40 AM

First thing is to back up the server / data before driving in


Put the site in maintenance mode

bin/magento maintenance:enable


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.

composer update

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

bin/magento setup:upgrade

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:

Also checkout the official elasticsearch install – this is for Linux servers:

bin/magento maintenance:disable

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


Website Design
Website Development
Website Marketing