
Today I will describe how you can perform a Magento 2 Upgrade Service.
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.
We strongly suggest you use an expert to upgrade your Magento 2 site.
Submit a form to get a free quote.
If you decide to perform a service yourself, follow the instructions below.
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.
3 Ways to Upgrade Magento 2 Installation
- Magento composer update. That is using Composer, a terminal command line program.
- Upgrade Magento from admin using the Web Setup Wizard.
- 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 (say 2.4.3):
When that is done go to SSH and update Magento 2 with Composer:
composer update
It will ask you for credentials.You may obtain those at Magento marketplace, here is the link https://marketplace.magento.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:
UPDATE: If you don't want to edit any files you can run the following command to update to the latest Magento release (2.4.3 at the moment):
composer require magento/product-community-edition 2.4.3 --no-update composer update
If you are running Magento 2 commerce the command will be slightly different:
composer require magento/product-enterprise-edition 2.4.3 --no-update composer update
Replace 2.2.5 with the latest M2 version.
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 performed a Magento 2 upgrade! 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. Using the Web Setup Wizard in the Admin Menu
Magento 2 has a menu option under System > Tools called Web Setup Wizard. You can use it to install extensions bought via the Magento Marketplace. You can also use it to upgrade Magento.
NB: There might not be such a link in your installation. The link might disappear after your migrated from Magento 1.
The simple workaround is:
- Login to Magento backend.
- Go to http://shop.com/admin_xxx/admin/backendapp/redirect/app/setup/. http://shop.com/admin_xxx is path your backend.
- You will be automatically redirected to http://shop.com/setup/#/home. There you will select System Upgrade.
Click on System Upgrade and follow instructions. They are self-explanatory.
If Show All Versions is checked you can upgrade to unstable development releases.
At Step 2. Readiness Check you might need to upgrade your PHP. Or install plugins. Do as suggested:
I suggest you backup your files and database manually. Skip Create Backup step. It might hang and you will need to start over.
3. Download the latest version manually and copy/paste
Upgrade this way if the previous two failed for whatever reason.
Download the latest Magento 2 off the official website. 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 Magento 2 upgrade 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 Magento upgrade service process.
1. Component dependency conflict
This problem happens when you try and upgrade Magento via Setup Wizard. At the Readiness Check step it might throw out an exception like this:
There is no real explanation of the issue and you might wonder how to fix it. From my experience dependency conflict in most cases is caused by a third-party extension depending on some old Magento 2 component.
You can resolve the issue by doing the following:
- Uninstall all custom extensions.
- Perform an update to the latest Magento version.
- Reinstall the custom extensions.
In some cases the conflict is caused by a changed composer.json file. Try and restore composer.json to the original version and run Setup Wizard one more time.
2. Can’t create 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.
3. 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.
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.
4. 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:
1. Give full permission to var and pub folders:
sudo chmod -R 777 var pub
2. 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>
3. Inspect your composer.json file. Sometimes an error there might cause a Magento 2 upgrade command to throw the"no commands defined" exception.
5. 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.
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 2.1.8 to 2.1.6.
I don't think you can use the Web Setup Wizard, but I am sure you can follow step 3 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 34 ways to improve Magento 2 & 1 performance.
Contact an expert to make your Magento faster.
Do you need a Magento 2 update? Contact me today for a free quote!
If you find this post interesting do not hesitate to sign up for our newsletter and join the 1307 people who receive Magento news, tips and tricks regularly.
Thank You!
Great Article on Magento 2 Upgrade!
Nice! blog seems helpful, Guidance Makes update ease.......Mentioning conflicts were also assured error-free upgrade.
Thanks for the useful article!
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!