Upgrade Magento 2 to Magento 2.x.x via SSH

In this article, I will explain how to upgrade your Magento version from Magento 2.x.x to Magento 2.x.x using Command-Line Interface (CLI). Please keep in mind that this upgrade supports a fresh installation of Magento 2, so it is not recommended to apply this method on your live store. After the upgrade, you can migrate your data from old Magento 2 store to newly upgraded Magento 2.1 & 2.x store.

Step 1: Access Your Server via SSH

You need to connect your server via SSH.

Step 2: Navigate to the Magento 2 Root Directory

Once your SSH connection is up, you will need to move to your target application folder. In that application folder, you will find the public_html folder which is the root directory of Magento 2.

Step 3: Upgrade Commands

Please follow the same order and use the commands listed below:

Copy
composer require magento/product-community-edition 2.2.4 --no-update

Note: As 2.2.4 is the latest version, these numbers can be changed accordingly. You can also Upgrade Magento 2.x.x to 2.x.x using the same process. you just need to change the version 2.x.x.

Copy
composer update

Note: It will ask for repo.magento.com authentication keys. For more information, visit this link.

Copy
rm -rf var/di var/generation
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento indexer:reindex

I hope this Magento blog helped you find what you were looking for.

Bookmark it for your future reference. Do comment below if you have any other handy commands which are not included in the list.

P.S. Do share this note with your team.

Review other articles maybe it'll help you too.