How to Update Magento 2 (composer way)

Magento 2 offers possibility to update it’s self through  Magento backend panel or trough composer  (described here).

First of all check if the cache is enabled:

php bin/magento cache:status

If it is enabled you’ll get something similar to this:

So we need to disable the cache:

That been done we can go further to the actual update process.



The must important part is to provide the proper record in composer.json.

As my project is still in development and the updates are quite often I have the following record in composer.json which allows me to update to any version of Magento 2.

But in a production website I would go with a fixed value, like:

"require": {
     "magento/product-community-edition": "2.1.6"

In this way you get  to control when the new version is getting installed (avoiding mistakes).


Backup DB (precautions)

Before upgrading the database it’s a good idea to make a DB backup (Magento will put the store in maintenance mode, dump the database into a file and take out the store from maintenance mode) :

php bin/magento setup:backup --db

After we have the backup we run the DB upgrade:

php bin/magento setup:upgrade

Once everything is done we can enable back the magento cache:

php bin/magento cache:enable


And, to make sure we have the proper version run this command

php bin/magento --version