Sometimes your project might require you to use the same Symfony2 app for multiple domains. In such scenarios you might require separate database connection or other configuration specific to each domain.
This short tutorial will show you how to do this with Symfony2.
To start with we will set environment variables that we can use in our Symfony app. Add the following to your virtualhost configuration for domain2 in Apache.
Now we can access the environment variable domain.name in our Symfony2 code.
To know more about using environment variables in Symfony2 read http://symfony.com/doc/2.0/cookbook/configuration/external_parameters.html
Now we need to modify our AppKernel to use separate config files and cache folder when the site is accessed from domain2.
Make sure you create a separate folder config\domain2 and move the config file for all environments such as dev, test and prod. You can also make use of the import feature to import the default config.yml and only modify the properties that have to be changed for domain2.
That's it, access the app from domain2 and it will load domain2 config files and create a separate cache folder for it.
Copyright © 2013 Amal Raghav