This article shows how you can upgrade/update your Magento 2 version through command line using composer.
Upgrading to Magento 2.3.x is a bit different than that of Magento 2.2.x or 2.1.x.
At first, I will show the commands that need to be run to upgrade Magento2 to version 2.1.x or 2.2.x.
Upgrading Magento to 2.2.x
In this example, I am upgrading Magento 2 to version 2.2.6.
Here are commands to run on terminal/command-prompt:
php bin/magento maintenance:enable
composer require magento/product-community-edition 2.2.6 --no-update
composer update
rm -rf var/di var/generation
php bin/magento cache:flush
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento indexer:reindex
php bin/magento maintenance:disable
Note: In Ubuntu/Debian Linux, if you are having permission issues then try using sudo at the beginning of every command. For example, sudo composer update
After you have upgraded Magento 2, you can check your Magento’s version with the following command:
php bin/magento --version
If you get cache write permission error when you browse your Magento site after upgrade, then run the following command to give write permission to pub and var directories:
chmod -R 777 pub var
Upgrading Magento to 2.3.x
The above commands work fine while upgrading Magento to 2.2.x.
To upgrade to Magento 2.3.x, you need to follow some more steps.
Here’s the step-by-step guide to upgrade Magento to 2.3.x:
Enable maintenance mode
php bin/magento maintenance:enable
Specify Magento packages
composer require magento/product-community-edition=2.3.0 --no-update
Specify additional packages
composer require --dev phpunit/phpunit:~6.2.0 friendsofphp/php-cs-fixer:~2.10.1 lusitanian/oauth:~0.8.10 pdepend/pdepend:2.5.2 sebastian/phpcpd:~3.0.0 squizlabs/php_codesniffer:3.2.2 --no-update
Remove unused packages
composer remove --dev sjparkinson/static-review fabpot/php-cs-fixer --no-update
Update autoload
Open composer.json
and edit the "autoload": "psr-4"
section to include "Zend\\Mvc\\Controller\\": "setup/src/Zend/Mvc/Controller/"
:
"autoload": {
"psr-4": {
"Magento\\Framework\\": "lib/internal/Magento/Framework/",
"Magento\\Setup\\": "setup/src/Magento/Setup/",
"Magento\\": "app/code/Magento/",
"Zend\\Mvc\\Controller\\": "setup/src/Zend/Mvc/Controller/"
},
...
}
Apply updates
composer update
Clean the Magento cache
php bin/magento cache:clean
Manually clear caches and generated content
Clear the var and generated subdirectories:
rm -rf <Magento install dir>/var/cache/*
rm -rf <Magento install dir>/var/page_cache/*
rm -rf <Magento install dir>/generated/code/*
If you use a cache storage other than the filesystem, such as Redis or Memcached, you must manually clear the cache there too.
Update the database schema and data
php bin/magento setup:upgrade
Disable maintenance mode
php bin/magento maintenance:disable
Finally, check your Magento version
php bin/magento --version
Read more: https://devdocs.magento.com/guides/v2.3/comp-mgr/cli/cli-upgrade.html
Hope this helps. Thanks.