Today I will explain how you can upgrade Magento 2.3 to 2.4 (the latest version is 2.4.7-p3).
I'll also list most common post-upgrade issues and how to fix them.
When you run an eCommerce store it is vital to stay secure and up to date. You should always look out for the latest M2 version and update promptly.
Running the latest platform version will help with improving performance and keeping hackers and skimmers away.
A word of advice: always backup your files and database before attempting an upgrade. With a platform as complex as Magento 2 you can’t anticipate what is going to happen next. A lot of things might go wrong. You better have a way to go back.
2 Ways to Upgrade Magento 2 Installation
- Magento composer update. That is using Composer, a terminal command line program.
- Copy the Magento 2 latest version over the old installation.
1. Using Composer
Composer is a dependency manager for PHP. It can help you update your store with minimum hassle.
Instructions to get Composer installed might depend on your server operating system. I will use Debian Linux as an example. Run this SSH command:
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
It will install Composer systemwide for every user to run. You can always ask your system administrator for assistance.
Now for the upgrade itself you will need to use SSH (Secure Shell). Ask your hosting company for credentials. Login to your server and go to the Magento root folder (usually it is ~/public_html):
cd ~/public_html
Then remove everything in the vendor folder:
rm -rf vendor/*
Now you can open composer.json file and replace your current version with the latest version sequence (2.4.7-p3):
Then start the update itself:
composer update
Alternatively, you can issue a single command that does everything (this is for an Open Source version only):
composer require magento/product-community-edition=2.4.7-p3 -W
Include -W switch to upgrade all dependency packages and extensions.
Note: composer can refuse to run because some of your server software isn't compatible with the latest Magento 2.
For example, your server PHP version is too old:
Error: magento/product-community-edition 2.4.7-p3 requires php ~8.1.0||~8.2.0||~8.3.0 Your PHP version (8.0.2) does not satisfy that requirement
Or too new:
composer require magento/product-community-edition=2.4.6-p8 -W
I'd recommend to upgrade or downgrade PHP to the supported version and try again.
You can always attempt to skip server requirements with a --ignore-platform-reqs flag:
composer require magento/product-community-edition=2.4.7-p3 -W --ignore-platform-reqs
Run it at your own risk.
Composer will ask you for credentials. You may obtain those at Adobe Commerce Marketplace, here is the link https://commercemarketplace.adobe.com/customer/accessKeys/:
One thing to remember: username is a public key and password is a private key. That is one of the ways Magento might confuse you.
Once you enter credentials, Composer will go ahead and install the latest Magento 2 version:
composer require magento/product-enterprise-edition=2.4.7-p3 -W
When it is completed, run another SSH command and upgrade the Magento database:
php bin/magento setup:upgrade
After that you will want to recompile if you are in production mode:
php bin/magento deploy:mode:set production
This is it. You’ve successfully upgraded the platform to the latest version! Now go to the frontend and backend and check everything.
NB: Composer might complain about some PHP extensions not being downloaded. You might want to install them in order to proceed.
2. Download the latest version manually and copy/paste
Upgrade this way if the previous one failed for whatever reason.
Download the latest Magento 2 Open Source from the official github page. Unzip it in your magento main folder. That will overwrite the core files with the new ones.
Then run:
php bin/magento setup:upgrade
...and
php bin/magento deploy:mode:set production
That will upgrade database, compile and deploy static content. It might require some time depending on the number of products, orders and customers you have.
Upgrade is done. Head to frontend and backend and see if everything looks normal.
Should I update my theme after an upgrade?
If it’s a custom-made theme you should definitely contact its developers and ask them to audit it. Tell them you just upgraded M2 and you are not sure if the theme will play well with the current Magento version.
If you purchased a premade theme the vendor usually releases patches for every new M2 version that comes out. Go to templatemonster.com or the site you bought your theme from and see if there are updates available for download.
It is important that you check your Magento frontend pages for any misaligned or missing content. A new version can cause serious damage to the look of your website.
What if things go the wrong way?
As with everything in Magento, an upgrade is easier said than done. Below I put together the various errors (and suggested fixes) that might happen during the upgrade process.
1. Your requirements could not be resolved to an installable set of packages
This error happens when you upgrade Magento with composer. The description helps to fix it:
In the case above, you just need to downgrade PHP to 8.2 in order to update to 2.4.6-p8.
Sometimes, a package version isn't compatible with the newest Magento. You can edit composer.json and put * next to the package:
Putting * tells composer to update the package to the most compatible version.
2. Could not validate a connection to Elasticsearch. No alive nodes found in your cluster
Magento 2.4+ requires OpenSearch (ElasticSearch) server to function properly.
Ask your hosting team to provide you with OpenSearch host and port (and username and password if it's required).
If you are self hosting, you can install ElasticSearch or OpenSearch with the help of a package manager. For example, on Debian:
apt-get install elasticsearch
Once you have host and port number, you can update Magento configuration with the direct SQL queries (suppose we installed ElasticSearch 7):
UPDATE core_config_data SET value='elasticsearch7' WHERE path='catalog/search/engine'; UPDATE core_config_data SET value='host' WHERE path='catalog/search/elasticsearch7_server_hostname'; UPDATE core_config_data SET value='port' WHERE path='catalog/search/elasticsearch7_server_port';
3. Can’t create a directory
This error happens when you run php bin/magento setup:upgrade right after an upgrade. The complete issue description might look like this:
Fatal error: Uncaught exception 'MagentoFrameworkExceptionLocalizedException' with message 'Can't create directory /var/www/html/site/var/generation/Magento/Framework/App/ResourceConnection/.' in /var/www/html/site/vendor/magento/framework/Code/Generator.php:103 Stack trace: #0 /var/www/html/site/vendor/magento/framework/Code/Generator/Autoloader.php(35): MagentoFrameworkCodeGenerator->generateClass('MagentoFramewo...') #1 [internal function]: MagentoFrameworkCodeGeneratorAutoloader->load('MagentoFramewo...') #2 [internal function]: spl_autoload_call('MagentoFramewo...') #3 /var/www/html/site/vendor/magento/framework/Code/Reader/ClassReader.php(19): ReflectionClass->__construct('MagentoFramewo...') #4 /var/www/html/site/vendor/magento/framework/ObjectManager/Definition/Runtime.php(44): MagentoFrameworkCodeReaderClassReader->getConstructor('MagentoFramewo...') #5 /var/www/html/site/vendor/magento/framework/ObjectMana in /var/www/html/site/vendor/magento/framework/Code/Generator.php on line 103`
What should you do in this case? The fix is very simple:
- Delete var/di folder.
- Change permissions of var and pub folder to 777 (chmod -R 777 var pub).
- Run php bin/magento setup:upgrade.
- Run php bin/magento setup:di:compile.
4. Cannot allocate memory error
If you encounter this error during an upgrade it means there is not enough RAM allocated to PHP processes. Contact your system administrator and ask him/her to increase memory limit to at least 2 Gs.
A quick fix that I usually do is putting memory_limit in bin/magento script:
#!/usr/bin/env php <?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ ini_set('memory_limit','4G'); /* Increase Memory Limit */ if (PHP_SAPI !== 'cli') { echo 'bin/magento must be run as a CLI application'; exit(1); }
Of course that means you cannot safely run Magento 2 on a server with less than 2G of available RAM. You should upgrade your plan to meet the minimal hardware requirements.
5. There are no commands defined in the "setup" namespace
This is a generic message that might not be helpful.
There are various ways to try to fix the error:
- Give full permission to var and pub folders:
sudo chmod -R 777 var pub
- Inspect your custom modules, make sure every extension's module.xml has setup_version in it:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> <module name="SomeVendor_SomeModule" setup_version="1.1.2"/> </config>
- Inspect your composer.json file. Sometimes an error there might cause a command to throw the"no commands defined" exception.
6. php bin/magento setup:upgrade not working
From my experience this is mostly related to some custom module having a problem. Try to inspect every one of them to see if you could spot an error.
Try to delete every custom module, update your instance and install them back.
Sometimes clearing generated (the latest 2.2.x versions) or var/di, var/generation (in case of an older Magento 2.1 upgrade) folders helps.
7. The site is slow after the upgrade
Check to see if all your cache is enabled:
php bin/magento cache:status
Sometimes, composer can turn off some of your caches for whatever reason. If it's off, turn it on:
php bin/magento cache:enable
The speed should improve afterwards.
If you are interested to see how else you can speed up Magento - check out 35 tips to fix a slow online store.
8. Checkout page not loading after the upgrade
After an upgrade to 2.4.7-p3 the checkout page might fail to render correctly.
It happens because Content-Security-Policy (CSP) is now enforced (in strict mode) on payment pages to make Magento 2 PCI complaint:
vendor/magento/module-checkout/etc/config.xml:
<csp> <mode> <storefront_checkout_index_index> <report_only>0</report_only> </storefront_checkout_index_index> </mode> <policies> <storefront_checkout_index_index> <scripts> <inline>0</inline> <event_handlers>1</event_handlers> </scripts> </storefront_checkout_index_index> </policies> </csp>
Strict CSP mode tells a browser to only run JavaScript from whitelisted sources. Inline scripts are not allowed.
Some one step checkout extensions might not work correctly because of it. You can either request an update from the vendor or turn off CSP (not recommended).
To temporarily turn off CSP on the checkout page, set report_only=1 in a custom module etc/config.xml file:
<csp> <mode> <storefront_checkout_index_index> <report_only>1</report_only> </storefront_checkout_index_index> </mode> </csp>
Bonus: Can I downgrade Magento 2 the same way I upgrade?
Yes you can!
You should follow step 1 and downgrade with Composer. Just put the version number you would like to have and repeat everything else.
I have tried this method and successfully downgraded from 2.4.6 to 2.4.3.
You can follow step 2 to downgrade M2.
I hope now you have learned how to upgrade Magento 2 to the latest version. At least I hope I managed to explain it well in this article. If you have any questions you are more than welcome to ask them at the bottom of this page.
Do you know Magento 2 can be slow? And slow checkout leads to sloppy conversion rates.
Check these 35 ways to improve Magento 2 performance.
Contact an expert to make your Magento faster.
Do you need a Magento 2 update? Contact me today for a free quote!
Find this article useful? Share it on LinkedIn with your professional network, spread the knowledge!
If you find this post interesting do not hesitate to sign up for our newsletter and join the 1686 people who receive Magento news, tips and tricks regularly.
Thank You!
The blog on **upgrading Magento 2.3 to 2.4** offers a comprehensive guide for developers and store owners. The step-by-step process is well-explained, making it easier to understand the complexities of upgrading. I particularly appreciate the emphasis on creating backups and testing in a staging environment to avoid downtime or data loss during the upgrade. The inclusion of command-line instructions and tips for resolving common issues is very helpful. For those considering further upgrades, I recommend exploring **Magento 2.4.7**, which introduces enhanced performance, security updates, and new features. Check out the **TheCoachSMB** blog for more expert tips and tutorials on Magento upgrades!
Thanks for sharing the comprehensive post, your post having informative & valuable content, it will be helpful.
Great Article on Magento 2 Upgrade!
Nice article to helpful for upgrade Magento 2 version.
Its the same process as to upgrade with the latest version 2.4.0?
Nice! blog seems helpful, Guidance Makes update ease.......Mentioning conflicts were also assured error-free upgrade.
Thanks for the useful article!
In this blog is very useful to upgrade in Magento skills. Thanks for sharing this information.
Written in a very detailed and organized manner. Apart from backing up the database, checking compatibility still remains the main issue in an upgrade. My recommendations:
• Make a full backup of your Magento 1 store including all files, folders, and the database.
• Create a clone of your Magento 1 store. Do not use the live store for Magento migration process.
• Analyze your store. Keep what you think is necessary and delete the rest.
• Check whether your current theme(s), extensions and custom code are compatible with the Magento 2.
• Migrate the data from the cloned database of your Magento 1 store.
• Remove outdated and useless data from the database. This includes logs, recently viewed products, compared products.
• To make Magento migration process as hassle-free as possible, install a fresh copy of Magento 2 on the same hosting server where your Magento 1 store is located.
Thanks for this guide for upgrading Magento, I wanted to upgrade my website because of a marketplace extension which I learned about on Magenticians, which is not compatible with my website. Thanks again
Your article Awesome Thanks for this information, very informative as well as Modern.
One can upgrade magento 2 using the two basic methods, one is from admin panel and other is using composer
Good tips to upgrade the Magento! Many people want to upgrade their Magento with the higher version. After visiting this article, they can have a rough idea of upgrading their Magento versions! Looking to visit this article more often in the future!