How to Setup Multi Store in Magento 2 (Updated)

How to Setup Multi Store in Magento 2 Updated 2018

Every business takes a birth as one small store and starts its journey to serve more products and offering to their customers. But over the period of time to reach a wide audience, gain potential customers, improve sales and profitability one should need to expand the business to various geographic locations. It creates a necessity to have multiple stores and need to manage all store separately. Moreover, to deal better with the local audience we need to translate the store into multiple languages and respectively need to change currency too.

Having Magento 2 as rough & tough E-commerce Platform allows us to setup multi-store environment to sever purpose betterly under the hood of single Magento admin panel.

You can leverage some benefits of creating multiple store setup like…
1. Setup different customer group for each store.
2. Set different display prices as per need.
3. Category settings can be different but you can use same root category for all store views.
4. Setup a different theme for each store.
5. Set different language, currency, payment, and shipping options and apply tax classes to each store.

Simply follow these instructions and you are done!

1. Creating New Website

First Logged in to your Magento 2 admin backend. Now navigate to Stores->All Stores.

5 Create website

To create a new store, click on “Create Website” available on the top right corner.

6 website information

Now it will require some fields like…
Name – Enter the store name
Code – Enter the code to identify store easily
Sort Order – Enter list order sequence
Set as Default – Checked to make it default store

Click “Save Web Site” after filling all the required fields.

2. Creating Store

Second step is to create the Store. From the same stores grid page click on “Create Store” button and fill the required fields.

7 create store

Now it will require some fields like…
Website – Select you Magento 2 Store
Name – Enter Store frontend name
Root Category – If you want to separate catalog and products for each store, create a new category. Otherwise, select “Default Category”.

Click “Save Store” after filling all the required fields.

3. Creating Store View

Last Step is to create the Store View. On the stores grid now click on Create Store View and fill in the required fields.

8 create store view

Now it will require some fields like…
Store – Select your Magento 2 store
Name – Enter Store front name
Code – Enter the code to identify store easily
Status – Select option of enabled
Sort Order – Enter list order sequence

Click on “Save Store View” after filling all the required fields.

Now, let’s check that store is created successfully or not? Go to stores->Configuration and open drop down menu from default config and see store is liste or not! Now select the store we have just created minutes ago from the list.

9 Select store view

4. Store base Url Setup

Now we need have to assign base URL to our newly created second store. For that go to Stores->Configuration->General tab-> Web.

10 web settings base urls

Now we can set URLs using any of these two methods.

  • For using main store URL, check Use Default box.
  • For specific store URL, go to base URL field and type URL trailed with “/” at the end.

Repeat the same steps for the Base URL (Secure) section and Save Config at last.

Once you’re done with creating a store, you need to configure the server to load it properly on the frontend. There are two popular methods for it, use any of them.

Method 1: Separate directories for each store using secondary domains

    1. Check if your desired domain name points to the server. Create a secondary domain for your new store.
    2. Either use FTP or SSH and copy the .htaccess and index.php files from your Magento to the document root of your new domain.
    3. Open copied index.php file and edit the last lines of the file as follows:
      Replace following code:
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);

/** @var \Magento\Framework\App\Http $app */
$app = bootstrap->createApplication('Magento\Framework\App\Http');

$bootstrap->run($app);

With the below code:

require __DIR__ . '/app/bootstrap.php';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = ' [WebsiteCode]';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);
  1. Create symbolic links in the document root of your new domain using SSH, and replace the path given below with the full path:
ln -s /home/[user_name]/demo.com/html/app/ app 
ln -s /home/[user_name]/demo.com/html/lib/ lib 
ln -s /home/[user_name]/demo.com/html/pub/ pub 
ln -s /home/[user_name]/demo.com/html/var/ var 

Once you have successfully configured your secondary domain to work with Magento, The new domain will load in browser and you can begin developing new store.

