cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding Multi-Store Setup

SOLVED

Regarding Multi-Store Setup

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.

Spoiler

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? 

 

3 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Regarding Multi-Store Setup

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?

View solution in original post

Re: Regarding Multi-Store Setup

@sahebyuvrajsingh 

 

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/

Manish Mittal
https://www.manishmittal.com/

View solution in original post

Re: Regarding Multi-Store Setup

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

View solution in original post

4 REPLIES 4

Re: Regarding Multi-Store Setup

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?

Re: Regarding Multi-Store Setup

@sahebyuvrajsingh 

 

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/

Manish Mittal
https://www.manishmittal.com/

Re: Regarding Multi-Store Setup

Okay, thanks for the code, I will imply this instead of the one I am using right now.

Re: Regarding Multi-Store Setup

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