Categories: How ToMagento 2

How to Setup Multi Store in Magento 2 (Updated)

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.

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

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.

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.

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.

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.

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.

Now click on “Add Root Category”.

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

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

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!

Click to rate this post!
[Total: 19 Average: 4.3]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

View Comments

  • 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 ...

  • Hi Thank you for sharing a great post. I have successfully create multi store but second store into cart and checkout page is not working. why?

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

  • 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.

    • 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

  • 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);

  • 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

  • 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

    • Yes, you just need to upload index.php/.htaccess on second domain. and they both should be on same hosting as you said.

Recent Posts

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

1 day ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

1 day ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

2 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

3 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

5 days ago

How Upcoming Cookie Changes Will Affect Your E-commerce Website?

The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…

5 days ago