Upgrading Magento 2 from the command line is a straightforward process. Here’s a step-by-step guide on how to upgrade Magento 2 from the command line:
- Backup your Magento 2 site files and database to ensure you have a restore point in case something goes wrong during the upgrade process.
- Connect to your server via SSH.
- Navigate to your Magento 2 root directory using the cd command.
- Put your site into maintenance mode by running the following command:bash
bin/magento maintenance:enable
- Check for updates by running the following command:sql
composer update
This command will check for available updates for your Magento 2 installation and its dependencies.
- Upgrade to the latest version by running the following command:lua
composer require magento/product-community-edition=X.X.X --no-update
Replace X.X.X with the version number you want to upgrade to. This command will update the composer.json file to require the new version of Magento 2.
- Run the following command to update the composer.lock file:sql
composer update
This command will download and install the latest version of Magento 2 and its dependencies.
- Update the database schema and data by running the following command:python
bin/magento setup:upgrade
- Re-compile your code by running the following command:python
bin/magento setup:di:compile
- Clear the cache by running the following command:
python
bin/magento cache:flush
- Disable maintenance mode by running the following command:
bash
bin/magento maintenance:disable
Your Magento 2 site should now be upgraded to the latest version. You can verify the version number by logging into the Magento 2 admin panel and checking the footer of the page.