tags:

views:

153

answers:

4

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?

A: 

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

Timo
A: 

I have described the use of dynamic subdomains in Symfony here using sfDomainRoutePlugin.

However, you will need to rewrite much of your existing application logic to support multiple clients in the same app, and you must also merge the two old databases.

cvaldemar
A: 

I requested the same information and have the chance to receive mike´s and fabien´s reply. Here are the details:

For one logic with subdomains: http://trac.symfony-project.org/wiki/HowToDoMultipleSitesWithSingleCore

Multiple Sites Based on Identical Configurations This may be a strange topic, but I wanted to configure our access into subdomains, all with SSL access. We needed different sites because SSL forces IP based virtual domains, which meant different document roots for us. Such as:

•www.mydomain.com •admin.mydomain.com •parents.mydomain.com However, these were all sites with the same core schema and plugins. The advantage of this configuration is:

•Shared model files: All the XxxPeer classes will be linked across applications Disadvantage:

•You now have 2-n different caches/logs to monitor. If you look at a typical Symfony directory structure, it can be broken up to two type groups:

•Common Directories: ◦batch ◦config ◦data ◦doc ◦lib ◦plugins ◦test •Application Specific Directories: ◦apps ◦cache ◦log ◦web Here are the steps I took:

•Develop the www.yourdomain.com schema and site. Once this is starting to come together, you can start to develop the additional sites. •In the new site, symbolic link the Common Directories •In the new site, create the Application Specific Directories ◦NOTE: In the web directory, you may need to copy some of the original contents (css, js, and .htaccess files come to mind). Keep this in the back of your mind as you start to bring up the new site. •Run the command symfony fix-perms ◦NOTE: For me, Virtualmin creates these new sites with new usernames. You will have to insure that all the Application Specific Directories are owned by that username, so your clear-cache commands and logging commands work. •Now, you have a the project configured. You start by doing: ◦symfony app MYAPP ◦symfony module MYAPP MYMODULE ◦... •You will now find that your apps/MYAPP/modules/MYMODULE has been created, and you have full peer access to the entire database

Here is fabien regarding one logic with different domains names: client1.com client2.com using same apps.

For one logic with different domains: "You could point them all at the same front controller, and then use a filter or a action parent class to do things like change the site template etc. However, having a front controller per domain may be more efficient, and is a perfectly good way to go.

Each domain could have its own application, but the bulk of the logic should be implemented in plugins, so they can be enabled for each domain/app that needs them, and shared as required. How much code is required per application depends, I guess, on how different the sites actually are. "

sebastian_h
A: 

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

Lloyd Moore