I’m currently working on a symfony project for our company. And I have issues figuring out how to build a dynamic configuration from an environment variable.
My main problem here is that symfony caches my “defaut_database” once, and then never changes it. I’m willing to change this with a variable defined in each Vhost I create.
Here is my Vhost configuration :
<Macro demoVHost ${slug}>
<VirtualHost *:80>
ServerName ${slug}.domain.com
DocumentRoot /home/domain/www/web
SetEnv SYMFONY__DYNAMIC__DATABASE_NAME db_${slug}
<Directory /home/domain/www/web>
AllowOverride None
Order Allow,Deny
Allow from All
Require all granted
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app_demo.php [QSA,L]
</IfModule>
</Directory>
ErrorLog /home/demo/log/${slug}.error.log
CustomLog /home/demo/log/${slug}.access.log combined
</VirtualHost>
</Macro>
Use demoVHost aaa
Use demoVHost bbb
Use demoVHost ccc
And my .yml configuration :
doctrine_mongodb:
connections:
default:
server: 'mongodb://127.0.0.1:27017'
options: {}
default_database: "%dynamic.database_name%"