How to Configure Magento 2 Multistore

How to configure Magento 2 multistore

Magento is well-known for its flexibility, high-quality performance, and ability to support businesses of all sizes. It’s packed with functionality that budding entrepreneurs require to efficiently build and scale their operations and boost their reach globally.

Perhaps one of its most powerful features is the ability to support multiple websites using a single installation. This feature allows businesses operating across various regions and industries to manage all their ecommerce operations from a single channel. It also brings down the costs of custom Magento development because you only have one application that needs to be configured and integrated with your ERP system.

In this article, we’ll go over how to configure Magento 2 multistore so that you can boost your business without complicating your operations.

What is Magento 2 multistore?

Magento 2 multistore is a setup that can be configured using the Global, Website, Store, and Store-view hierarchy system in Magento to create and run multiple websites from a single installation.

Each website can be configured to have an independent default language, domain name, set of categories, products, and currency — all using a single codebase that can be managed from one Magento admin panel.

How to configure Magento 2 multistore

Magento’s developers have simplified the process of setting up a multistore operation to the point that most store owners can do it themselves.

However, setting it up properly is essential to ensuring your new store doesn’t affect the performance or configuration of your existing website.

Let’s look at how you can configure your Magento 2 multistore in a few easy steps.

Step 1: (Optional) Create root categories

To start configuring your Magento 2 store for multistore use, you need to log in to your Magento admin panel as an administrator and create a unique root category for each website.

Although this is an optional step, it will help you categorize products across multiple websites more efficiently.

  1. Head over to Catalog > Categories and select ‘Add Root Category’.
  2. Enter a unique name in the ‘Category Name’ field to identify your new root category.
  3. Set ‘Enable Category’ to Yes and click Save.

Create root categories

You can repeat this process each time you wish to add a new category before setting up a new website.

Step 2: Create websites

A fresh Magento 2 installation operates with a single default website called ‘Main Website’. Each new website you create can have exclusive configurations like shipping, taxes, and payment gateways.

  1. Head over to Stores > Settings > All Stores and click on ‘Create Website’.
  2. Enter a name to identify your website, a unique code for your website, and a sort order number.
  3. Once completed, click on ‘Save Web Site’.

Create websites

You may repeat this as often as required to add multiple websites.

Step 3: Create stores

Now, it’s time to create a store under the newly created website. A single website can have multiple stores assigned to it, so you can repeat this process multiple times if you need to add additional stores to a website.

  1. Navigate to Stores > Settings > All Stores and click on ‘Create Store’.
  2. From the dropdown, select the website you wish to associate the store with.
  3. Next, enter a name and unique code to identify the store.
  4. Then select a root category from the dropdown and click ‘Save’ once completed.

Create stores

Step 4: Create store views

By default, each store has a single store view. You can create additional store views if you wish to offer multilanguage support on your store.

  1. Head over to Stores > Settings > All Stores and click on ‘Create Store View’.
  2. Select the name of the store you wish to create a store view for and enter a name and unique code to identify the store view.
  3. Next, set the ‘Status’ to ‘Enabled’ and click ‘Save’.

Create store views

Step 5: Set the new website’s base URL

  1. First, go to Stores > Settings > Configuration > General > Web.
  2. On the top left-hand side of the page, select your website’s name from the dropdown next to ‘Store View’.
  3. Next, expand ‘Base URLs’ and enter the URL or subdomain you would like to set for your new website.

Set Base URLs

Repeat this step in the ‘Base URLs (Secure)’ section and click on ‘Save Config’.

Step 6: Add the store code to the newly configured base URL

To avoid the hassle of creating new directories on your server for the .htaccess and index.php files for your new websites, Magento allows you to add your store code to the site’s base URL from inside the admin panel.

To add the store code to your site’s base URLs, follow these steps:

  1. Go to Stores > Settings > Configuration > General > Web, and set the ‘Store View’ option on the top left-hand side of the window to ‘Default Config’.
  2. Next, expand ‘URL options’ and set ‘Add Store Code to URLs’ to ‘Yes’.
  3. After this, click ‘Save Config’ and then flush Magento cache from System > Cache Management.

Add store code to URLs

Step 7: Change the default store view base URL

