There are various ways to upgrade your Magento 2 website to a higher version. This post is gonna show you how to do that via command line.
You can upgrade Magento from the command line if you installed the software using any of the following:
- Downloaded the metapackage using composer create-project
- Installed the compressed archive
How to upgrade Magento 2 via command line
1. Put your store in maintenance mode:
To prevent any access during upgrading process, it’s necessary to set maintenance mode for your site.
Here is the simplest way to enable this mode:
- Log in to your Magento server as, or switch to, the Magento file system owner.
- Enter the following command:
php <your Magento install dir>/bin/magento maintenance:enable
2. Upgrade using Command line:
Step 1: Log in to your Magento server as, or switch to, the Magento file system owner.
Step 2: Change to the directory in which you installed the Magento software.
For example: cd /var/www/html/magento2
Step 3: Enter the following commands in the order shown:
composer require <product> <version> --no-update composer update
For example, to upgrade to Magento Open Source version 2.0.14, enter:
composer require magento/product-community-edition 2.0.14 --no-update composer update
Step 4: Then enter your authentication keys.
Step 5: Manually clear var subdirectories:
rm -rf <Magento install dir>/var/cache/* rm -rf <Magento install dir>/var/page_cache/* rm -rf <Magento install dir>/var/generation/*
If you use a cache storage other than file system (e.g., Redis, Memcached, etc.) you need to manually clear the cache there too.
Step 6: Update the database schema and data:
php bin/magento setup:upgrade
Step 7: Put your storefront online (it means to disable the maintenance mode):
php bin/magento maintenance:disable
Step 8: Restart Varnish if you use it for page caching.
service varnish restart
Step 9: Access your storefront.
The following error might display: We’re sorry, an error has occurred while generating this email.
Please perform the following tasks:
- Reset file system ownership and permissions as a user with root privileges.
- Clear the following directories and try again:
<your Magento install dir>/var/cache <your Magento install dir>/var/page_cache <your Magento install dir>/var/generation
After the upgrade, again check your Magento version with the following command:
php bin/magento —version