1

So I have set up a Symfony 3.4 application, which I downloaded following the instructions here using the Symfony Installer:

https://symfony.com/download

I am building this app for my employer to run within multiple eCommerce sites. It will not only have to have to use the prod, test, and dev configurations that come preinstalled in /app/config/ directory, but it will also need one set site unique configurations (mainly several twig globals, etc) for each site that it runs on.

My question is what is the best way to detect what site my app is running on and pass that into the configuration side of things?

I am looking at how dev, test, and prod work int web/app.php and web/app_dev.php and wondering if there is some way I can expand on that concept similarly based on the site domain.

Not sure if this matters but I am using the default Yaml configuration files that came with the framework download and would like to stick with that over the XML or PHP options.

Thanks for your help.

space97
  • 153
  • 1
  • 4
  • 19
  • Wouldn't it be more sensible to have multiple Symfony app instances for each customer? – Jovan Perovic Aug 20 '18 at 18:32
  • So there will be one repository for this app, but I will install one instance on each of the 3 eCommerces sites that this is needed for. Is that what you are referring to or something else? – space97 Aug 20 '18 at 19:04
  • 1
    Off topic but you should really use [Symfony Flex](https://symfony.com/doc/3.4/setup/flex.html#using-symfony-flex-in-new-applications) for creating your project. The Symfony installer has gone away. The flex directory structure is a bit different and is forward compatible with Symfony 4. – Cerad Aug 20 '18 at 19:46
  • So I am converting a decent bit of code into this which was on one of our sites which is mostly based of Symfony / Doctrine packages like the Symfony framework, but with custom bootstrapping. I chose Symfony 3.4 to make that code conversion process easier, since that was what the code was already on. I plan to update to Symfony 4 on a future project. But for now it is what I have to make work. I will keep Symfony Flex in mind. – space97 Aug 20 '18 at 20:25

1 Answers1

1

You have several options to do this depending on your server configuration. What I did was define an environmental variable SYMFONY__ENV in my virtual host like this: SetEnv SYMFONY__ENV dev.

Then you can modify your web/app.php to read this variable.

$env = strtolower(getenv('SYMFONY__ENV'));
$kernel = new AppKernel($env, $env === 'dev' || $env === 'test');

As a commenter mentioned you should update to Symfony Flex when you can but you can use this configuration until you do.

Chip Dean
  • 4,222
  • 3
  • 24
  • 36
  • So this sounds good. The only issue is that I have dev, test and prod settings already. I am going to need to run multiple instances of this application (4 now that I think of it) so that means I would need dev_site1, test_site1 and prod_site1 then dev_site2, test_site2 and prod_site2 and so on for each of the 4 sites giving me something like 12 large fairly redundant settings files. What I would like to do is have settings for dev, prod, and test and then use them in conjunction with a different set for site1, site2, site3 and site4. I would be looking for 2 unique sets of settings and not 1. – space97 Aug 24 '18 at 16:33