Magento multi site set up

One of the many features of Magento is the ability to run multiple websites, stores and views all off of the same code base. In other words that means you can have several completely different e-commerce sites all sharing the same code base. But the question is how do you set up the multiple domains to point to each store view? In this tutorial I'm going to show you how to do just that. I am assuming that your Magento install is already set up and that you are using at least version 1.7 for this tutorial to work. Note that version is very important because the methods to this are different on older versions of Magento.

But wait I only have 1 store why would I want to do this?

If you want to test out any changes, theme modifications, code modifications, widgets or anything else that can impair the functioning of your store a development site is the best way to test our your changes first. That way if you "break" your test store the main store is still functioning.

For example I have 2 stores:

  • store.aandgwebtech.ca (Main site)
  • dev.store.aandgwebtech.ca (Develoment site)

The first thing that I did was to search for "Magento multi site set up" and found these tutorials:

  1. http://www.crucialwebhost.com/blog/how-to-setup-multiple-magento-stores/
  2. http://www.elief.com/blog/2010/08/how-to-setup-multiple-stores-with-magento/

 

They explain quite well how to go about setting up a multi site Magento but both are under the assumption that you have full access to the Linux shell. But what if you don't? Now what? Most web hosts keep shell access away for security purposes, but if you need something that can only be done at the shell level you'll need to ask your web hosts tech support department to do this for you.

  1. Read both tutorials completely
  2. BACK UP your Magento install just in case
  3. In order to set up multiple stores in Magento we will complete the following steps from both tutorials:

     

     

     

    1. Create a domain / sub domain from cPanel
    2. Request from the web host's tech support that symbolic links to your magento install be created in the new domain's directory
    3. Add 2 SetEnvIf directives to the .htaccess file
    4. Configure Magento to see the second store
  4. First thing that we do is create a new domain from cPanel and set it to it's own directory. This is critical because we need to set the 2  SetEnvIf directives in thier own .htaccess file so that magento knows what domain is being access in order to select the correct site / store / view.
  5. From within the first tutorial you will see instructions to create symbolic links. What are symbolic links? Consider them similar to short cuts in Windows in that is they are a pointer to to specific directory. Once a symbolic link has been created it's as if the directory is in 2 places at once. So the following commands listed below will create symbolic links to the Magento installation in ../public_html at the current directory in the shell.

    ln -s ../public_html/app ./app
    ln -s ../public_html/errors ./errors
    ln -s ../public_html/includes ./includes
    ln -s ../public_html/js ./js
    ln -s ../public_html/lib ./lib
    ln -s ../public_html/media ./media
    ln -s ../public_html/skin ./skin
    ln -s ../public_html/var ./var
  6. So in our case we'll send a e-mail to our web host to create the symbolic links in the public_html/devstorethisandthat directory:

     

     

     

     

    symlink('/public_html/magento/app','/app');
    symlink('/public_html/magento/errors','/errors');
    symlink('/public_html/magento/includes','/includes');
    symlink('/public_html/magento/js','/js');
    symlink('/public_html/magento/lib','/lib');

    symlink('/public_html/magento/media','/media');
    symlink('/public_html/magento/skin','/skin');
    symlink('/public_html/magento/var','/var');

     

  7. Why we're waiting, follow the steps to set up your new store in second tutorial.
  8. As in the second tutorial, copy both the index.php & .htaccess to the root directory of the new domain that you just created
  9. We don't need to edit the index.php file and since we don't have a shell account we can't use Vhosts file. But we can use .htaccess
  10. Edit the .htaccess and add the following 2 lines to the top of the file:

     

     

     

     

    SetEnvIf Host dev.store.aandgwebtech.ca MAGE_RUN_CODE=devstorethisandthat
    SetEnvIf Host dev.store.aandgwebtech.ca MAGE_RUN_TYPE=website

    Where:

    dev.store.aandgwebtech.ca is the domain name for the new store/site/view that you are setting up
    devstorethisandthat is the code name used internally by Magento to identify the store under either the website or store view screen under manage stores.
    website indicates that it's a website, but it can also be set to store

     


  11. Save the .htaccess file
  12. If the symbolic links have been created by your web host , then test both of the orginal store as well as the new store to verify that they are both indeed working.
  13. Happy e-commerce! I hope that this helps eliminate some of the confusion surrounding configuring a Magento multi site installation.

P.S. There is an interesting side effect of this change. If you try to log into the admin panel via the newly created domain, after you enter your username and password it will re-direct you back to the login screen in an infinite loop. You can only log into the store's admin panel via the URL that you used to originally create the store. I know that the error should be fixed but it means that it makes it more difficult for someone to get into the admin of your stores. Just remember to save your admin URL first.

 


 

 

 

Comments are closed.