This is the last step to be carried out inside the Magento admin because you will lose access to the admin panel after this. It will only be restored once you reconfigure your web server application.

  1. First, go to Stores > Settings > Configuration > General > Web and set the ‘Store View’ on the top left to ‘Default Config’.
  2. Next, expand the ‘Base URLs’ section and update Base URL, Base Link URL fields to your website’s top-level domain URL.
  3. Expand the ‘Base URLs (Secure)’ section and repeat the previous step.
  4. Finally, click on ‘Save Config’.

Change default config

You will lose access to your Magento admin after this; however, we’ll restore it by reconfiguring our web servers in the next step.

Step 8: Configure your web server to work with your multistore setup

The processes to configure Magento 2 multistore to work with Apache and Nginx are different. Let’s go over the steps to configure each to work with Magento.

Nginx configuration:

Although you can use multiple virtual host files with Nginx, using a single file will help you keep things simple and easy to manage. Log in to your server as a user with superuser privileges and follow these steps:

  1. Using your preferred text editor, create a new file as /etc/nginx/sites-available/magento and add the following contents to it.

<code>

map $http_host $MAGE_RUN_CODE {

default ”;

german.yoursite.com german;

}

server {

listen 80;

server_name yoursite.com german.yoursite.com;

set $MAGE_ROOT /var/www/html/magento2;

set $MAGE_MODE developer;

set $MAGE_RUN_TYPE website; #or set $MAGE_RUN_TYPE store;

include /var/www/html/magento2/nginx.conf;

}

</code>

  1. Save the file and exit the text editor.
  2. Next, test your Nginx configuration by running the following command in the terminal:

<code>

# sudo nginx -t

</code>

In case of errors, check the syntax of your configuration files. If it returns successful, move on to the next step.

  1. Create a symbolic link to the previously created file in the /etc/nginx/sites-enabled directory. To do this, copy and run the following command in your terminal.

<code>

# sudo ln -s /etc/nginx/sites-available/magento /etc/nginx/sites-enabled/magento

</code>

  1. Next, we need to modify the conf.sample file inside your Magento installation directory. To do this, create a copy of the nginx.conf.sample file and then add the following two lines under the ‘# PHP entry point for main application’ section before the ‘include fastcgi_params;’ line.

<code>

fastcgi_param MAGE_RUN_TYPE $MAGE_RUN_TYPE;

fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;

</code>

  1. Finally, make sure to reload nginx, so that all your changes are updated.

Apache configuration:

If you’re using an Apache web server, you can use the following instructions to set up your virtual host.

  1. Using a text editor of your choice, open the /etc/httpd/conf/httpd.conf file on your server.
  2. Locate the <VirtualHost *:80> section and create new virtual hosts after any existing ones as follows.

Here’s a sample of what your file might look like after you’ve added in the additional data:

<code>

<VirtualHost *:80>

ServerName          yoursite.com

DocumentRoot        /var/www/html/magento2/pub/

</VirtualHost>

<VirtualHost *:80>

ServerName          german.yoursite.com

DocumentRoot        /var/www/html/magento2/pub/

SetEnv MAGE_RUN_CODE “german”

SetEnv MAGE_RUN_TYPE “website”

</VirtualHost>

</code>

  1. Finally, save your changes, exit the text editor, and restart Apache to update your changes.

Step 9: Point your subdomains to your server

If you have DNS set up for your store, point your newly configured subdomains to your server’s IP address.

If you haven’t set it up, add a static route to the hosts file on your server in the following format:

<code>

<ip address> german.yoursite.com

</code>

And just like that, you will have regained access to your admin panel, and your newly configured Magento 2 multistore will be live.

Bonus tip

Setting up your Magento 2 multistore using Docker containers can be extremely beneficial to your website’s performance. If you find it tricky to DIY, it might be wise to seek help from a Magento development agency instead.

Wrapping it up

Magento 2 multistore is extremely easy to configure as long as you follow the steps outlined in this article.

Using one admin panel to rule them all, you can set up multiple stores for your business and even customize how your catalog is set up for each website and store.

Properly configuring your multistore setup will help you minimize unwanted downtime and reap the rewards of using Magento 2 as your ecommerce platform.

Leave a Comment

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