Knowledgebase

How to configure a multistore in Magento

You can configure a single Magento installation to be used for more than one shop. The process can be roughly divided into two steps. One involves the settings that you have to configure from the admin panel of Magento. The second one is connected with some custom modifications which are slightly different depending on whether you want to use subdirectories, subdomains or different domains for your shops within the multistore.

Here are the things that you have to do from the admin panel of your Magento installation:

  • You have to create a website, a store, and a store view(s) for each shop that you want to include in the multistore. Log in to the admin panel and go to System menu>Manage Stores. In the top right corner of the page that opens you'll see the buttons Create Website, Create Store, Create Store View. First click on the Create Website button and on the following page configure the settings (a name and code for the website); you'll need the code later during the setup so remember it (you can check it at any time from the settings of the website). Then click on the Create Store button and configure the settings; make sure that from the Website drop-down menu you select the website that you just created. From the Root Category drop-down menu you can select the root category for the store; if you want the store to have its own catalog, you have to create a new root category from Catalog menu>Manage Categories, and then select it while creating the store. After you create the store click on the Create Store View button and configure the settings; make sure that from the Store drop-down menu you select the store that you just created.
  • After that go to System>Configuration. Select the new website from the Current Configuration Scope drop-down menu in the upper left corner. Then click on the Web button in the General section on the left and select the Unsecure panel from the panels that appear on the right. Unmark the Use Default checkbox next to Base URL and type the full URL address of the new shop including a trailing forward slash at the end (e.g. http://domain2.com/, http://store2.domain.com/, or http://domain.com/store2/). In case you'll use subdirectories or subdomains for the new shops in your multistore you'll also need to edit the URL addresses for Base Skin URL, Base Media URL and Base JavaScript URL. Change them to point to the respective folders in the Magento installation (e.g. http://domain.com/skin/ instead of http://store2.domain.com/skin/). Then expand the Secure panel that's under the Unsecure one and edit the settings in the same way but change the http part of the URL to https.

The things that you have to do in the second part of the multistore configuration process depend on whether you want to use subdirectories (e.g. domain.com/store1, domain.com/store2, etc.), subdomains (e.g. store1.domain.com, store2.domain.com, etc.), or different domains (e.g. domain1.com, domain2.com, etc.).

The setup process for subdirectories and subdomains is almost the same:

  • Create a subdirectory/subdomain for each shop that you want to add.
  • Copy the index.php and the .htaccess file from the Magento installation (e.g. /home/username/public_html) into the folder of the subdirectory (e.g. /home/username/public_html/store2) or that of the subdomain (e.g. /home/username/subdomains/store2).
  • You need to edit the copied index.php (not the original file in the installation). Find the following line:

$mageFilename = MAGENTO_ROOT . '/app/Mage.php';

and edit it with the full path to the Mage.php file in the Magento installation. For example, if your Magento is installed directly in the public_html directory on your Magento hosting account the line has to be changed into this (replace username with the real username of your account):

$mageFilename = '/home/username/public_html/app/Mage.php';

Then at the end of the file find the lines:

$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

At the end of the line for the code put between the quotation marks the code of the website that you created for the shop. You can check the code in the admin panel in System>Manage Stores. At the end of the line for type replace store with website.

This is what you have to do if you want to use different domains for each shop:

  • From the domain name registrar of the domain that you want to add in the multistore make sure that the name servers are the same as those for the domain that's hosted and that resolves to the Magento installation.
  • Go to the Domain Names and DNS Settings section of the Pixie control panel and add the domain name. This has the same function as parking a domain in cPanel.
  • Edit the index.php file of the Magento installation. Find the last line:

Mage::run($mageRunCode, $mageRunType);

Just above it place the following:

switch($_SERVER['HTTP_HOST']) {
	case 'domain2.com':
	case 'www.domain2.com':
	$mageRunCode = 'domain2_website_code';
	$mageRunType = 'website';
	break;
}

In the place of domain2.com and www.domain2.com put the domain name of the new shop, and replace domain2_website_code with the code of the website that you created for the shop from admin panel>System>Manage Stores.

For a more in-depth description you can also read the tutorial on Magento multistore.

Was this answer helpful?

 Print this Article

Also Read