How To Setup Multiple Magento Stores

Gone are the days when you have to setup separate E-commerce scripts to manage & run multiple online stores. Magento makes new store creation extremely easy for the store owners so that they can have as many stores as they like still maintaining one backend (admin panel). If you are new to Magento then this tutorial will require you to read the instructions very carefully. You can create multiple stores with other E-commerce software as well i.e. osCommerce, X-Cart, Zen Cart or Miva but to have multiple stores you need to add few plugins, addons and invest in hiring a full time programmer which is painful. A single Magento installation will be enough to run multiple stores having different domain names, different IP’s and different Security certificate. You can optionally setup single checkout for each store as well.

Choosing a URL structure for your individual store is your own personal choice. You can install two different stores on same domain name under different directories ie. Mystore.com/women & Mystore.com/men. You can also use single Magento installation to host two or more stores each sharing same Magento backend but pointing to different domain names as well i.e. womenstores.com & mensstore.com. Similarly you can setup more than one Magento powered stores in sub-domains i.e. women.mystore.com & men.mystore.com

Once you are done selecting a URL structure just stick to it. Typically people prefer hosting more than one Magento powered stores with one backend but each store having its own domain name (better for SEO).

In order to setup another Magento powered store you need to following the steps given below:

  1. Login to the Magento admin panel.
  2. Go to the Catalog tab, and select Manage Categories.
  3. Click on the Add Root Category button on the left.
  4. We will input mystore2.com as Name. Set the dropdown to Yes for both “Is Active” and “Is Anchor”. Click Save category button.
  5. Now, Go to the System tab and select Manage Stores.
  6. Click on the Create Website button.
  7. We will enter mystore2.com as Name and in Code field we will enter mystore2. As we are going to use this value later so keep it handy. Click Save Website button.
  8. Click on the Create Store button.
  9. For the Website, select mystore2.com from the dropdown. For theName, we’ll enter Main Store. For the Root Category, select the mystore2.com from the dropdown. Click Save Store button.
  10. Click on the Create Store View button.
  11. For the Store, select Main Store from the dropdown, making sure it’s for themystore2.com website. For the Name, we’ll enter English. For the Code, we’ll enter mystore2_en. For the Status, select Enabled from the dropdown. Click Save Store view button.
  12. Now, Go to the System tab and select Configuration.
  13. For the Current Configuration Scope (located on the top left), change the dropdown menu from Default Config to mystore2.com.
  14. Select Web from the sidebar on the left under the General heading.
  15. For both the Unsecure and Secure sections, uncheck the Use default box next to the Base URL item, and enter the URL for your store, e.g.http://www.mystore2.com/. Don’t ignore the trailing slash. Click Save Config button. You are all set, your new store is created.

