Magento 2 Tutorial: How to Install, Upgrade, and Migrate to Magento 2

Magento 2 Tutorial. Sketch

Magento 2 is a superb eCommerce platform with a more flexible architecture (comparing to Magento 1), first-class performance, engaging shopping experience, and brand-new features. However, Magento 2 is a new platform; that means, you’ll have to spend plenty of time searching for the solution of a problem on the Internet. SaM Ecommerce is a Trained Magento 2 Solution Partner and we’re eager to lend you a willing hand in this difficult situation. In the given Magento 2 tutorial, we're going to have a close look at the process of migration, installing, and updating of Magento 2.

How to Migrate from Magento 1 to Magento 2?

How to migrate from Magento 1 to Magento 2? Sketch

Probably, the question about the process of migration is the most popular one, and we’ve already answered it long ago. Check out our article Magento 2 Migration Tool, where you’ll find a step-by-step tutorial on migration from Magento 1 to Magento 2 using a Data Migration Tool. 

Using this Tool you’ll be able to perform a store data migration. To migrate some customizations use a Code Migration Toolkit that focuses on Magento modules migration. Unfortunately, this Toolkit can’t help you with themes migration; moreover, you'll need a developer to manually adapt some files. But still, it does perform the most tedious tasks: the Toolkit deals with the migration of a module directory structure, layout and config XML files and PHP files.

For adapting custom Magento 1 code to Magento 2 with the help of the Code Migration Toolkit you need PHP 5.5.x or higher and a composer dependency management software. 

  1. In the Code Migration Toolkit, run composer install.
  2. Somewhere in the file system (it doesn’t matter where exactly), arrange such directories:
  • <src> with a custom Magento 1 code (which will be adapted) and without core files.
  • <dst> must be empty: it will be filled with the generated Magento 2 code.
  • <m1> with the standard as well as with the custom Magento 1 code and dependencies of the last one.
  • <m2> with the standard Magento 2 codebase.

3. The quality of migration highly depends on the correctness of mapping files. Thus, our next step will be to regenerate mapping files. Run:

  • php bin/utils.php generateClassDependency <m1> 
  • php bin/utils.php generateClassMapping <m1> <m2> 
  • php bin/utils.php generateModuleMapping <m1> <m2>  
  • php bin/utils.php generateTableNamesMapping <m1>  
  • php bin/utils.php generateViewMapping <m1> <m2> 
  • php bin/migrate.php generateAliasMapping <m1>  
  • php bin/migrate.php generateAliasMappingEE <m1>  

4. Carry out the migration script in the following order:

  • php bin/migrate.php migrateModuleStructure <src> <dst> This script doesn’t change the content of files; it arranges a suitable Magento 2 module directory and sends the current Magento 1 code there.
  • php bin/migrate.php convertLayout <dst> This script does make some changes to files: it breaks them up into isolated XML files for all layout handles individually and changes their format to the appropriate for Magento 2 one. 
  • php bin/migrate.php convertConfig <dst> This script performs the same job as the previous one but with config files.
  • php bin/migrate.php convertPhpCode <dst> <m1> <m2> This script changes the major part of the PHP code to the one that agrees with the Magento 2 Framework. 

To streamline the process of migration from Magento 1 to Magento 2, exploit the Data Migration Tool and the Code Migration Toolkit. You aren't able to migrate themes as they must be created from scratch to suit new approaches of the new Magento platform. 

How to Install Magento 2?

How to install Magento 2? Sketch

In case you’re new in the retailing business and can’t decide which Magento platform to choose, we advise you to go with Magento 2 as pretty soon Magento Inc. will stop supporting Magento 1. We’ve written about that in great detail with references to official sources in our recent article The Official Date of Magento 1.x End of Life

So let’s go back to the question: how to install Magento 2? Actually, we’ve already answered this question in the article How to Install Magento 2 with Composer? where we share our own experience. Hope, the article will help you to install Magento 2 without any other help.

How to Upgrade Magento 2?

How to Upgrade Magento 2? Sketch

We sincerely advise you to regularly upgrade your Magento 2 to the latest version as:

  • There you may find new enhanced functions (the latest version as of the date of publishing the article is Magento 2.1.7, and it offers one new function ).
  • The bugs of the previous version are fixed.
  • It guarantees the security of your Magento 2 software (Magento 2.1.7 contains over 15 security enhancements).

So how to upgrade Magento 2? For the time being, Magento 2.1.7 is the latest version that contains over 15 security enhancements. It’s highly recommended to upgrade to this latest version as soon as possible in order to eliminate any possibility of misusing some vulnerabilities of the older versions. 

