cancel
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

Situation

We have a Magento installation that conatins multiple websites, each with its own URL. For example shop1.domain.com for website 1 and shop2.other.com 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.
Solution
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
Help?

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

4 Comments
denizesen80
Regular Visitor

my index.php looks like this:

 

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

...

HTML;
exit(1);
}

$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);
$bootstrap->run($app);

denizesen80
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?

denizesen80
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

denizesen80
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