• USD
  • Polish
How to Upgrade Magento 2 via Command Line?

As the title indicates, this article will guide you about Magento 2 update using the command line interface (CLI) method. Before we go further, we would like to mention that there are 3 ways to upgrade Magento 2. However, for the sake of this article, we will only focus on one particular method in this article – the CLI method. You can use this method if you have installed the Magento software by:

  • Downloading the metapackage using composer create-project.
  • Installing the compressed archive. Source

If you are still running on Magento 1, you’ll first need to upgrade to Magento 2 before you can even think of installing any Magento 2 update.

Why Upgrade Magento 2 to the Latest Version?

There are countless reasons to upgrade Magento 2 to the latest version, 2.4.7.

Enhanced Security

With almost each new update, the developers introduce security features that are critical for your store’s protection. Given the rising instances of online crime nowadays, relying on outdated technology is a recipe for disaster. Hackers may exploit a vulnerability in the older version and wreak havoc across your store. Once your reputation is lost, it can be quite challenging to recover it.

New Features

Another reason to upgrade Magento 2 is because of the new features. While they may not seem much, in reality, they can go a long way in enhancing user experience and overall store operations. For instance, the latest version brings support for PHP 8.3.

Performance Improvement

Additionally, the developers keep optimising their code which results in performance improvements.

Issue Fixes

Magento just introduced a patch on June 11 2024. For more information on it, visit here. If you read carefully, you’ll notice that the patch offers fixes for a few security bugs and issues related to UPS. If a user fails to upgrade to the latest version, they’ll be running their store with known security vulnerabilities and other bugs.

Pre-Upgrade Checklist

To make sure the process goes smoothly, do the following before you start the upgrade.

  • Verify that your PHP extensions and other environment settings are not in conflict with the version system requirements.
  • Make sure your cron jobs are setup and running.
  • Make sure the file permissions are set properly.
  • Enable maintenance mode to prevent access to the website during the upgrade. You can do so with this command.
 
bin/magento maintenance:enable
  • Back up your entire store. While it is quite rare for things to go wrong during the Magento 2 update process, yet there is a slight possibility. Thus, we don’t want you to take any risk and recommend taking a complete back up before updating to the latest version.

Will Your Custom Extensions Stop Working After Updating Magento 2?

This is a frequent question from store owners who have used a lot of custom code in their Magento 2 store. As long as you haven’t made the customisations to the core Magento 2 files, then your extensions will work smoothly even after the update. The reason is that any Magento extension company assumes that the core files are untouched. In case changes are done to the core files, updating Magento will overwrite the core files, doing away with all the custom code.

How To Upgrade Magento 2 Via Command Line

Follow the steps below to upgrade your Magento 2 via CLI.

Step 1: Access Your Magento Server Via SSH

You need to login to your Magento server using your SSH credentials.

Step 2: Navigate to Magento 2 Root Directory

Once you are connected, navigate to your Magento 2 root directory. Usually, it is public_html.

Step 3: Apply Upgrade Commands

Apply the following commands to upgrade.

 
composer require magento/product-community-edition=2.3.3 --no-update

composer update

Version 2.7.7 is the latest version. You can change this number accordingly.

Step 4: Enter your Authentication Keys

It will ask for authentication keys. If you don’t know how to find/generate authentication keys, click here.

Step 5: Manually Clear Cashes and Generated Content.

 
rm -rf var/di/* var/generation/* var/cache/* var/log/* var/page_cache/*

Step 6: Update the Database Schema & Data

 
php bin/magento setup:upgrade

Step 7: Disable Maintenance Mode

You are ready to make your store live again.

 
php bin/magento maintenance:disable

Conclusion

That’s all you needed to do. Now, open your storefront URL in a web browser and see if the upgrade was successful. Check your Magento 2 version to ensure that the update was successful.

Read More:

This blog was created with FME's SEO-friendly blog