How to Create & Configure Multi Store in Magento 2

by Fayyaz Khattak  January 18, 2016

Magento is an incredibly powerful Ecommerce software that is the most preferred among ecommerce store owners. Recently, Magento 2 was launched with new features. One of the features in Magento 2 for developers and merchants is the multistore function.

Magento 2 Multistore

We can setup Magento 2 multiple stores like we did in Magento 1, however, as we know Magento 2 is totally different with Magento 1 and is a bit difficult to get along for those peoples who recently started development in Magento 2 because of the change in the file system.

In this article, I am going to show you how to configure multiple stores in Magento 2.

Cloudways Magento Hosting For Developers

Create Second Store:  

For creating Magento 2 second store, go to your Magento 2 admin dashboard and then go Stores/ Settings / All Stores

magento 2 admin panel

  • Under  “All Stores”  you can see three options “Create Website”, “Create Store View”, “Create Store”. First click on Create Website Button.

                  Create Store magento 2
  • In the name field, enter your second store name
  • In code field, enter your second store code name (Be sure to remember your second store code)second store magento 2
  • Now click on Create Store for your second store website and those you created before. Click on “Create Store” option.Create Store magento 2
  • In “Web Site” option select your Magento 2 website
  • In “Name” field enter your Magento 2 store view name
  • In “Root Category” select “Default Category” and click on the “Save Store” button.multi store magento 2
  • After creating store now create store view for your Magento 2 second store. Click on “Create Store View”Create Store View magento 2
  • In “Store” field select your Magento 2 store
  • In “Name” field enter your Store View Name
  • In “Code” field enter code those you enter in “Create Website”Create Store View Magento 2
  • After this, click on “Save Store View” button. And now we connect our second store domain with new store that we have just created. Go to Stores > Settings > Configurationmultistore magento 2
  • Under “Configuration” select your second store in “Store View” option, the one you see on topmagento store configuration

Your store is now set-up successfully at the back-end of Magento 2. Now set values for MAGE_RUN_TYPE and MAGE_RUN_CODE by using the following code in your index.php entry point:

Save your index.php file. After this set values in .htaccess file. This section discusses to set values for MAGE_RUN_TYPE and MAGE_RUN_CODE for using Apache Server Variables SetEnvIf or RewriteCond.

For setting up SetEnvIf, add following code in your .htaccess file after “RewriteEngine on” this:

SetEnvIf Host .**
SetEnvIf Host .** MAGE_RUN_TYPE=website

For setting up RewriteCond, add following code in your .htaccess file after “RewriteBase /magento/” This:

Save your .htaccess file.

Your Magento 2 Multiple Store is now ready for deployment! You worked so hard to put it to work, why not host it on the most optimal performance oriented ecommerce hosting platform to ensure that your cart abandonment is stays below the danger line. Come home to the best managed cloud hosting platform for Magento, Cloudways.

Start Creating Web Apps on Managed Cloud Servers Now!

Easy Web App Deployment for Agencies, Developers and E-Commerce Industry

About Fayyaz Khattak

Fayyaz is a Magento Community Manager at Cloudways – A Managed Magento Hosting Platform. His objective is to learn & share about PHP & Magento Development in Community. Fayyaz is a food lover and enjoys driving. You can email him at

Stay Connected:

You Might Also Like...

  • Amit Kumar Thakur

    Thanks Wajid for the nice explanation. I’ve been configuring it on my local system though I wasn’t able to make it work. Can you have a look into it ?

  • Arvind Bhardwaj

    Few doubts?
    1. You have not added the default store domain in index.php? Is it not required?

    2. How to do in on nginx?


  • ryan

    Question when editing this portion:

    $params[MagentoStoreModelStoreManager::PARAM_RUN_CODE] = ‘’;

    I understand for “yourcode” you are supposed to use the Code field from the store information. I am unclear if the “” refers to the Root Main Website URL or the new URL intended for use?

    In 1.9x I’m familiar with the .htaccess portion which I enter the new domain URL under the “” portion. I guess I’m a little lost with the ‘’

    • Kevin Moody

      This is the same question I am having. I can’t find a clear answer anywhere. I’m trying to get 2 sites running on the same Magento install, which is much easier than this on 1.9.

    • Kevin Moody

      Ok, What worked for me was the following.
      1. Don’t add the index.php code. No matter which site I put here, it forced it to go to that site only. Both URLs would only go to the URL specified.
      2. Set your sites in htaccess as follows

      SetEnvIf Host .*site1.* MAGE_RUN_CODE=site1_com
      SetEnvIf Host .*site1.* MAGE_RUN_TYPE=website

      SetEnvIf Host .*site2.* MAGE_RUN_CODE=site2_com
      SetEnvIf Host .*site2.* MAGE_RUN_TYPE=website

      Just setting those 2 in the htaccess seems to make Magento2 play nice… at least for me and my setup (CentOS 7, PHP 7.0.10).

      I hope this helps!

    • Scientic

      So did you resolve it ?
      I am also setting up multiple stores. Retail and wholesale, both in 3 languages. 6 fronts in total. The ‘’ is confusing and I think incorrect. Results are better using just the code you put in the store field in the admin without the I am also having better results when I change both the index and .htaccess. The point where I am looking at is that all fronts seem to work but after a few clicks magento ends up going ‘back’ to the wholesale front and won’t change back to the retail front. I have changed secure and unsecure url’s. Magento version 2.1.1

      in index.php I commented out the original statement from $bootstrap… and copied in the example and added the following where ‘wholesale’ is the code I added in Magento
      $params[MagentoStoreModelStoreManager::PARAM_RUN_CODE] = ‘wholesale’;
      $params[MagentoStoreModelStoreManager::PARAM_RUN_TYPE] = ‘website’;

      and in .htaccess below Rewrite Engine on:

      SetEnvIf Host .** MAGE_RUN_CODE=base
      SetEnvIf Host .** MAGE_RUN_TYPE=website

      SetEnvIf Host .** MAGE_RUN_CODE=wholesale
      SetEnvIf Host .** MAGE_RUN_TYPE=website

      where of course mydomain is substituted
      Conclusion is that it runs but unstable, close but not exactly right
      what to do ?