Magento 2

Multi-Website Setup in Magento 2

We all must have stepped in the position to setup a multi-site in Magento 2. Since Magento 2 supports Multi Site hosting in one application its easier for the owner as well cheaper to make all the sites up since you dont need separate hosting to host each website.

Lets get to the point of setting up another website in your base magento website. Just go to Stores->All Stores. Then create a new website say domian 2 with the website code du. Then create the store linked to the website and the category as root Catalog if you need a new Categories then create one and link that to the new store which is linked with the domain 2 website whose website code is du. Then create store view link it with the store that you just created. Now since the 1st part of the website creation is done. Next part comes the url part.

Go to Stores->Configuration and then select domain 2 from the dropdown which is for store view on the top left side of the screen under the configuration heading. Then click on web which is under General tab. Update the Base Url and Base Link Url with your new domain 2 address. Like http://www. domain2.com/ same for Base Url(secure). Make sure you end the url with ‘/’.

With the url part done its time to set up the right settings in the directory. Create a folder in the root directory with the website code du and make sure that when you enter the url domain2.com it is pointed to the du folder of your domain1.com site. Once you confirm that the url is pointing to the right folder then we can got to the next step.
Now copy the index.php and .htaccess from domain1.com to the folder du for domain2.com. Now open index.php file and edit with the following.

From
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
$bootstrap->run($app);

To

$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = ‘du’;// code of website
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = ‘website’;
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
$app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
$bootstrap->run($app);

and also

require __DIR__ . ‘/../app/bootstrap.php’; from require __DIR__ . ‘/app/bootstrap.php’;

Once that is up now is the time to create symbolic links.

Log in using ssh to the domain1.com site. Navigate to du folder.
And run this code
ln -s /var/www/domain1/pub/ pub

ln -s /var/www/domain1/app/ app

ln -s /var/www/domain1/lib/ lib

After this just redeploy clear cache and you are good to go.
Even after this if your domain2,com site is loading with css error then go to du folder using ssh and run this code

ln -s /var/www/domain1/pub /var/www/domain1/du/pub

After this redeploy clear cache and you are good to go with your second website.
And that’s how you setup your Multi-Website in Magento 2

 415 total views

Leave a Reply

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