Method 2: Shared directory for all stores using pointer domains

    1. Verify your desired domain name is pointing to the server.
    2. Create a server alias pointer domain for your new store. The pointer domain will be pointing at the primary domain of your Magento installation.
    3. Edit .htaccess file in the document root of your Magento installation and enter the following code just above the line RewriteEngine On:
      • Replace .*newstore.* with the domain of your new created store, keep the dots and asterisks as it is.
      • Make sure that MAGE_RUN_CODE matches with the code you wrote down when you created the new website with above steps. Here, newstore specifies the domain name and websitecode specifies the store code created in Magento.
SetEnvIf Host .*[StoreCode].* MAGE_RUN_CODE=[StoreCode]
SetEnvIf Host .*[StoreCode].* MAGE_RUN_TYPE=website or store
  1. Once you have successfully configured your pointer domain to work with Magento, you’re ready to develop new store.

If you want separate catalog and products for each store

From sidebar menu, navigate to Products->Categories.

navigate-to-categories

Now click on “Add Root Category”.

add-root-category

Provide a name to category and activate it by selecting “Yes” from dropdown.

3_category-settings

Now move to “Display Settings” and set “yes” to the option “Is Anchor”.

display-settings

Becuase now you have learned to create a store, you can create one or more store according to your need of setting up different languages and currencies. Comment down below if you are facing an issue while creating store.
Feel free to ask questions regarding this code.
Happy Setting Up!

How to Setup Multi Store in Magento 2 CTA V2

Previous Article

How to Upgrade Magento

Next Article

Inserting Data in Existing Table During Magento 2 Extension Installation

Write a Comment
  1. ngimut elisee

    Hello thank you for this tutorial. I did everything to the end but it does not work. I have a problem with the last part. I do not know if I understood well.

    My subdomain english.bigstore.com points to the magento directory just as bigstore.com

    1. Make sure the store code you have set is correct.
      You need .htaccess and index.php in the sub domain folder, make sure those are there with necessary changes.

    1. Do you want separate admin for every website? The best option in that case separate Magento installation because Magento don’t provide store or website access by admin user.

        1. Willem de Bock

          re :’ [StoreCode]’ i added as such
          ‘ [mycode]’
          should it be

          ‘ mycode ‘ or ‘ [mycode]’

  2. Let me know about second domain -> There i need to upload complete magento files OR just need to add 2 file index.php/.htaccess ???

    Both domain on same hosting

  3. To all readers, you can skip method 1 and method 2, as per Magento 2 Wiki there is no need to modify any file index.php or .htaccess anymore. I spend countless hours trying to figure this out and this is the key.

    Store > Settings > Configuration > General > Web > Add Store Code to Urls: Yes

    Store > Settings > Configuration > Store View: Pick your new store and Add the new domain.

    clear cache and try your new store domain follow by the code for example.com/code

  4. One last tip, in order to use the secondary domain http://www.example2.com properly without http://www.example2.com/code [code] at the end the new website will get redirect to the primary or main website http://www.example.com, to fix this you need to edit the root index.php with the following codes on this tutorial

    require __DIR__ . ‘/app/bootstrap.php’;
    $params = $_SERVER;
    $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = ‘code goes here’;
    $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = ‘website or store’;
    $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
    /** @var \Magento\Framework\App\Http $app */
    $app = $bootstrap->createApplication(‘Magento\Framework\App\Http’);
    $bootstrap->run($app);

  5. Is there any way to install multiple themes in one magento 2? Since I have multi store and need multiple themes as well.

    Thanks in advance.

    1. Yes, you can have multiple themes for multi website set up,
      You will just need to upload the theme package and select and enable the theme per website from Content/Design/Configuration

  6. Kishor Hase

    I am using Magento Version 2.1.7 and follow all the step up to Method 1 (Exclude the Method 1 and Method 2).

  7. I am having trouble with my multistore on 2.2. Can someone give me the files contents for index.php and .htaccess which should be in the main directory and what these should be changed to in the second website directory? I followed the instructions (I thought) but my second website is resolving to the first …

Leave a Comment

Your email address will not be published. Required fields are marked *

Get Connect With Us

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