Loading..
Processing... Please wait...

Product was successfully added to your shopping cart.



Magento 2 Upgrade in 3 Easy Steps (Updated 2018)

Today I will describe how you can perform a Magento 2 upgrade.

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.

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

  1. Magento composer update. That is using Composer, a terminal command line program.
  2. Upgrade Magento from admin using the Web Setup Wizard.
  3. 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.2.0):

Set the latest Magento 2 version in composer.json Set the Latest Magento 2 Version in Composer.json

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/:

Magento marketplace public/private keys Magento Marketplace Public/Private Keys

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:

Magento 2 upgrade with composer Magento 2 Upgrade with Composer

UPDATE: If you don't want to edit any files you can run the following command to update to the latest Magento release (2.2.5 at the moment):

composer require magento/product-community-edition 2.2.5 --no-update
composer update

If you are running Magento 2 commerce the command will be slightly different:

composer require magento/product-enterprise-edition 2.2.5 --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. That is a bug which is not fixed as of Magento 2.1.8. The simple workaround is:

  1. Login to Magento backend.
  2. Go to http://shop.com/admin_xxx/admin/backendapp/redirect/app/setup/. http://shop.com/admin_xxx is path your backend.
  3. You will be automatically redirected to http://shop.com/setup/#/home. There you will select System Upgrade.
Magento 2 Web Setup Wizard Magento 2 Web Setup Wizard

Click on System Upgrade and follow instructions. They are self-explanatory.

If Show All Versions is checked you can upgrade to unstable development releases.

Magento 2 web setup wizard upgrade Magento 2 web setup wizard upgrade

At Step 2. Readiness Check you might need to upgrade your PHP. Or install plugins. Do as suggested:

Step 2. Rediness Check Step 2. Readiness Check

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 2 upgrade 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:

Component Dependency Conflict Component Dependency Conflict

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:

  1. Uninstall all custom extensions.

  2. Perform an update to the latest Magento version.

  3. 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 
'Magento\Framework\Exception\LocalizedException' 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): 
Magento\Framework\Code\Generator->generateClass('Magento\\Framewo...') 
#1 [internal function]: Magento\Framework\Code\Generator\Autoloader->load('Magento\\Framewo...') 
#2 [internal function]: spl_autoload_call('Magento\\Framewo...') 
#3 /var/www/html/site/vendor/magento/framework/Code/Reader/ClassReader.php(19): ReflectionClass->__construct('Magento\\Framewo...') 
#4 /var/www/html/site/vendor/magento/framework/ObjectManager/Definition/Runtime.php(44): Magento\Framework\Code\Reader\ClassReader->getConstructor('Magento\\Framewo...') 
#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:

  1. Delete var/di folder.

  2. Change permissions of var and pub folder to 777 (chmod -R 777 var pub).

  3. Run php bin/magento setup:upgrade.

  4. 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.2 update? Contact me today for a free quote!

  

Need help with a Magento site? Hire me!

 

Other articles you might be interested in:

  1. Magento Enterprise 1.14 to Community 1.9 Downgrade

  

If you find this post interesting do not hesitate to sign up for our newsletter and join the 874 people who receive Magento news, tips and tricks regularly.

Thank You!

 

2 thoughts on “Magento 2 Upgrade in 3 Easy Steps (Updated 2018)”
  • seanmal
    seanmal July 8, 2018 at 1:48 am

    One can upgrade magento 2 using the two basic methods, one is from admin panel and other is using composer

  • markwarner
    markwarner September 26, 2017 at 12:42 am

    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!