<img alt="" src="https://secure.leadforensics.com/150446.png " style="display:none;">
Go to top icon

Multiple websites or stores in Magento 2.0

Amol Asodekar Jun 15, 2017

e-commerce Digital Commerce Magento 2.0

sonal-multipl-websites-in-magento2.png

One of the useful features of Magento 2.0 is the ability to create multiple stores/websites that share the same MBO (Magento Back Office). This allows multiple store fronts to share a common code base and backend making its administration a lot easier. Stores can share customer base, product catalogue and settings based on how you choose to configure your sites.
This tutorial will help you to go through the steps of setting up multiple stores in Magento 2.0, and how to configure a domain for each store.

How to create a store in MBO?

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:

  • Log in to the Magento Administrator Panel (MBO)
  • Navigate to Stores > All Stores

magento2-1.png

  • Click Create Web Site

magento2-2.png

  • In the Name field, enter your new store/website name.
  • In the Code field, enter a unique string without spaces and click on Save Web Site. Retain this code for later use.

magento2-3.png

  • Click Create Store button
  • In the Web Site field, select the website that created in above steps (5)
  • In the Name field, enter a name of store
  • In the Root Category field, select the root category and click Save Store button

magento2-4.png

  • For root category, MBO can create new root category/subcategory and assign here
  • Click Create Store View
  • In the Store field, select the store created in above steps. In the Name field, give your view a name such as "new store view"
  • In the Code field, enter a unique string to identify the store view. Change the Status to Enabled and click Save Store View button

magento2-5.png

  • Click Stores > Configuration
  • In the Store View field, select the website that you just created

magento2-6.png

  • Select the Web menu option, and click to expand the Base URLs and Base URLs (Secure)
  • In Base URLs enter your new store http url

magento2-7.png

  • Click Save Config button

How to configure store on the server to load the new storefront (http://store2.mywebsite.com)

    • Create new subdomain and new virtual host for (80 and 443)
    • Create new folder in /var/www/html/store2 and copy .htaccess and index.php from Magento root
    • directory to new store2 folder.
    • Open index.php from new store2 folder and edit the following lines:

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:

$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'newstoreview'; //store view code set in admin panel
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'newstore'; //website code set in admin panel
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);

  • 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 /var/www/html/store1/app/ app
ln -s /var/www/html/store1/lib/ lib
ln -s /var/www/html/store1/pub/ pub
ln -s /var/www/html/store1/var/ var

  • Then, execute following command.

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
php bin/magento index:reindex
php bin/magento cache:flush

Now you have successfully completed your new store configuration. You can now browse your new domain at www.store2.mywebsite.com

If you face any challenges while creating stores in Magento 2.0, feel free to drop a comment below.

e-Zest is a leading digital innovation partner for enterprises and technology companies that utilizes emerging technologies for creating engaging customers experiences. Being a customer-focused and technology-driven company, it always helps clients in crafting holistic business value for their software development efforts. It offers software development and consulting services for cloud computing, enterprise mobility, big data and analytics, user experience and digital commerce.