Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure symfony project for Multiple Domains

Tags:

php

symfony1

We have a product developed in PHP Symfony framework. We have couple of clients right now for whom we are maintaining different code base and databases (MySql).

They access their respective code base using subdomain like client1.myproduct.com and client2.myproduct.com

Now we want to make a single code base for both the clients and only keep files which are different (in terms of logic) for both of them in separate subdomains.

So both the subdomains will point to the same code base but will access files from their respective subdomains whenever required i.e. whenever logic is different for some feature for both the clients.

Can anyone suggests what is the best way to go about this?

like image 824
abhi Avatar asked Aug 19 '10 10:08

abhi


2 Answers

sites: [foo.com, bar.co.uk, www.mike.es]

// index.php
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');

// get the domain
$domain = $_SERVER['SERVER_NAME'];

// get rid of www, com, es etc ...
foreach(array('www.', '.com', '.es', '.co.uk') as $crap) {
    $domain = str_replace($crap, '', $domain);
}
$confs = array(
    'foo' => 'somefoo',
    'bar' => 'somebar',
    'waz' => 'andwazconfig'
);
$cfg = (!empty($confs[$domain])) 
    ? $confs[$domain] 
    : 'default';

$configuration = ProjectConfiguration::getApplicationConfiguration($cfg, 'prod', false);

sfContext::createInstance($configuration)->dispatch();

// End of index.php

Hope this helps

like image 178
Lloyd Moore Avatar answered Oct 24 '22 09:10

Lloyd Moore


Yes you can do so. Symfony Routing can handle this use-case, but it is not one of the easier tasks to do. For a detailed description take a look at the Symfony-Documentation: http://www.symfony-project.org/more-with-symfony/1_4/en/02-Advanced-Routing

like image 2
Timo Haberkern Avatar answered Oct 24 '22 10:10

Timo Haberkern