How to upgrade Magento 2 from the command line?
Remember, you can upgrade Magento with the command line only if you set up the software by:
- Downloading the metapackage with the use of composer create-project
- Installing the archive
How to update Magento from the command line?
Step 1. Make the following prerequisites:
- Determine if your current catalog search engine is supported
- Check the Upgrade and Upgrade checklist
- Set the root of the pub/ directory
- Review PHP and environment setting
- Turn to maintenance mode
- Review the status of cron jobs
- Install Composer Update Plugin:
Do this to install the plugin:
composer require magento/composer-root-update-plugin=~1.0 --no-update
To update dependencies:
Step 2. Managing packages:
Make a backup copy of your composer.json file.
Add or remove specific packages based on your needs.
composer remove magento/product-community-edition --no-update
Specify Magento 2 packages by including the edition and version you want to upgrade to in the upgrade command:
composer require magento/product-community-edition=2.4.7 --no-update
composer require magento/product-enterprise-edition=2.4.7 --no-update
Step 3. Updating meta:
Update the "name", "version", and "description" in the composer.json file bases on your needs.
After that, apply the updates:
Now clean the var/ and created/ subdirectories:
rm -rf var/cache/*
rm -rf var/page_cache/*
rm -rf generated/code/*
Update the schema and database data with the following Magento setup upgrade command:
Disable maintenance mode.
Restart Varnish if you use it to cache pages:
service varnish restart
Step 4. Check the work:
Open the URL of your page in a browser to check if the update was successful. If the update was unsuccessful, then your page will not load as expected.
If you have updated Magento data but notice problems and lags in the work, then you should optimize your site. Magento Optimization Service will help you understand what is the cause of the problems and improve the speed of your website. Our specialists will conduct a full audit of your page, identify all the problems, and suggest ways to fix them, after which it is up to you to decide how to fix them and whether to fix them at all. If the decision is positive, then our team will carry out all the necessary work and provide a 2-month warranty for the work performed and answer all your questions.