Is it possible to make one installation, and from this installation to make multiple shops with different databases?

Something like I will make one installation on domain.1 with a database, and from admin I will crate a new website and a store on some new database for domain.2.

I know that multiple stores can be achieved with one database. But can it be the same with different databases.

  • Can you explain why you need 2 databases? Is it a master/slave configuration or just want to have 2 separate databases?
    – Marius
    May 26, 2014 at 8:20
  • I just want to have 2 separate databases. I need two different stores with one installation but separate database.
    – Mike
    May 26, 2014 at 8:22

6 Answers 6


Great answer slarek. We did something very similar. Instead of editing index.php we setup separate folders outside of magento's codebase, and include mage.php from those folders, and then edit the etc_dir (and other dirs) like in your method above.

folder structure:


Inside each of the client folders are:

  • /www/clientx/etc/local.xml (with unique database defined, and unique redis db)
  • /www/clientx/etc/modules (this is a sym link to /www/magento/app/etc/modules)
  • /www/clientx/index.php

in /www/clientx/index.php

define('MAGENTO_ROOT', '/www/magento');

...(rest of index.php is business as usual)...

$client = isset($_SERVER['CLIENT_ID']) ? $_SERVER['CLIENT_ID'] : '';] Mage::run($mageRunCode, $mageRunType, array('etc_dir'=>'../'.$client));

We set

$_SERVER['CLIENT_ID'] in Nginx with 
`fastcgi_param  CLIENT_ID clientx; `

I don't think this is possible out of the box. Magento supports master/slave database configuration, but you have to have them for all the stores.
And I don't think this can be done easily with custom coding since the stores are kept in the database.

So depending on the store view you need to know which database to connect to, but in order to know the store view, you need to query a database. So you run around in circles.


You want to have several separate stores with their own databases using single codebase?

Well, there's no simple and recommended way to do that. That being said we can see what CAN be done:

Database information comes from a single xml file: app/etc/local.xml This file is being loaded from app/Mage.php so if you change that file you can theoretically decide which configuration file you're going to load (based on desired condition, such as domain name). Voila, different domain, different database. Now comes the Bad News Part(tm).

  1. You're overwriting core code and so called "god class" at that. This is considered a VERY BAD practice in Magento world! Every time you upgrade your changes will be overwritten.
  2. Content overlapping. Not all your content is stored in database, there's also media folder and there's session folder (var/session) you either need to find a workaround for (for example custom paths based on database) or store both images and sessions in the database (before you ask: yeah, this is possible).
  3. Cache. You most certainly don't want you different stores share cache folder (var/cache). Fortunately it's possible to use external caches, such as memcached instead of storing files to that folder. Still you must make sure that your cache ID-s won't overlap, because if they do, you're going to be in the world of hurt.
  4. You can't use compilation (the feature is deprecated anyway).
  5. Maybe something else I'm forgetting. Anyone?

i just found this extension:

Magento Multi Client
Host multiple clients on the same Magento code base.

Each client has their own local.xml and etc/modules.xml. This allows you to specify separate databases and caching services per client, as well as enable/disable modules as requested.

Each client maintains their independance but shares a code base.

This could be considered a Magento Go-esque approach to hosting Magento websites.


You just need to create a new folder to contain the configuration files and in index.php you add an array of options to Mage::Run().

In that folder you'll have all the same content as app/etc/ including the modules folder.

First domain :

Mage::run($mageRunCode, $mageRunType, array('etc_dir'=>'app/domain1'));

Second domain :

Mage::run($mageRunCode, $mageRunType, array('etc_dir'=>'app/domain2'));

this will tell Magento where is the config files for the domain.


What is your main goal? Different admin area or easier handling of your source code?

I would do it with a mix of "local" directories and files and linked (ln -s) common directories and files

/www/common /www/shop1 /www/shop2


  • app/
  • js/
  • lib/
  • ...


  • /var/
  • index.php
  • .htaccess
  • app/etc/local.xml

But could be a little bit confusing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.