Showing results for 
Search instead for 
Did you mean: 

Correct Working of Multiple Websites on single Magento Instance

0 Kudos

Correct Working of Multiple Websites on single Magento Instance


We have a Magento installation that conatins multiple websites, each with its own URL. For example for website 1 and for website 2.
Magento supports all it needs to do so, exept one little thing, a tiny but not unimportent part is missing for this solution to work out of the box.
You have to start the correct website in the bootstrapping, mapping to your shop.
In Fakt since the first version of magento i had to code this litle last step in the index.php and create multiple copies of the index.php and create multiple settings file for my apache server.
Please create a component that scans all the websites url's and build a cached repo where $_SERVER[\Magento\Store\Model\StoreManager:Smiley TongueARAM_RUN_CODE] and $_SERVER[\Magento\Store\Model\StoreManager:Smiley TongueARAM_RUN_TYPE] gets automatically set upon the $_SERVER['HTTP_HOST'] == $url_configured_in_setting

I allready have my own implementation of it, its just a patchwork direct in the index.php file, not a own class, i think you will do it it better, therefore i can send you my code, if its any help to you, just ask Smiley Wink

Regular Visitor

my index.php looks like this:


try {
require __DIR__ . '/app/bootstrap.php';
} catch (\Exception $e) {
echo <<<HTML



$params = $_SERVER;

if ($_SERVER['HTTP_HOST'] == 'o***.ot****.ch')
$params[\Magento\Store\Model\StoreManager:Smiley TongueARAM_RUN_CODE] = 'o****';
$params[\Magento\Store\Model\StoreManager:Smiley TongueARAM_RUN_TYPE] = 'website';

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);

/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);

Regular Visitor

would it not be million times better, if this last part is also automated, i dont see a reason why this last step cant be automated?

Regular Visitor

I forgot to mention, that i'm running magento since lately in a docker environment. Its running smoothly, but it would be realy great to have everything automated based upon configuration and scripts. The only thing i couldnt aproach with scripting was at the end, this little last part to i have to hardcode the multiple websites inside the index.php file for each shop running on that instance, if there where multiple

Regular Visitor

it seems to be a complex solution, i dont think that the db is accessible before the bootrstrapper, but we need to scan the config for all urls that are available. Therefore it needs a spezial component, with integrated caching, that can achive exactly this, it must be after bootstrapping with the default settings.
The current behaviour, just start default webiste if bootstrapper has null parameter is not good enough, there must be a evaluartion of possible entry points, because in fakt there are multiple, and it is determinable witch to choose, just only load default is not good enough