This post describes how to update Magento 2 to the latest available version. Below, you will find all the necessary information related to the procedure, including some vital prerequisites. So, the version of your platform is a little bit outdated? Find out how to update it with the following Magento 2 tutorial.
First of all, you should peform Magento 2 download and installation. Then, it is necessary to log in as a Magento server user with permissions to write to the Magento 2 file system. You can choose a web server user, for instance.
Another important preparation is the ability to run Magento commands from any directory. Therefore, add <your Magento install dir>/bin to your system PATH. Check unix.stackexchange.com for more information. In case of CentOS, bash shell example has the following look: export PATH=$PATH://var/www/html/magento2/bin.
Note that you have alternate ways for running commands:
This part of the Magento 2 tutorial describes how to update the software without reinstalling it. Being crucial for getting all the latest code changes, the procedure requires doing everything in an development environment.
1. Now, when you are logged as a user with permissions to modify files in the file system of Magento 2, save all changes to composer.jsonsince the following actions will overwrite it:
cd<your Magento install dir>
cp composer.json composer.json.old
2. Use the following command, in case when the optional sample data has been installed:
3. Now, it’s time to get the latest code by updating your local repository:
git pull origin master
Magento 2 GitHub repository have two major branches: master & develop. Master offers the latest stable version of code, while develop can have some new features and fixes which are not yet ready for production. If the command described above fails, check the official troubleshooting.
4. The fourth step requires diffing and merging composer.json.oldwith composer.jsoninstalled with the Magento 2 software. These actions are possible with the aid of the following command:
5. After manipulations with composer.json, you should update the Magento 2 database. Run the command below:
php bin/magento setup:upgrade
6. The last step of this Magento 2 tutorial requires clearing vardirectory contents. The following command will help you to achieve your goal:
Now, you know how to update Magento 2. If you have any questions, ask us in comments – Firebear team is always here to help you. For more information, check the official Magento 2 update guide.
Magento 2 Command Line Update
It is possible to upgrade Magento using the command line if your software was installed by downloading the meta package via the composer create-project command or was installed as the compressed archive.
Do not use the command line upgrade in case you cloned the Magento 2 GitHub repository. You should implement the aforementioned approach.
And don’t forget to perform these tasks, if you’re upgrading from 2.0.0 or 2.0.1.
If you set the Magento root directory to <your Magento install dir>/pub, perform the following prerequisites. In case you didn’t do this, dismiss the prerequisite section.
Create another docroot or subdomain that utilizes the Magento installation directory as the root. The System Upgrade utility should be run using that subdomain.
Command Line Update
1. Be log in to your Magento server as a file system owner.
2. Change to the directory with the installed Magento software (e.g. cd /var/www/html/magento2)