The differences between Magento 1 and Magento 2 are huge. The code has a whole new structure with a lot of improvements but there is one big disadvantage. What do I do if I want to upgrade my Magento 1 shop to a Magento 2 shop?
Magento created an upgrade tool that migrates the data from a Magento 1 database to the right structure for a Magento 2 database.
The custom modules in your Magento 1 shop will not work in Magento 2. It is possible that some of your modules will have a Magento 2 version, and depending on the module, the module author will have a migration tool to migrate the data that is in the module.
Before we get started, make sure you have an empty (without sample data) Magento 2 installation with the same version as the Migration tool that is available at:
In your Magento 2 version (with the same version as the migration tool), run the following commands:
composer config repositories.data-migration-tool git https://github.com/magento/data-migration-tool-ce composer require magento/data-migration-tool:2.0.0
Install Magento 2 with an empty database by running the installer. Make sure you configure it with the right time zone and currencies.
When these steps are done, you can test the tool by running the following command:
php bin/magento migrate:data --help
The next thing is creating the configuration files. Examples of the configuration files are in
vendor/magento/data-migration-tool/etc/<version>
. We can create a copy of this folder where we can set our custom configuration values. For a Magento 1.9 installation, we have to run the followingcp
command:cp –R vendor/magento/data-migration-tool/etc/ce-to-ce/1.9.1.0/ vendor/magento/data-migration-tool/etc/ce-to-ce/packt-migration
Open the
vendor/magento/data-migration-tool/etc/ce-to-ce/packt-migration/config.xml.dist
file and search for thesource/database
anddestination/database
tags. Change the values of these database settings to your database settings like in the following code:<source> <database host="localhost" name="magento1" user="root"/> </source> <destination> <database host="localhost" name="magento2_migration" user="root"/> </destination>
Rename that file to
config.xml
with the following command:mv vendor/magento/data-migration-tool/etc/ce-to-ce/packt-migration/config.xml.dist vendor/magento/data-migration-tool/etc/ce-to-ce/packt-migration/config.xml
By adding a composer dependency, we installed the data migration tool for Magento 2 in the codebase. This migration tool is a Magento console command that will handle the migration steps from a Magento 1 shop.
In the etc
folder of the migration module, there is a sample configuration of an empty Magento 1.9 shop.
If you want to migrate an existing Magento 1 shop, you have to customize these configuration files so it matches your preferred state.
In the next recipe, we will learn how we can use the script to start the migration.