Tutorial: Multi-Site, Multi-Domain Setup
One of Magentoâs greatest strengths is its capabilities for scaling to support multi-store and multi-language retailing all from the same backend. In this tutorial, we will be showing you how to take advantage of Magentoâs scalability by creating multiple websites with unique domain names sharing the same product catalog. (***NOTE: Each store can also be configured to offer a unique product catalog as well.)
For this example, weâll be attempting to set up domain1.com, domain2.com and domain3.com.
Generally, Magento is installed into the folder /var/www/http, as per the Magento Installation Guide, and you can find more information related to the initial setup and configuration of any Magento installation there. We arenât going to through an full blown installation right now though, and for our purposes, we are going to presume that the Magento instance has already been installed in the server.
Weâll be dividing the process into steps based on the areas of configuration we will need to deal withânamely, Categories, Store Configuration in Magento Admin, Store Configuration in the Server.
First, will need to create our Categories. Since all three websites will be sharing the same catalog, we will be using the default root Category in Catalog -> Categories -> Manage Categories and will be creating our categories under that root category (i.e. Clothing, Electronics, etc.).
These categories (Clothing, Electronics) should be set as both âIs Activeâ from the General Information tab and âIs Anchorâ from the Display Settings tab for them to appear on the frontend of your Magento shop. (***NOTE: If the websites will not be sharing the same catalog, a Root Category must be created for each website. Thus, if there are 3 websites, there will be 3 Root Categories with subcategories under them.)
2: Store Configuration in the Magento Admin
1. Now that we have created our Categories, itâs time to create our websites by going to System -> Manage Stores and clicking the âCreate Websiteâ button.
- Name â domain name of our new website
- Code â a parameter that will be used in configuring the Apache web server to point to that particular domain name
2. Once the website has been created, weâll create the store corresponding to this website by clicking on the âCreate Storeâ button in System -> Manage Stores.
- Website â website to which this store will be associated
- Name â the same as the website name
- Root Category â the root category that will be used for this store. (Refer to Step 1 for Details)
3. Then, we create the store view which is the interface that the customer will be able to access on the frontend. Click the âCreate Store Viewâ button in System -> Manage Stores.
- Store â store to which this view will be associated
- Name â name of this store view (i.e. English Version, German Version, etc.)
- Code â code for this store view
- Status â if enabled, this store view will be accessible from our frontend, otherwise, it will not be accessible
4. After the Store has been created, we need to configure the Unsecure Base URL and Secure Base URL under System -> Configuration -> General -> Web. Before we set their respective base URLs, we first need to ensure that the configuration scope is set to the domain1.com website to define which site we are working on.
Then, we modify the base URLs for both Unsecure:
with the corresponding domain name by unchecking the âUse default [STORE VIEW]â checkbox and then save the configuration.
5. Now we just repeat Steps 2-4 for the other two websites, domain2.com and domain3.com by replacing the fields with their respective information.
3: Store Configuration in the Server
1. Now we re-configure the Apache configuration file, httpd.conf, for all domains to set the DocumentRoot to our Magento directory. In this case, the directory is /var/www/http
<VirtualHost *:80> ServerAdmin DocumentRoot /var/www/http ServerName domain0.com </VirtualHost> <VirtualHost *:80> ServerAdmin DocumentRoot /var/www/http ServerName domain1.com </VirtualHost> <VirtualHost *:80> ServerAdmin DocumentRoot /var/www/http ServerName domai2.com </VirtualHost>
2. Edit the .htaccess file at /var/www/http/.htaccess and add the following lines below:
SetEnvIf Host www\.domain1\.com MAGE_RUN_CODE=domain1_com SetEnvIf Host www\.domain1\.com MAGE_RUN_TYPE=website SetEnvIf Host ^domain1\.com MAGE_RUN_CODE=domain1_com SetEnvIf Host ^domain1\.com MAGE_RUN_TYPE=website SetEnvIf Host www\.domain2\.com MAGE_RUN_CODE=domain2_com SetEnvIf Host www\.domain2\.com MAGE_RUN_TYPE=website SetEnvIf Host ^domain2\.com MAGE_RUN_CODE=domain2_com SetEnvIf Host ^domain2\.com MAGE_RUN_TYPE=website SetEnvIf Host www\.domain3\.com MAGE_RUN_CODE=domain3_com SetEnvIf Host www\.domain3\.com MAGE_RUN_TYPE=website SetEnvIf Host ^domain3\.com MAGE_RUN_CODE=domain3_com SetEnvIf Host ^domain3\.com MAGE_RUN_TYPE=website
3. Restart Apache Server
If you are on a Red Hat based distribution, youâll be able to type service apache restart. For other distributions, youâll want to type apachectl restart. (***NOTE: The second option here is different than âapachectl gracefulâ which will run a graceful restart and reload configuration files, without terminating current connections. We donât have any visitors to our site yet, so itâs okay to do a âapachectl restartâ.)
4: Weâre Ready to Go!
After weâve complete all of these steps we should now see all 3 domains in our backend:
All thatâs left now is to add products to the catalog and give each site a custom theme if we wish to do so. Many people are taking advantage of Magentoâs powerful multi-store functionality, whether itâs to set up stores with multiple languages, different catalogs and even the same catalogs (as in our example) with different front ends as a marketing vehicle. No matter which you decide to use Magentoâs powerful features for, we hope this post will provide a good starting point to help you get there!