Before hitting the road and delving into the process of Magento 2 upgrade, you need to check whether the following necessary set-ups are done properly:

  • Magento file system owner (regulates who can perform actions)
  • Cron jobs. Type the next command line crontab -u <magento file system owner> -1 where <magento file system owner> is your user name. If all three necessary cron jobs run properly, you’ll see: 

* * * * * /usr/bin/php /var/www/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log

* * * * * /usr/bin/php /var/www/magento2/update/cron.php >> /var/www/magento2/var/log/update.cron.log

* * * * * /usr/bin/php /var/www/magento2/bin/magento setup:cron:run >> /var/www/magento2/var/log/setup.cron.log

In case you don’t see this or in Magento Admin you see an error, read this document. 

  • Magento file system permissions (regulates what actions can be performed by the user). To check up whether the system permissions are set up correctly, try to log in to the Magento server or use the hosting provider's file manager application.

If everything works like a charm, your further step will be to choose the way of updating Magento 2 you prefer more or which is more convenient for you and follow the instructions. But don’t forget to switch the site to the maintenance mode to forbid the access to the store during the upgrading. For this purpose, log in to the Magento server and type the next command line:

php <your Magento install dir>/bin/magento maintenance:enable

Upgrade Magento 2 from the Magento Admin via Web Setup Wizard

Upgrade Magento 2 via Web Setup Wizard

Probably, it is the most straightforward way to upgrade Magento 2. Even a non-tech-savvy will manage to upgrade Magento 2 with the help of Web Setup Wizard.

  1. Log in to the Magento Admin as an administrator.
  2. In System click Tools. There you’ll see Web Setup Wizard.
  3. In Web Setup Wizard, go to the System Configuration task and check there whether you’ve typed in your authentication keys. If not, type them in and then click Save Config.
  4. Now you can go to the System Upgrade. Magento will start looking for the latest core version. At the same time, you can click Yes to upgrade components, too.
  5. Wait till the latest Magento 2 version will be found. This process may take a while.
  6. You’ll be allowed to choose among several last Magento 2 versions, but we recommend you to favor the latest one with fewer bugs, security enhancements, and new functions. Thus, choose the latest core version Magento 2.1.7 and the necessary components and click Next.
  7. The further step is to check the environment for the correct PHP version, PHP extensions, the file permissions, and compatibility. This step is called Readiness Check.
  8. If you've passed the Readiness Check, you’ll see the permission to move on and you’ll be able to click Next. Otherwise, you have to solve the issues before moving on.
  9. The next step is to back up the file system and database. You’ll be offered to back up code, media, and database. You can choose not to back up, but we strongly recommend you not to do that.
  10. If you’ve chosen to back up, click Create Backup and wait till the system checks the disk space availability and completes the backup. Then, you’ll be allowed to click Next. In case you’ve encountered a problem while backing up, check the document.
  11. And finally, the last step is System Upgrade. On this stage, you just have to click Upgrade and wait.

Upgrade Magento 2 from Terminal with a Command Line

Upgrade Magento 2 to the latest version from terminal with a command line

This way of the system upgrade requires some technical knowledge and will suit best developers. 

  1. Log in to the Magento server as a file system owner.
  2. Go to the directory where you’ve saved the Magento software. 
  3. For the time being, the latest version of Magento 2 is Magento 2.1.7. So enter the next command if you want to upgrade Magento CE    

composer require magento/product-community-edition 2.1.7 --no-update

composer update

If you want to upgrade Magento EE, then enter a bit different command

composer require magento/product-enterprise-edition 2.1.7 --no-update

composer update

4. Then you may be asked to enter the authentication keys.

5. Finally, upgrade your Magento 2 with the command:

php bin/magento setup:upgrade

After-Upgrading Tasks

It doesn’t matter, which way you’ve used for upgrading your Magento 2, but after the store has been upgraded, you’re required to perform the following tasks:

  • 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 Varnish for caching pages, you’ll have to restart it 
service varnish restart
  • Disable maintenance mode
php bin/magento maintenance:disable

Check the storefront whether everything works correctly. 

In case you’ve encountered any problem with installing, upgrading, or migrating to Magento 2 or any other issue with Magento 1 or Magento 2, Our Team of Certified Developers is ready to help out. 

Hope, our article was useful for you. Share your experience on migration to Magento 2 or its installing and upgrading. 

You may be interested in the following articles:

Worldwide Examples of Magento and Magento 2 Online Stores

10 Basic Tips On Launching Magento 2.0 Extensions

Tutorial on Using Bash Script for Magento 2 Themes Management

Comments (2):
Posted on Thursday, July 27, 2017 by :
Well written, thanks for sharing this post it helped me a lot while installing magento 2.
Posted on Monday, August 07, 2017 by :
Great Article!Well, to update Magento 2 using composer, some CLI commands have to be run in SSH terminal.
Leave a comment:
*Your comment will be published after approval by site administrator.