Steps For Magento 2 Upgrade To New Version

If you want to know how to upgrade Magento 2 version when using the command line & composer, you can follow these steps given below.

There are 4 general steps:
1) Backup your store for safety
2) Make sure to turn on maintenance mode before start of Magento upgrade
3) Upgrade to new version of Magento 2

Step 1: Backup your store for safety
Creating backups is necessary for backup point where you can restore your backup if your upgrade is not successfully done or stuck somewhere where you need to rollback. If you want to know how to take backup of your Magento 2 store, you can follow the link provided below:

You can use this link to backup your Magento 2 store.

Step 2: Make sure to turn on maintenance mode before start of Magento upgrade
You should put your store in maintenance mode while upgrading your Magento 2 store.
To enable the maintenance mode, you need run following commsnd on your command line:
php bin/magento maintenance:enable

To verify whether the maintenance mode is enabled or not, you can check inside the var directory where you will find this file “.maintenance.flag” . Also you can hit the store frontend url, it will show you the maintenance page.

Step 3: Upgrade to new version of Magento 2
a) Consider you need to upgrade to 2.3.3, so you need to go to the command prompt and run the following command:

For community version:
composer require magento/product-community-edition 2.3.3 --no-update
composer update

For enterprise version:
composer require magento/product-enterprise-edition 2.3.3 --no-update
composer update

In Ubuntu/Debian Linux, if you face any permission issue, just add sudo at the beginning of every command such as “sudo composer update” .

b) After running this command, you may be asked the username and password for “repo.magento.com”:

So if you have those username (public key) and password (private key), please enter those details. If you don’t have those details, you need to create those details from your Magento account on below path:
Go to MarketPlace tab => Profile (top right corner) => Click profile => Create Keys
Please find the reference screenshot of the same:

c) Remove Magento old data using following command:
rm -rf var/cache/*
rm -rf var/page_cache/*
rm -rf generated/* OR rm -rf var/generation/*

d) Run following command to update your Magento system with latest data:
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento indexer:reindex
chmod -R 777 pub/ var/

e) Now disable maintenance mode to check the new changes on your Magento 2 store using below command:
php bin/magento maintenance:disable

f) Check / Verify the upgraded Magento 2’s version using following command:
php bin/magento --version

g) If you face any server related read-write errors or you can not access frontend, you can try following commands to resolve the issue:
find var vendor app/etc pub/media pub/static -type f -exec chmod u+w {} \
find var vendor app/etc pub/media pub/static -type d -exec chmod u+w {} \
chmod u+x bin/magento

If you run above commands, you need to flush your cache again using commands:
rm -rf var/cache/*
rm -rf var/page_cache/*
rm -rf generated/* OR rm -rf var/generation/*

Hope this helps you guys!

Leave a Reply