Home
/
Other Applications
/
How to set up Magento Multistore?

How to set up Magento Multistore?

The primary use of the Magento multistore functionality is to create multiple stores accessible on different URLs under the same Magento installation. All stores under the Magento multistore installation share the same backend, which makes the administration easier.

Once you have installed Magento, you could start building your multistore. To do that, log in the backend of your Magento installation and follow the steps below to add a new store:

  • Go to Catalog > Categories.
  • Click on Add Root Category.
  • Enter the name of your store. In this tutorial, we will use sgtest.com.
  • Click on Display Settings and enable the Anchor setting.
  • Save the category.

Once the category is saved, you could create a new store:

  • Go to Store > Settings > All Stores.
  • Under All Stores, click on Create Website.
  • For Name, we will use sgtest.com and for Code – sgtest.
  • Save the website.
  • Click on Create Store.
  • Select sgtest.com for Website and Root Category. For Name, we will use Main Store.
  • Save the store and click on Create Store View.
  • Select the newly created store ( sgtest.com ) from the drop-down menu. For the Name and Code, we will use sgtest. Select Enabled for Status and save the store view.

The last steps to complete the store creation is to configure its settings through the configuration of your Magento. Follow the steps outlined below:

  1. Go to Stores > Configuration.
  2. Select the newly created store from the Store View drop-down menu on the left side

After the store is created through the backend of Magento, you should choose how the new domain will be used. There are several possible setups and we will explain each one of them below.

Parked Domain Method:

To use that method, first, you need to add your domain as a parked domain through your Site Tools.

Once the domain is added, open the index.php file of your Magento and find the line with the following code:

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

This should be the last line in the index.php file. Right before that line, add the following block:

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

If you want to use more than one domain, you should add a new block for every domain. For example:

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

case 'mythirdstore.com':
case 'www.mythirdstore.com':
$mageRunCode = 'thirdstore';
$mageRunType = 'website';
break;
}

Save the index.php file, clear the cache of your Magento and you should be able to access the newly created store with its domain name.

Subdomain Method:

To use the Subdomain method, you need to add your subdomain through your Site Tools. This will create a separate document root directory for that subdomain. Once the domain is added, you need to establish an SSH connection to your account. Once connected, go to the directory for the corresponding subdomain. In this case, this will sub.sgtest.com.

Copy the index.php and the .htaccess files of your Magento installation to that directory:

cp ../index.php ../.htaccess .

Open the index.php file and right before the last line, add the following code:

$mageRunCode = 'sub.sgtest';
$mageRunType = 'website';

Once you add the code, save the file and close it. The last step to complete is to create eight symbolic links that will point to the core Magento directories. You could do that by executing the following commands in the document root directory of your subdomain:

ln -s ../app/ app
ln -s ../errors/ errors
ln -s ../includes/ includes
ln -s ../js/ js
ln -s ../lib/ lib
ln -s ../media/ media
ln -s ../skin/ skin
ln -s ../var/ var

Note that depending on where the document root directory of your domain is, the path in the commands may defer. Once the links are created, clear the cache of your Magento and you should be able to access the newly created store with its domain name.

Share This Article