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:How to configure store on the server to load the new storefront (http://store2.mywebsite.com)
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);
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
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.