This appears to be the scariest topic relating to Symfony2, as after a week of searching and testing, I am still unable to find an answer to this.
In short, I am buildin
Basically Fabien is right, there's no reason to have more than one application, if you really have a need for a different application it's probably a different project. Bundles and libraries can be easily shared like any other bundle you see on the web. Then you can have the small part of the set up belonging to each thing you call "app" in the app part of each project. If they share the entirety of the code then it's just a matter of configuration hierarchy for each sub-domain, which could be your case considering you want to share some part of the config.
Symfony has many ways of allowing you to reutilise code which are very nice, but the framework is not meant to have many applications, if you want to try to hack it, go ahead, but then you're not using the framework anymore. And that's why you can't find examples, not because it's scary, it'd not be that hard to modify, it'd just be ugly, IMO.
You can create different configuration using the testing/Dev example :
Step 1 Create as many web/app.php file as you have subdomain.
web/app_subdomainx.php
Step 2 In each app_subdomain_X.php file change configuration :
$kernel = new AppKernel('subdomainx', false);
Step 3 create configuration file matching your environment
config_subdomainx.yml
security_subdomainx.yml
Step 4
acces you specific domain through
/web/app_subdomainx.php
PS :
Keep config.yml for common configuration (like db connection) and include config.yml into config_subdomainx.yml
imports:
- { resource: config.yml }
Maybe you can try this bundle, that handle multiple domain website on same app and database: https://github.com/AppVentus/MultiDomainBundle.
you can try to find something on github. I've found the following Bundle which should do this. Imikay RouterBundle
Sorry for necroing...
I just want to say that I have looked into multiple application structure for Symfony2 as well. Since version 2.4, when routing supported hostname based routing, there has been no need for multiple apps.
All you now need to do is separate your "apps" into different bundles, say AcmeSiteBundle
and AcmeApiBundle
, then in app/config/routing.yml
:
acme_site:
host: "www.{domain}"
resource: "@AcmeSiteBundle/Resources/config/routing.yml"
prefix: /
defaults:
domain: "%domain%"
requirements:
domain: "%domain%"
acme_api:
host: "api.{domain}"
resource: "@AcmeApiBundle/Resources/config/routing.yml"
prefix: /
defaults:
domain: "%domain%"
requirements:
domain: "%domain%"
Remember to have domain
parameter set in app/config/parameters.yml
parameters:
.....
domain: example.com
Multiple applications projects can be achieved by splitting your code in multiple Kernels.
You can then benefit:
I have described the whole process here: http://jolicode.com/blog/multiple-applications-with-symfony2 and you can find an example distribution here: https://github.com/damienalexandre/symfony-standard