Magento is yet a powerful opensource e-commerce solution. It allows you create multiple stores inside single installation.
You can then point each of store to a new url.

Lets start with multi store creation.

Step 1: Create Category for new store

Magento needs root category for the store, you can either create new store category for your store or pick default one.

Below I am going to add a new category for new store you can just select default if you don’t want a new category.

Create New Category

Go to Catalog > Manage Categories and create new root category

magento_multidomain_add_root_category

Provide the category name and set is active to “Yes”

magento_multidomain_add_root_category_form_1

In Display settings tab select is anchor to “Yes”

magento_multidomain_add_root_category_form_2

Save the category, It will be showing on left side categories as new root category

magento_multidomain_add_root_category_created

 

 

Step 2: Create new site, store and store view

Login to magento backend and go to system > manage stores

 

Create website

Click on “Create Website” Button

create-new-magento-website

Enter website name and code and save it

new-website-form

 

After Saving the website we are going to create store for that website

 

Create Store

Click on “Create Store” button to create a store for that website

create-new-store-on-magento

Select website you just created from drop-down and provide store name, select the root category you just created for your store. If you haven’t created new root category you can pick default one.

magento_multidomain_create_new_store

Save the store and next is to create store view for that store

 

Create Store View

Click on “Create store view” button to create a view for store we just created.

magento_multidomain_create_store_view

Select the store you just created from drop-down and provide store code, set is Enabled.

magento_multidomain_create_store_view_form

 

Save “Store View” and that’s it. New store has been created.

Configure your store

we have created store. Now we are going to configure it i.e store urls and store name

Go to System > Configuration

Select your store from top left drop-down

magento_multidomain_configure_store

Click on web in left and then provide secure and unsecure urls for your store.
Note: Uncheck the “Use Website” checkbox

magento_multidomain_configure_store_web

Save Config.

Next step is to create subdomain in cpanel for our new store

 
 

Step 3: Create Sub Domain

Go to your hosting website or CPanel and create a new subdomain i.e dev.mywebsite.com
Create document root inside your magento installation.
For example if your magento is installed at /home/usrname/public_html/magento
Then your subdomain document root should be like /home/usrname/public_html/magento/dev_mywebsite

So basically we have created new directory inside existing magento installation and named it to our store name.

magento_multidomain_subdomain_directory.png

Look at the screenshot above, “dev_mywebsite” is placed inside magento
 
 

Step 4: Linking Magento with Store

We have created our subdomain and pointed it to directory inside the magento installation.
You would be thinking how magento will use this subdomain directory, lets solve this game.

Copy magento index.php and .htaccess files into new store

We have created a separate directory inside magento for subdomain so we can do our changes for new store separately but that doesn’t mean we are going to copy whole magento code into it. A big No. We are just going to copy the index.php and .htaccess file inside the dev_mywebsite directory.

Do it via ssh or do it via ftp, I am going to do it via ssh

Cd to the dev_mywebsite directory and copy the index.php and .htaccess file

$ cd /home/usrname/public_html/magento/dev_mywebsite
$ cp ../index.php ../.htaccess .

 

Creating links to default magento installation

We have copied index.php and .htaccess files from base magento installation into new store directory. Now we are going to create links to magento so our new index.php file will still using base magento installation.

$ ln -s ../app ./app
$ ln -s ../errors ./errors
$ ln -s ../js ./js
$ ln -s ../lib ./lib
$ ln -s ../media ./media
$ ln -s ../skin ./skin
$ ln -s ../var ./var

 
 

Step 5: Manage Subdomain  Redirection at magento

We have linked base magento installation with our new store directory, now we just have to configure .htaccess file inside dev_mywebsite directory so magento can know which store to load.

For example you type dev.mywebsite.com in url it will call index.php located inside dev_mywebsite directory and will look for configurations in .htaccess file location in dev_mywebsite directory before loading index.php.

gentSo we are using .htaccess file to control the magento. Mao uses environment variables to load the stores.

Open your .htaccess file located inside dev_mywebsite directory and on top write following lines


<IfModule mod_setenvif.c>
	SetEnvIf Host .*dev.mywebsite.* MAGE_RUN_CODE=dev_mywebsite
	SetEnvIf Host .*dev.mywebsite.* MAGE_RUN_TYPE=website
</IfModule>

 

Save the file and now run your store in browser like dev.mywebsite.com

It will be loading your store.
Enjoy 🙂

Please provide your feedback 🙂

Advertisements