multistore setup in magento2
How could I make sense of below? Instead of below mumbo jumbo, I added the web sites, the stores and the store fronts, went into the virtual host configuration section of the domain, added the relevant SetEnv-parts and (after a apachectl restart) it just worked. I did change the base url and so of the new site, but nothing much more.
I feel stupid everytime I work in Magento and *nix environment. Obviosuly, I lack some basic knowledge. I acknowledge. But still, I read the different manuals / “how-tos” / stack exchange answers and do everything to understand. Even so, I’ve got trouble understanding. My conclusion is that the Magento-community by intention makes it difficult to understand (because, I’m not stupid?!).
Here is the magento-instructions for setting up multi-store.
I really tried to follow and understand. I didn’t. Surprise. Furthermore, if you google on this, there are many ideas on how to setup different folders (which I presume is what the Magento2 instructions means), but why? I don’t see the point.
in vhost.config, add the domains and for these, set some environmental variables using SetEnv. E.g. see here.
SetEnv MAGE_RUN_CODE "store2"
SetEnv MAGE_RUN_TYPE "website"
In index.php, there is a need to somehow secure that the variables that were set are taken into account. I could belive it should be taken into account without changing anything at all, actually... but it seems no to be the case?
Some of the original content of index.php:
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);
The suggested way of modifying according to Magento
$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = '<code>';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = '{store|website}';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);
Where ‘<code>’ then should be replaced by ‘store2′ and ‘{store|website}’ with ‘website’. Working like this, you would have to create a new folder and add the store code to each index.php file, and some symlinks (I don’t know the details of this, becuase it felt completely wrong). You also have to point the vhost to the new folder created. Instead, in the index.php, in the magento2 root folder, I did:
$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);