Now, as you have created another store using your Magento admin panel, you need to decide which method to use for Magento to locate your new store. There are four main methods to setup your domains which are entirely based upon your URL structure.

  1. Addon Domain Method (Each store have its own domain name)
  2. Parked Domain Method (New stores will be setup on Parked domain
  3. Sub-directory Method (New Store will be setup in different directory under primary domain)
  4. Sub-domain Method (Each new store will be setup in different sub domains)

 

If you have chosen to setup multiple stores each having their own domain name then this method should be used. This method requires you to have your domain administrative account ready with you to modify and add another domain. Simply, follow the steps given below:

  1. Login to cPanel for your domain, and click on the Addon Domains icon.
  2. For the New Domain Name, we’ll enter mystore2.com. cPanel will automatically fill in the next two fields, so remove public_html/ from the Document Root field, leaving us with just mystore2.com
  3. Set a password for this domain and click on the Add Domain button.
  4. Login to your site via SSH, and go to the directory that we previously set in the Document Root field above when adding our domain. In our case, we would do the following:
    1
    cd mystore2.com/
  5. Copy the index.php and .htaccess file from the directory where Magento is installed, which would be in our root web directory:
    1
    cp ../public_html/index.php ../public_html/.htaccess
  6. Open up the index.php file that we just copied over and replace the following line of code:
    1
    $mageFilename = 'app/Mage.php';

    with the following

    1
    $mageFilename = '../public_html/app/Mage.php';
  7. With the index.php file still open, replace the following line of code:
    1
    Mage::run();

    with the following:

    1
    Mage::run(mystore2, 'website');
  8. Finally, we need to create symbolic links to point to a few directories:
    1
    2
    3
    4
    5
    6
    7
    8
    ln -s ../public_html/404/ ./404
    	ln -s ../public_html/app/ ./app
    	ln -s ../public_html/includes/ ./includes
    	ln -s ../public_html/js/ ./js
    	ln -s ../public_html/media/ ./media
    	ln -s ../public_html/report/ ./report
    	ln -s ../public_html/skin/ ./skin
    	ln -s ../public_html/var/ ./var

This is the easiest method to setup multiple Magento powered stores. In this method we setup a new Magento store on a parked domain. Parked domain method requires that you have one store already setup and now you are adding one more. Follow the steps given below to setup a new Magento store on a parked domain.

  1. Login to cPanel for your domain and click on the Parked Domains icon.
  2. In the input field, enter the domain name that you’ll be setting up as a second store, e.g. mystore2.com.
  3. Click on the Add Domain button.
  4. Open up the index.php file for Magento and replace the last line of code:
    1
    Mage::run();

    with the following code

    1
    2
    3
    4
    5
    6
    7
    8
    9
    switch($_SERVER['HTTP_HOST']) {
    		case mystore2.com':
    		case 'www.mystore2.com':
    			Mage::run('mystore2', 'website');
    		break;
    		default:
    			Mage::run();
    		break;
    	}

    If you own more than one store then the above code will look like

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    switch($_SERVER['HTTP_HOST']) {
    
    		// mystore2.com
    		case mystore2.com':
    		case 'www.mystore2.com':
    			Mage::run('mystore2', 'website');
    		break;
    
    		// mystore3.com
    		case mystore3.com':
    		case 'www. mystore3.com':
    			Mage::run('mystore3', 'website');
    		break;
    
    		// Mainstore.com (default store)
    		default:
    			Mage::run();
    		break;
    	}

Suppose you want to setup multiple stores under different sub-directories on the same server then you should follow this method. In this method you will have one primary domain and you will call you additional store by calling the sub-directory in the URL. i.e.

       Mainstore.com/store1
       Maninstore.com/store2

Follow the steps given below:

  1. Login to your site via SSH, and create a subdirectory where your second store will be:
            cd public_html
    	mkdir mystore1/
    	cd mystore1/
  2. Copy the index.php and .htaccess file from the directory where Magento is installed, which would be in our root web directory:
    1
    cp ../public_html/index.php ../public_html/.htaccess
  3. Open up the index.php file that we just copied over and replace the following line of code:
    1
    $mageFilename = 'app/Mage.php';

    with the following:

    1
    $mageFilename = '../public_html/app/Mage.php';
  4. With the index.php file still open, replace the following line of code:
    1
    Mage::run();

    with the following:

    1
    Mage::run('mystore1', 'website');

If you want to setup your additional store in a sub-domain then you should follow this step. This step requires you to own a primary domain where you have Magento powered store already running. In order to setup another sub-domain and setup your additional store you need to follow the steps given below. You new store will look like mystore1.mysite.com

  1. Login to cPanel for your domain, and click on the Subdomains icon.
  2. For the Subdomain, we’ll enter mystore1. cPanel will automatically fill in the next field, so remove public_html/ from the Document Root field, leaving us with just mystore1.
  3. Click the Create button.
  4. Login to your site via SSH, and go to the directory that we previously set in the Document Root field above when creating our subdomain. In our case, we would do the following:
        cd mystore1/
  5. Copy the index.php and .htaccess file from the directory where Magento is installed, which would be in our root web directory:
    1
    cp ../public_html/index.php ../public_html/.htaccess
  6. Open up the index.php file that we just copied over and replace the following line of code:
    1
    $mageFilename = 'app/Mage.php';

    with the following:

    1
    $mageFilename = '../public_html/app/Mage.php';
  7. With the index.php file still open, replace the following line of code:
    1
    Mage::run();

    with the following:

    1
    Mage::run('mystore1', 'website');
  8. Finally, we need to create symbolic links to point to a few directories:
    1
    2
    3
    4
    5
    6
    7
    8
            ln -s ../public_html/404/ ./404
    	ln -s ../public_html/app/ ./app
    	ln -s ../public_html/includes/ ./includes
    	ln -s ../public_html/js/ ./js
    	ln -s ../public_html/media/ ./media
    	ln -s ../public_html/report/ ./report
    	ln -s ../public_html/skin/ ./skin
    	ln -s ../public_html/var/ ./var

All the above method may require you to have full server access. In case you are installing and creating additional stores in a shared hosting environment you may face the following problems:

  • All of your stores share a secure checkout point. If you run two different store i.e. store1.com and store2.com and you are using store1.com as primary domain and have an SSL certificate associated with it. The other domain would be either addon or parked domains, and visitors to those sites would be redirected to your primary domain for checkout.
  • All of your stores do not have a secure checkout, which is fine if you’re using PayPal, Google Checkout, or a similar third-party service that handles the processing of card data on their website. For example, visitors to any of your stores are redirected to a third-party website for card processing.
  • All of your stores are setup as subdomains, and you’ve purchased a wildcard SSL certificate, which is roughly $1000/year and is for legally registered businesses.

In the recent development Magento has evolved and so does index.php file which does not have Mage::run(); function anymore. In Magento 1.4x version you will see this line of code changed to something like

1
2
3
4
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

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

It is visible that now Magento looks for two environment variables to start Magento store, this leaves you with two choices:

1. .htaccess Solution
2. Virtualhost Solution

Depending upon your expertise you can choose which of these will suit your needs.

Easiest amongst these is .htaccess solution. In your .htaccess file you should define your primary and secondary store e.g. suppose the URL of your primary/base store is xyz.com and the URL of your second website is store2.com add the following lines in your .htaccess.

1
2
3
4
SetEnvIf Host .*xyz.* MAGE_RUN_CODE="base";
SetEnvIf Host .*store2.* MAGE_RUN_TYPE="store2";
//Similary, create few more 
SetEnvIf Host .*store3.* MAGE_RUN_TYPE="store3";

Simply ensure that .*xyz.*, .*store2.* are regex expression matching the domain for which you want to set environmental variables for.

If you have access to virtual hosts definition file then you can use this method which requires you to add these lines in your virtualhost definition:

1
2
3
4
SetEnv MAGE_RUN_CODE "base" #Put here your main/base store code
SetEnv MAGE_RUN_TYPE "store2" #Put 'store2' if the URL of the additional store is store2.com.
//Similarly, add additioanl store like this
SetEnv MAGE_RUN_TYPE "store3" #Put 'store3' if the URL of the additional store is store3.com.

These two methods will help you to setup multiple Magento stores without ruining the Magento core.

I would recommend that you use dedicated server to run multiple stores but its entirely your choice. If you face any problem setting up multiple Magento stores. Please leave me a comment and let me know.

Advertisements

3 thoughts on “How To Setup Multiple Magento Stores

  1. I used multiple store in our website with different domain on single magento installation.
    I have problem if user buy something on second store it’s automatically redirect to our main store
    but i need seperate checkout.
    How can do this please help me

    Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s