Back to Top

How to upgrade Magento 2 to the latest version ( Command Line)

Updated 12 September 2023

Magento latest release always focus on enhancing the security, improving performance and fixing bugs. With the help of this blog you can do the Magento 2 Upgrade.

Please check the system requirements for your latest Magento version here.

https://experienceleague.adobe.com/docs/commerce-operations/installation-guide/system-requirements.html

Note: It is recommended to take the backup of the code and database if you are planning to upgrade your live site.

In the following steps we will upgrade from Magento 2.3.5-p2 to Magento 2.4.5.

Searching for an experienced
Magento 2 Company ?
Find out More

Step 1 -> Change your composer version to the compatible version of latest Magento version.

composer -vvv about

Step 2 -> Take a backup of the composer.json

cp composer.json composer.json.bak

Step 3 -> Put your site into maintanance mode.

php bin/magento maintenance:enable

Step 4 -> Install the Composer update plugin

composer require magento/composer-root-update-plugin=~2.0 --no-update

Step 5 -> Update Magento version in composer.json file using below command. You can type the any required Magento version.

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

Step 6 -> This step keeps you safe from the dependency version issues. You have to update “require-dev” key in root composer.json. You can see this in the magento composer.json file on github.

Following are the magento 2.4.4 and 2.4.5 with their compatible dependencies.

https://github.com/magento/magento2/blob/2.4.4/composer.json#L113

https://github.com/magento/magento2/blob/2.4.5/composer.json#L113

Here we are using the require-dev of Magento 2.4.5.

"require-dev": {
    "allure-framework/allure-phpunit": "~1.5.0",
    "dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
    "friendsofphp/php-cs-fixer": "~3.4.0",
    "lusitanian/oauth": "~0.8.10",
    "magento/magento-coding-standard": "*",
    "magento/magento2-functional-testing-framework": "^3.7",
    "pdepend/pdepend": "~2.10.0",
    "phpmd/phpmd": "^2.12.0",
    "phpstan/phpstan": "^1.6.8",
    "phpunit/phpunit": "~9.5.20",
    "sebastian/phpcpd": "^6.0.3",
    "squizlabs/php_codesniffer": "~3.6.0",
    "symfony/finder": "^5.2"
},

Step 7 -> Now change php version to the compatible version with magento 2.4.5.

sudo a2dismod php7.3
sudo a2enmod php8.1
sudo update-alternatives --set php /usr/bin/php8.1
sudo /etc/init.d/apache2 restart
php --version

Step 8 -> Update dependencies using the following command.

composer update

Step 9 -> Execute the following commands.

rm -rf var/cache/*
rm -rf var/page_cache/*
rm -rf generated/code/*
bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento c:f

Step 10 -> Check base url in core_config_data and update with adding pub/ after base url.
For example https://devmage.com/m235p2 to https://devmage.com/m235p2/pub

php bin/magento c:f

Step 11 -> Disable the maintenance mode

php bin/magento maintenance:disable

Hope this helps, Thanks ­čÖé

You can also explore more about Magento 2 Upgrade Services to update your e-commerce website with the latest Magento version or migrate from another e-commerce platform.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home