Welcome Guest, Not a member yet? Register   Sign In
same site mirrored on multiple subdomains, just need seperate databases
#1

[eluser]phazei[/eluser]
I have a site, say domain.com

I need to basically clone its functionality on multiple subdomains.

jake.domain.com
bill.domain.com
demo.domain.com

They all are going to do the exact same thing, but will have their own separate database. So they are just clones of domain.com

I don't want to actually just copy everything over to the subdomain because that will make updates very difficult.

In config I have:

$config['base_url'] = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '')."://".$_SERVER['HTTP_HOST'].preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME'])).'/';



So the site will work wherever I put it without needing to modify that I don't believe.


The subdomains are just going to be sub-directories from /root/

eg:
/root/jake
/rood/demo



The only configuration that needs to be different between the sites in the database info.

How can I have only the database config different between these sites?

Is there a way I can just put it in the separate index file I'll have for each site? That would be optimal.

And are there any other issues that I haven't thought of that might be of use?

Thanks,

Adam
#2

[eluser]pistolPete[/eluser]
You have already specified your $config[‘base_url’], so use it to choose the right database.
Put this in ./system/application/config/database.php:
Code:
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "";
$db['default']['password'] = "";
switch($config[‘base_url’])
{
   case 'put first subdomain here': $db['default']['database'] = "first database";
   break;
   case 'put second subdomain here': $db['default']['database'] = "second database";
   break;
(...)
}
$db['default']['dbdriver'] = "mysql";
(...)

You could also define a constant in each index.php file:
Code:
define('DATABASE_USED', 'put subdomain specific db here');
And in ./system/application/config/database.php use:
Code:
db['default']['database'] = DATABASE_USED;
#3

[eluser]xwero[/eluser]
You could do
Code:
$active_group = config_item('base_url');
Then you can create domain based settings.

if only the database changes pistolPete's solution is better.
#4

[eluser]phazei[/eluser]
:cheese:
Wow, so simple. YAY. Super many thanks pistolPete.




Theme © iAndrew 2016 - Forum software by © MyBB