I was setting up a multi store website locally on xampp. Successfully created a virtual host and the website as well in the stores option. The website is opening successfully, both of them, but I am getting a code on the top of my default website. I placed the code mentioned below, in the "index.php" which is present in the root directory of magento.
switch($_SERVER['HTTP_HOST']) { case 'test1.com': $mageRunCode = 'base'; $mageRunType = 'website'; break; case 'imc.test1.com': $mageRunCode = 'second'; $mageRunType = 'website'; break; } $params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = $mageRunCode; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = $mageRunType; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
I'm getting this error on the top of the default website.
Notice: Undefined variable: mageRunCode in C:\xampp\htdocs\magento-community-edition\index.php on line 49
Notice: Undefined variable: mageRunType in C:\xampp\htdocs\magento-community-edition\index.php on line 50
Here is the screen shot for your reference of the same,
Default Website: http://prnt.sc/tefvbx
Second Website: https://prnt.sc/tefvvc
If this method is wrong what else can be done to make the second store option work after initializing the virtual host and creating the website, store and store view?
Solved! Go to Solution.
As I made some changes in the current script the said error no longer exists. Here is what I did.
switch($_SERVER['HTTP_HOST']) { default: $mageRunCode = 'base'; $mageRunType = 'website'; break; case 'imc.test1.com': $mageRunCode = 'imc_website'; $mageRunType = 'website'; break; } $params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = $mageRunCode; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = $mageRunType; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
Just want to know is this the right way of doing it? Or there are other ways as well, to set up a multi-store website?
Follow below code for index.php
<?php $params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'yourcode.yourdomain.com'; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website'; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params); $app = $bootstrap->createApplication('Magento\Framework\App\Http'); $bootstrap->run($app);
Or you can follow below shared links for info and steps:
https://meetanshi.com/blog/setup-magento-2-multi-store/
https://www.cloudways.com/blog/create-and-configure-multistore-magento-2/
Its not working, throwing some error
There has been an error processing your request
Exception printing is disabled by default for security reasons.
Error log record number: f1ed025467d8bf9977c48013fd52407cb71140c70d1951e57c5c947f1afc03db
As I made some changes in the current script the said error no longer exists. Here is what I did.
switch($_SERVER['HTTP_HOST']) { default: $mageRunCode = 'base'; $mageRunType = 'website'; break; case 'imc.test1.com': $mageRunCode = 'imc_website'; $mageRunType = 'website'; break; } $params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = $mageRunCode; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = $mageRunType; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
Just want to know is this the right way of doing it? Or there are other ways as well, to set up a multi-store website?
Follow below code for index.php
<?php $params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'yourcode.yourdomain.com'; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website'; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params); $app = $bootstrap->createApplication('Magento\Framework\App\Http'); $bootstrap->run($app);
Or you can follow below shared links for info and steps:
https://meetanshi.com/blog/setup-magento-2-multi-store/
https://www.cloudways.com/blog/create-and-configure-multistore-magento-2/
Okay, thanks for the code, I will imply this instead of the one I am using right now.