Saturday, 5 May 2012

Multiple Stores on Magento 1.6+ (possibly 1.4+) and with CPANEL and shared hosting

Right, most of the guides out there on multi store setup in magento are a bit techy, plus they also tend to assume that you have, and want, to mess about with stuff like virtual hosts.
Well none of that is necessary.

I have two domain names registered, lets call them http://www.fantastic.co.uk and http://www.rubbish.co.uk
(those arent my domains, dont follow the links!)

So my magento store is all set up with the default store of fantastic.co.uk and working nicely.

Now I want to add a new website for rubbish.co.uk, and only have my rubbish products on show. lol.

This is how you do it.

1) point rubbish.co.uk at your DNS server for the same as fantastic.co.uk. Exactly the same.

2) go to cpanel for fantastic.co.uk and go to addon domains. Add rubbish.co.uk and set the username to anything. but importantly, set the document root to your magento root folder. This may be public_html, it may be public_html/magento. This is very important to get right.

3) Note that you may have to wait for rubbish.co.uk to propagate before it works. This can take up to 48 hours. Go do stuff. Read an entire book or something.

4) Go to magento backend. Go to catalog-> categories and add a new root category, call it what you like. I called mine rubbish. Make sure it's active, anchor, etc.

5) Go to system -> manage stores. Add a new website, store and store view in that order. Remember the "code" you enter though for website, you'll need that soon. Point the store to your new root category.

6) Go to system -> configuration. Choose website scope for "rubbish" in the drop down combo box. Thats the one in grey (the top level for "rubbish").  Go to Configuration-> general-> web on the left side, and change these (untick and enter your own url):

Unsecure Base URL: http://www.rubbish.co.uk
Secure Base URL: https://www.rubbish.co.uk
Use Secure URLs in Frontend: NO (you cant have 2 ssl certs on one hosting account*)
(later you can come back and change also CMS home page, but thats for later)

*well, you can in theory, but I have yet to find a host that will entertain theory.

 Now save this. Oh, its IMPERATIVE that you include the www above. Otherwise it doesnt work.

7) now we need to redirect any traffic that DOESNT include the www. Go to cpanel and go to REDIRECTS. Add "rubbish.co.uk", leave the / box blank, and set "redirects to " to "http://www.rubbish.co.uk". Important: set the radio button to "Do not redirect www" and leave wildcard blank. Save this.


8) phew. Now to see any products, you need to:
- add some products/categories to that root category you created in step 4. You also need to go to the products themselves, and in the Websites tab, enable them for rubbish.co.uk.

9) clear all magento caches, reindex all files.

10) go to magento root folder, and open index.php for editing. Add this line at the bottom before "/* Store or website code */" (line 74 for me)


if ($_SERVER['HTTP_HOST'] == "www.rubbish.co.uk"){
$_SERVER["MAGE_RUN_CODE"] = "rubbish";   <--this is the code you made up in step 5
$_SERVER["MAGE_RUN_TYPE"] = "website";
}


Then you should see your website when you type in either http://www.rubbish.co.uk or http://rubbish.co.uk.


1 comment:

  1. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles.

    Megento Commerce

    ReplyDelete