Set up multiple websites or stores
You can configure Adobe 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 depends on whether you choose to use unique or shared domains.
Multiple stores with unique domains:
https://first.store.com/
https://second.store.com/
Multiple stores with the same domain:
https://store.com/first/
https://store.com/second/
Add Domains
Custom domains can be added to Pro Staging and any Production environment; they cannot be added to integration environments.
The process to add a domain depends on the type of Cloud account:
-
For Pro Staging and Production
Add the new domain to Fastly, see Manage domains, or open a support ticket to request assistance. In addition, you must Submit an Adobe Commerce Support ticket to request new domains to be added to a cluster.
-
For Starter Production only
Add the new domain to Fastly, see Manage domains, or Submit an Adobe Commerce Support ticket to request assistance. In addition, you must add the new domain to the Domains tab in the Cloud Console:
https://<zone>.magento.cloud/projects/<project-ID>/edit
Configure local installation
To configure your local installation to use multiple stores, see Multiple websites or stores in the Configuration Guide.
After successfully creating and testing the local installation to use multiple stores, you must prepare your integration environment:
-
Configure routes or locations—specify how incoming URLs are handled by Adobe Commerce
-
Set up websites, stores, and store views—configure using the Adobe Commerce Admin UI
-
Modify variables—specify the values of the
MAGE_RUN_TYPEandMAGE_RUN_CODEvariables in themagento-vars.phpfile -
Deploy and test environments—deploy and test the
integrationbranch
Configuration updates to Pro environments
routes.yaml file and the cron configuration in the .magento.app.yaml file. Adobe recommends updating and testing YAML configuration files in an Integration environment, then deploying changes to the Staging environment. If your changes are not applied to Staging sites after you redeploy and there are no related error messages in the log, then you MUST Submit an Adobe Commerce Support ticket that describes the attempted configuration changes. Include any updated YAML configuration files in the ticket.Configure routes for separate domains
Routes define how to process incoming URLs. Multiple stores with unique domains require you to define each domain in the routes.yaml file. The way you configure routes depends on how you want your site to operate.
To configure routes in an integration environment:
-
On your local workstation, open the
.magento/routes.yamlfile in a text editor. -
Define the domain and subdomains. The
mymagentoupstream value is the same value as the name property in the.magento.app.yamlfile.code language-yaml "http://{default}/": type: upstream upstream: "mymagento:http" "http://<second-site>.{default}/": type: upstream upstream: "mymagento:http" -
Save your changes to the
routes.yamlfile. -
Continue to Set up websites, stores, and store views.
Configure locations for shared domains
Where the routes configuration defines how the URLs are processed, the web property in the .magento.app.yaml file defines how your application is exposed to the web. Web locations allow more granularity for incoming requests. For example, if your domain is store.com, you can use /first (default site) and /second for requests to two different stores that share a domain.
To configure a new web location:
-
Create an alias for the root (
/). In this example, the alias is&appon line 3.code language-yaml web: locations: "/": &app # The public directory of the app, relative to its root. root: "pub" passthru: "/index.php" index: - index.php ... -
Create a pass-through for the website (
/website) and reference the root using the alias from the previous step.The alias allows
websiteto access values from the root location. In this example, the websitepassthruis on line 21.code language-yaml web: locations: "/": &app # The public directory of the app, relative to its root. root: "pub" passthru: "/index.php" index: - index.php ... "/media": root: "pub/media" ... "/static": root: "pub/static" allow: true scripts: false passthru: "/front-static.php" rules: ^/static/version\d+/(?<resource>.*)$: passthru: "/static/$resource" "/<website>": *app ...
To configure a location with a different directory:
-
Create an alias for the root (
/) and for the static (/static) locations.code language-yaml web: locations: "/": &root # The public directory of the app, relative to its root. root: "pub" passthru: "/index.php" index: - index.php ... "/static": &static root: "pub/static" -
Create a subdirectory for the website under the
pubdirectory:pub/<website> -
Copy the
pub/index.phpfile into thepub/<website>directory and update thebootstrappath (/../../app/bootstrap.php).code language-none try { require __DIR__ . '/../../app/bootstrap.php'; } catch (\Exception $e) { -
Create a pass-through for the
index.phpfile.code language-yaml web: locations: "/": &root # The public directory of the app, relative to its root. root: "pub" passthru: "/index.php" index: - index.php ... "/media": root: "pub/media" ... "/static": &static root: "pub/static" allow: true scripts: false passthru: "/front-static.php" rules: ^/static/version\d+/(?<resource>.*)$: passthru: "/static/$resource" "/<website>": <<: *root passthru: "<website>/index.php" "/<website>/static": *static ... -
Commit and push the changed files.
pub/<website>/index.php(If this file is in.gitignore, the push may require the force option.).magento.app.yaml
Set up websites, stores, and store views
In the Admin UI, set up your Adobe Commerce Websites, Stores, and Store Views. See Set up multiple websites, stores, and store views in the Admin in the Configuration Guide.
It is important to use the same name and Code of your websites, stores, and store views from your Admin when you set up your local installation. You need these values when you update the magento-vars.php file.
Modify variables
Instead of configuring an NGINX virtual host, pass the MAGE_RUN_CODE and MAGE_RUN_TYPE variables using the magento-vars.php file in your project root directory.
To pass variables using the magento-vars.php file:
-
Open the
magento-vars.phpfile in a text editor.The default
magento-vars.phpfile should look like the following:code language-php <?php // enable, adjust and copy this code for each store you run // Store #0, default one //if (isHttpHost("example.com")) { // $_SERVER["MAGE_RUN_CODE"] = "default"; // $_SERVER["MAGE_RUN_TYPE"] = "store"; //} function isHttpHost($host) { if (!isset($_SERVER['HTTP_HOST'])) { return false; } return $_SERVER['HTTP_HOST'] === $host; } -
Move the commented
ifblock so that it is after thefunctionblock and no longer commented.code language-php <?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("example.com")) { $_SERVER["MAGE_RUN_CODE"] = "default"; $_SERVER["MAGE_RUN_TYPE"] = "store"; } -
Replace the following values in the
if (isHttpHost("example.com"))block:-
example.com—with the base URL of your website -
default—with the unique CODE for your website or store view -
store—with one of the following values:website—load the website in the storefrontstore—load a store view in the storefront
For multiple sites using unique domains:
code language-php <?php function isHttpHost($host) { if (!isset($_SERVER['HTTP_HOST'])) { return false; } return $_SERVER['HTTP_HOST'] === $host; } if (isHttpHost("second.store.com")) { $_SERVER["MAGE_RUN_CODE"] = "<second-site>"; $_SERVER["MAGE_RUN_TYPE"] = "website"; }elseif (isHttpHost("store.com")){ $_SERVER["MAGE_RUN_CODE"] = "base"; $_SERVER["MAGE_RUN_TYPE"] = "website"; }For multiple sites with the same domain, you have to check the host and the URI:
code language-php <?php function isHttpHost($host) { if (!isset($_SERVER['HTTP_HOST'])) { return false; } return $_SERVER['HTTP_HOST'] === $host; } if (isHttpHost("store.com")) { $code = "base"; $type = "website"; $uri = explode('/', $_SERVER['REQUEST_URI']); if (isset($uri[1]) && $uri[1] == 'second') { $code = '<second-site>'; $type = 'website'; } $_SERVER["MAGE_RUN_CODE"] = $code; $_SERVER["MAGE_RUN_TYPE"] = $type; } -
-
Save your changes to the
magento-vars.phpfile.
Deploy and test on the integration server
Push your changes to your Adobe Commerce on cloud infrastructure integration environment and test your site.
-
Add, commit, and push code changes to the remote branch.
code language-bash git add -A && git commit -m "Implement multiple sites" && git push origin <branch-name> -
Wait for deployment to complete.
-
After deployment, open your Store URL in a web browser.
With a unique domain, use the format:
http://<magento-run-code>.<site-URL>For example,
http://french.master-name-projectID.us.magentosite.cloud/With a shared domain, use the format:
http://<site-URL>/<magento-run-code>For example,
http://master-name-projectID.us.magentosite.cloud/french/ -
Test your site thoroughly and merge the code to the
integrationbranch 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 Cloud Console to push code across environments.
Adobe recommends fully testing in the Staging environment before pushing to the Production environment. Make code changes in the integration environment and begin the process to deploy across environments again.