Set up multiple websites or stores
You can configure Magento Commerce to have multiple websites or stores, such as an English store, a French store, and a German store. See Understanding websites, stores, and store views. The process to set up multiple stores is as follows:
- Configure and test your local installation.
- Configure Magento Commerce Cloud routes and variables.
- Push the changes to an Integration environment and test.
Configure your local installation
To configure your local installation to use multiple stores, see Multiple websites or stores.
After successfully creating and testing the local installation to use multiple stores, you must prepare your Integration environment:
- Configure routes—specify how incoming URLs are handled by Magento Commerce
- Set up websites, stores, and store views—configure using the Magento Commerce Admin panel
- Modify
magento-vars.php
file—specify the values of theMAGE_RUN_TYPE
andMAGE_RUN_CODE
variables - Deploy—deploy and test the
integration
branch
Configure routes
Magento Enterprise Edition routes define how incoming URLs are processed. The way you configure routes depends on how you want your site to operate. We suggest configuring routes for integration as follows. You can edit the values later if your needs change.
For Pro, you must create a Support ticket to set up routes in the Staging or Production environment.
To configure routes in an integration environment:
-
On your local workstation, log in as the Magento file system owner.
-
Change to your Magento Commerce base directory.
-
Open the
.magento/routes.yaml
file in a text editor. -
Replace the contents with the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
"http://{default}/": type: upstream upstream: "mymagento:php" "https://{default}/": type: upstream upstream: "mymagento:php" "http://*.{default}/": type: upstream upstream: "mymagento:php" "https://*.{default}/": type: upstream upstream: "mymagento:php"
-
Save your changes to the
routes.yaml
file.
Set up websites, stores, and store views
In the Admin panel, set up your Magento Commerce websites, stores, and store views. See Set up multiple websites, stores, and store views in the Admin.
It is important to name your websites, stores, and store views in your Cloud Admin the same as you did when you set up your local installation.
Modify the magento-vars.php
file
Instead of configuring an NGINX virtual host, pass the MAGE_RUN_CODE
and MAGE_RUN_TYPE
variables using the magento-vars.php
file located in your project root directory.
To pass variables using the magento-vars.php
file:
-
Open the
magento-vars.php
file in a text editor. -
Uncomment everything after the first two lines.
-
Move the entire block starting with
if (isHttpHost("example.com")
afterfunction isHttpHost($host)
.The file should look like the following:
1 2 3 4 5 6 7 8 9 10 11 12 13
// enable, adjust and copy this code for each store you run // Store #0, default one function isHttpHost($host) { if (!isset($_SERVER['HTTP_HOST'])) { return false; } return strpos(str_replace('---', '.', $_SERVER['HTTP_HOST']), $host) === 0; } if (isHttpHost("example.com")) { $_SERVER["MAGE_RUN_CODE"] = "default"; $_SERVER["MAGE_RUN_TYPE"] = "store"; }
-
Change the following line:
From:
1
return strpos(str_replace('---', '.', $_SERVER['HTTP_HOST']), $host) === 0;
To:
1
return $_SERVER['HTTP_HOST'] === $host;
-
Replace the following values in the
if (isHttpHost("example.com"))
block:example.com
—with the base URL of your websitedefault
—with the unique code for your website or store viewstore
—with one of the following values:website
—load the website in the storefrontstore
—load a storeview in the storefront
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// enable, adjust and copy this code for each store you run // Store #0, default one function isHttpHost($host) { if (!isset($_SERVER['HTTP_HOST'])) { return false; } return $_SERVER['HTTP_HOST'] === $host; } if (isHttpHost("french.branch-sbg7pPa-f3dueAiM03tpy.us.magentosite.cloud")) { $_SERVER["MAGE_RUN_CODE"] = "french"; $_SERVER["MAGE_RUN_TYPE"] = "website"; }
-
Save your changes to the
magento-vars.php
file.
Deploy and test on the Integration server
The final step is to push your changes to your Magento Commerce Cloud server and test your site there.
-
Add, commit, and push code changes to the remote branch.
1
git add -A && git commit -m "Implement multiple sites" && git push origin <branch name>
-
Wait for deployment to complete.
-
After deployment, open your site base URL in a web browser.
Use the format:
http://<magento-run-code>.<site-URL>
For example,http://french.master-name-projectID.us.magentosite.cloud/
-
Test your site thoroughly and merge the code to the
integration
branch for further deployment.
Deploy to Staging and Production
Follow the deployment process for deploying to Staging and Production. For Starter and Pro environments, you use the Project Web Interface to push code across environments. For Pro accounts created before October 23, 2017 and not updated, you can use SSH and CLI commands.
We recommend fully testing in the Staging environment prior to pushing to the Production environment. If you need to make changes, you should complete those in the Integration environment and begin the process to deploy across environments again.