Import Magento EE into Magento Commerce (Cloud)
QUESTION: Do we really want to support a full overwrite?
The following instructions walk-through importing your Magento Commerce code into your current project code. When importing, you are force pushing your existing code in a Git repository over the Magento Commerce (Cloud)’s Git master
branch.
Warning: When you force push code from an existing Git branch to your Magento Commerce (Cloud) project, you overwrite the project code in master
. Any data, websites, stores, and so on will be lost.
Before you continue, make sure there is nothing in your Magento Commerce (Cloud) project you want to keep.
Required information
Before you continue, make sure you have the encryption key from your Magento Commerce system.
Create a remote Git reference
This section discusses how to create a remote Git reference from your Cloud Git repository to the repository in which your Magento Commerce installation is located.
Before you continue, make sure you know the SSH or HTTPS URL for your Magento Commerce installation Git repository.
To create a remote Git reference:
- Log in to your local Magento Commerce (Cloud) development machine as, or switch to, the Magento file system owner.
-
Make a copy of
composer.json
in a non-tracked directory so it doesn’t get overwritten.cp composer.json ../composer.json.cloud
-
Rename your Cloud Git remote from
origin
tocloud-project
to make it clear which repository is which:git remote rename origin cloud-project
-
Add a remote upstream for your existing Magento Commerce installation:
git remote add prev-project <git url>
-
Confirm what you’ve done so far.
git remote -v
Results are displayed as follows.
cloud-project ikyyrqvlgnrai@git.us.magento.cloud:ikyykimjgnrao.git (fetch) cloud-project ikyyrqvlgnrai@git.us.magento.cloud:ikyykimjgnrao.git (push) magento ikyyrqvlgnrai@git.us.magento.cloud:ikyykimjgnrao.git (fetch) magento ikyyrqvlgnrai@git.us.magento.cloud:ikyykimjgnrao.git (push) prev-project git@github.com:mygitusername/myeereponame.git (fetch) prev-project git@github.com:mygitusername/myeereponame.git (push)
-
Make sure you’re on the Cloud project
master
branch.magento-cloud environment:checkout master
-
Make sure this
master
branch is set up to import code to the Cloud project.git fetch cloud-project git branch -u cloud-project/master
Import your Magento Commerce code to your Cloud project
Before you continue, make sure you’ve completed all tasks discussed in the preceding section.
To import your Magento Commerce code to Cloud:
-
Fetch the Magento Commerce branch.
git fetch prev-project
-
Reset your Cloud
master
branch to contain the code and the commit history of your Magento Commerce branch.git reset --hard prev-project/<branch name>
-
Push code from your Magento Commerce project to your Magento Commerce (Cloud) project, overwriting the previous contents and commit history with that of your project.
git push -f cloud-project master
A successful deployment is indicated by the following messages:
Re-deploying environment 43biovskhelhy-master-l5ut8gq. Environment configuration: mymagento (type: php:7.0, size: S, disk: 2048) mysql (type: mysql:10.0, size: S, disk: 2048) redis (type: redis:3.0, size: S) solr (type: solr:4.10, size: S, disk: 1024) Environment routes: http://master-o9gv6gq-43biovskhelhy.us.magentosite.cloud/ is served by application `mymagento` https://master-o9gv6gq-43biovskhelhy.us.magentosite.cloud/ is served by application `mymagento`
Import the Magento database
Before you can use your existing Magento Commerce code in Magento Commerce (Cloud), you must import the database.
To import the Magento database in Magento Commerce (Cloud), you must know:
- The Magento Commerce (Cloud) environment’s SSH URL
- The database name, user name, and password of the Cloud database
This topic discusses how to import the Integration environment database. The database connection information is different for Staging and Production environments.
When importing data, you will need to drop and create a new database. If you have done any data you want to keep, create a backup of the database.
To drop and re-create the Cloud database:
-
SSH to the Integration environment.
magento-cloud ssh
-
Connect to the database.
mysql -h <db-host> -P <db-port> -p -u <db-user> <db-name>
-
Drop the database. At the
MariaDB [main]>
prompt, enter:drop database main;
-
Re-create the database:
create database main;
- At the
MariaDB [main]>
prompt, enterexit
. -
At the shell command prompt, enter the following command to re-create the database.
zcat var/db.sql.tgz | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | mysql -h <db-host> -P <db-port> -p -u <db-user> <db-name>
For example,
zcat var/db.sql.tgz | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | mysql -h database.internal -p -u user main
Update base URLs
Before you can access Magento from your local Cloud development system, you must change the Base URLs in the Magento database. Base URLs are stored in the core_config_data
table.
The following example shows how to change only the insecure URL but you can use the same procedure to change secure URLs as well.
To update the unsecure base URL:
-
If you haven’t already done so, SSH to the Cloud integration server.
magento-cloud ssh
-
Connect to the database.
mysql -h <db-host> -P <db-port> -p -u <db-user> <db-name>
-
Show the contents of the
core_config_data
table.SELECT * from core_config_data;
Note the
path
ofweb/unsecure/base_url
; this is the value you’ll change. -
Enter the following command to change the value of
path
to your integration server’s unsecure base URL:UPDATE core_config_data SET value='<Cloud unsecure base URL>' WHERE path='web/unsecure/base_url';
The base URL must end with a
/
character. -
Confirm the change by entering the following command:
SELECT * from core_config_data;
- If the change was successful, enter
exit
to exit the[Maria DB]
prompt. - Continue with the next section.
For your system to be fully functional, you must also set unsecure and secure URLs for the default scope as well as for all websites, stores, and store views.
Add the Magento encryption key
The Magento Commerce encryption key is required as an environment variable in env.php
for Integration, Staging, and Production environments. If you deployed Magento when first creating a project across all environments, the encryption key should have been saved to env.php
. If you have not deployed previously, you should verify and add the encryption key if needed in every environment. Without this key, the store encounters authentication and authorization errors such as payments and shipping.
You copied the key in a previous step.
To add your Magento Commerce encryption key:
-
If you haven’t done so already, SSH to the Cloud environment.
magento-cloud environment:ssh
- Open
app/etc/env.php
in a text editor. -
Replace the existing value of
key
with your Magento Commerce key.return array ( 'crypt' => array ( 'key' => '<your encryption key>', ), );
-
Save your changes to
env.php
and exit the text editor.Make sure to add this key to the
env.php
file for all environments: Integration, Staging, and Production.
Import media
To import media files into your Cloud environment:
-
If you haven’t done so already, SSH to the Cloud environment.
magento-cloud ssh -p <project ID> -e <environment ID>
-
Enter the following command to clear existing media files:
rm -rf pub/media/*
-
Enter the following command to extract the media files to the
pub/media
directory:tar -xzf var/media.tgz pub/media
Clear the cache
On the Cloud environment, enter the following commands in the order shown:
bin/magento setup:upgrade
bin/magento magento setup:static-content:deploy
bin/magento cache:clean
After the cache flushes, enter exit
to close the SSH tunnel.
Verify the import
To verify everything imported properly, perform the following tasks in your local Cloud development environment:
-
On your Cloud environment, enter the following commands to find the information to log in to the Magento Admin and to view the storefront:
magento-cloud environment:url
- Log in to the Magento Admin using the user name and password of your Magento Commerce system.
- Make sure settings in the Admin are the same as your Magento Commerce system.
- Access the storefront.
- Make sure categories, products, and so on display as you expect.
- Test everything thoroughly.