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:
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.
- Read both tutorials completely
- BACK UP your Magento install just in case
In order to set up multiple stores in Magento we will complete the following steps from both tutorials:
- Create a domain / sub domain from cPanel
- Request from the web host's tech support that symbolic links to your magento install be created in the new domain's directory
SetEnvIfdirectives to the
- Configure Magento to see the second store
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
SetEnvIfdirectives in thier own
.htaccessfile so that magento knows what domain is being access in order to select the correct site / store / view.
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_htmlat 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
So in our case we'll send a e-mail to our web host to create the symbolic links in the
- Why we're waiting, follow the steps to set up your new store in second tutorial.
- As in the second tutorial, copy both the index.php & .htaccess to the root directory of the new domain that you just created
- 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
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
dev.store.aandgwebtech.cais the domain name for the new store/site/view that you are setting up
devstorethisandthatis the code name used internally by Magento to identify the store under either the website or store view screen under manage stores.
websiteindicates that it's a
website, but it can also be set to
- Save the .htaccess file
- 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.
- 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.