Set up multiple websites or stores
This topic discusses how to set up Magento Commerce to have multiple websites or stores. For example, you might have an English store, a French store, and a German store. For more information on websites, stores, and store views, see Understanding websites, stores, and store views.
To set up multiple stores, you must:
- Configure your local installation and test it locally.
- Configure Magento Commerce (Cloud) routes and variables.
- Push the changes to an Integration environment and test it.
Configure your local installation
To configure your local installation to use multiple stores, see Multiple websites or stores.
Configure your Integration environment
After successfully creating and testing multiple stores locally, you must:
- Configure routes, which specify how incoming URLs are handled by Magento Commerce.
- Set up websites, stores, and store views in your Magento Commerce server’s Admin.
- Modify
magento-vars.php
to specify the values of theMAGE_RUN_TYPE
andMAGE_RUN_CODE
variables. - Deploy to your Integration branch and test.
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.
To configure routes in an integration environment:
- Log in to your local environment as, or switch to, the Magento file system owner.
- Change to your Magento Commerce base directory.
- Open
.magento/routes.yaml
in a text editor. -
Replace its contents with the following:
"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
routes.yaml
and exit the text editor.
Set up websites, stores, and store views
Set up in your Magento Commerce Admin websites, stores, and store views identical to the ones you set up on your local system.
Get your access information
To get the access information you need to log in to the Magento Admin:
- If you haven’t done so already, log in to your local environment as, or switch to, the Magento file system owner.
- Change to your Magento Commerce base directory.
-
Log in to your account:
magento-cloud login
-
List the environments:
magento-cloud environment:list
-
Check out your environment:
magento-cloud environment:checkout <environment ID>
-
View the environment’s access URLs:
magento-cloud environment:url
-
View Admin login information:
magento-cloud variable:list
Admin access information displays similar to the following:
+----------------+---------------+-----------+------+ | ID | Value | Inherited | JSON | +----------------+---------------+-----------+------+ | ADMIN_PASSWORD | admin_A456 | Yes | No | | ADMIN_URL | magento_A8v10 | Yes | No | | ADMIN_USERNAME | meister_x2U8 | Yes | No | +----------------+---------------+-----------+------+
Configure websites, stores, and store views
Make sure you name your websites, stores, and store views in your Cloud Admin the same as you did when you set up your local installation.
See Set up multiple websites, stores, and store views in the Admin.
Modify magento-vars.php
Instead of configuring an nginx virtual host, pass the MAGE_RUN_CODE
and MAGE_RUN_TYPE
variables using magento-vars.php
which is located in your Magento root directory.
- Open
magento-vars.php
in a text editor. - Uncomment everything after the first two lines.
-
Move the entire block starting with
if (isHttpHost("example.com")
afterfunction isHttpHost($host)
.Following is what the file should look like so far:
<?php // 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:
return strpos(str_replace('---', '.', $_SERVER['HTTP_HOST']), $host) === 0;
To:
return $_SERVER['HTTP_HOST'] === $host;
-
Replace the following values in the
if (isHttpHost("example.com"))
block:"example.com"
with the base URL of your website, replacing the first period with three dashes."default"
with the unique code for your website or store view."store"
with eitherwebsite
(to load the website in the storefront) orstore
(to load a storeview in the storefront).
An example follows:
<?php // 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
magento-vars.php
and exit the text editor.
Deploy and test on the Integration server
The final step is to push your changes to your Magento Entperise Cloud Edition server and test your site there. To deploy and test:
-
Enter the following commands in the order shown:
git add -A && git commit -m "Implement multiple sites" git push origin <branch name>
- Wait for deployment to complete.
-
When deployment is done, in a web browser, go to your site’s base URL.
The URL must be in the format:
http://<magento run_code>---<rest of URL>
For example,
http://french---master-benrmky-dyrozemqbw72k.us.magentosite.cloud/
- Make sure you test your site thoroughly.
When complete, merge the code to the master
Git 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 Staging prior to pushing to Production. If you need to make changes, you should complete those in Integration and beging the process to deploy across environments again.