Contact
Site: US UK AU |

How to configure Magento 2 storefronts

How to configure Magento 2 storefronts

Overview
This article provides two different methods of using Magento 2 to configure multiple storefronts for a single website.

Notes

Separate directories for each store using secondary domains works for all versions of Magento.

Shared directory for all stores using pointer domains works for versions higher than 1.4.0.1.

Purpose

A Magento storefront is the customer-facing view of a Magento eCommerce website. These storefronts manage showcase products, categories, and search functionality. It is possible to configure multiple Magento storefronts for the same website. Explore the Magento website for more information.

Procedure

After completing the sections “Create a storefront” and “Configure the server to load your storefront” below, this article presents two different methods of implementing multi-store functionality at the server level.

Create a storefront 

The first step in setting up multi-store functionality is to create the new store or stores in the Magento administrator application. Follow the steps below to create a new store:

  1. Log in to the Magento Administrator Panel. If you want your stores to share the same catalog and products, skip to Step 7.

  2. In the navigation menu on the left, click Products > Categories (Figure 1).


    Figure 1. Products > Categories.

  3. Click Add Root Category (Figure 2).

Screenshot - 12_7_2015 , 12_50_16 PM.png

Figure 2. Add Root Category.

  1. In the Name field, enter your new store name.

  2. From the Is Active drop-down list, select Yes.

  3. Under Display Settings tab, from Anchor drop-down list, click Yes, and click Save Category.

  4. Navigate to Stores > All Stores (Figure 3).


    Figure 3. Stores > All Stores.

  5. Click Create Web Site (Figure 4).


    Figure 4. Create Website button.

  6. In the Name field, enter your new store name.

  7. In the Code field, enter a unique string without spaces and click Save Web Site. Retain this code so you may use it later.

Screenshot - 12_7_2015 , 1_52_58 PM.png

Figure 2. Save Web Site.

  1. Click Create Store.

  2. In the Web Site field, select the website that you just created.

  3. In the Name field, enter a name for your store.

  4. In the Root Category field, select the root category that you created above or use the default Root Category if you skipped ahead. Click Save Store.

Screenshot - 12_7_2015 , 1_54_18 PM.png

Figure 3. Save Store.

  1. Click Create Store View.

  2. In the Store field, select the store you just created. In the Name field, give your view a name such as "English."

  3. In the Code field, enter a unique string to identify the store view. Change the Status to Enabled and click Save Store View.

Screenshot - 12_7_2015 , 1_59_32 PM.png

Figure 4. Save Store View.

  1. Click Stores > Configuration.

  2. In thStore View field, select the website that you just created.

Figure 5. Store View field.

  1. Select the Web menu option, and click to expand the Base URLs and Base URLs (Secure) sections (Figure 6).


    Figure 6. Web menu option; Base URL and Base URLs (Secure) sections.

  2. In the Base URLs section, enter your store’s URL with one of the following methods:

    • To use your main store URL, select the Use Default check box.

    • To specify a store URL other than your main, locate the Base URL field, type your store URL, and include the “/” at the end of the URL.

  3. Repeat Step 21 in the Base URLs (Secure) section.

  4. Click Save Config. 

Configure the server to load the storefront

After creating the store, configure the server to load the correct store. There are several methods, but the two most popular methods follow.

Method 1: Separate directories for each store using secondary domains

  1. Verify your desired domain name points to the server.

  2. Create a secondary domain for your new store.

  3. Using either FTP or SSH, copy the .htaccess and index.php files from your Magento installation to the document root of your new domain.

  4. Open the index.php file that you just copied and edit the last lines of the file as follows: 

Attention: Change newstore to the code that you wrote down when you created the new website above.

Replace:

$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:

require __DIR__ . '/app/bootstrap.php';

$params = $_SERVER;

$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'newstore';

$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. Using SSH, create the following symbolic links in the document root of your new domain, and replace the path below with the full path to the document root of your Magento Installation:

ln -s /home/example/example.com/html/app/ app 

ln -s /home/example/example.com/html/lib/ lib 

ln -s /home/example/example.com/html/pub/ pub 

ln -s /home/example/example.com/html/var/ var 

  1. If you have successfully configured your secondary domain to work with Magento, your new domain will load in your browser, and you may begin developing your new store.

Method 2: Shared directory for all stores using pointer domains

Attention: These instructions will work only for Magento versions 1.4.0.1 and higher.

  1. Verify your desired domain name points 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 the .htaccess file in the document root of your Magento installation and enter the following just above the line RewriteEngine On:

    • Replace .*newstore.* with the domain name of your new store, keeping the dots and asterisks.

    • Confirm that MAGE_RUN_CODE matches the code you wrote down when you created the new website above. Newstore specifies the domain name of your new store, and websitecode specifies the store code created in Magento.

SetEnvIf Host .*newstore.* MAGE_RUN_CODE=newstore

SetEnvIf Host .*newstore.* MAGE_RUN_TYPE=website or store

  1. If you have successfully configured your pointer domain to work with Magento, your new domain will load in your browser, and you may begin developing your new store.

     

    For 24-hour assistance any day of the year, contact our Support Team by email or through the Client Portal.

Article Rating (11 Votes)
Rate this article
  • Icon PDFExport to PDF
  • Icon MS-WordExport to MS Word
 
Attachments Attachments
There are no attachments for this article.
Related Articles RSS Feed
How to write redirect (301) rules for Magento 2
Added on Wed, Jan 27, 2016
How to reset Magento 2 admin passwords
Added on Fri, Jun 3, 2016
How to disable maintenance mode in Magento
Added on Fri, Dec 15, 2017
How to change base URLs in Magento 2
Added on Wed, Jun 13, 2018
How to set up Magento 2 to use your SSL certificate
Added on Tue, Oct 11, 2016
How to add admins in Magento 2
Added on Mon, Dec 12, 2016
How to disable caching in Magento 2
Added on Wed, Oct 12, 2016
How to configure Magento 2 cron jobs
Added on Tue, Mar 27, 2018
How to set the return-path email in Magento 2
Added on Thu, Apr 21, 2016
How to enable CAPTCHA for user creation in Magento 2
Added on Mon, Feb 19, 2018