title: Symfony 2 - multiple server configuration
body: <p>We're starting to adopt Symfony 2 for projects here at work, which is great, but there's a challenge I'm working to solve that I've almost got, but not quite.</p>
  
  <p>Symfony treats the concept of an environment as a separate runtime on a single server.  This is great because you can switch between runtimes with different front controllers (web) or using the env switch (cli) at a whim.</p>
  
  <p>However, our code is deployed across many servers as part of the development process.  Everybody has a local VM, then code propagates up through Integration, QA, Staging, and finally Production.</p>
  
  <p>So, our concept of an environment is server (virtual or physical).  Here are the goals with this custom configuration</p>
  
  <ol>
  <li>Maintain Symfony's ootb functionality in respect to runtime environment switching</li>
  <li>Allow for public (i.e., developer controlled) configuration per-server</li>
  <li>Maintain private (i.e., sysad controlled) configuration per-server</li>
  <li>Will work for both web and cli</li>
  </ol>
  
  <p>This means we can't just 100% rely on <strong>parameters.ini</strong> or any statically-named file, for that matter, since the developer will need control over configuration for each server plus all this files will be living next to eachother in git.</p>
  
  <p>So, what I'd <em>like</em> to do is this. Add a new value to parameters.ini that sets the server environment.  Something like this</p>
  
  <p><strong>app/config/parameters.ini</strong></p>
  
  <pre><code>[parameters]
      server="int"
  </code></pre>
  
  <p>And then, in the kernel, load an additional configuration file based on that value. For example, I'd love for this to work but it doesn't (since the container doesn't yet exist at this step)</p>
  
  <p><strong>app/AppKernel.php</strong></p>
  
  <pre><code>public function registerContainerConfiguration(LoaderInterface $loader)
  {
    $loader-&gt;load(__DIR__.'/config/config_'.$this-&gt;getEnvironment().'.yml');
  
    // Per-server config
    $server = $this-&gt;getContainer()-&gt;getParameter( 'server' );        
    if ( $server )
    {
      $loader-&gt;load(__DIR__.'/config/server/'.$server.'.yml');
    }
  }
  </code></pre>
  
  <p>This would enable the usage of a file like <strong>app/config/server/int.yml</strong> that the developer can use to control non-private (i.e., not parameters.ini) configuration values.</p>
  
  <p>Thanks for reading, and let me know if anything is confusing.</p>
  
  <h2>EDIT</h2>
  
  <p>For clarification, things I <em>can't</em> use or rely on</p>
  
  <ul>
  <li>*nix environment variables from the user's profile or via <code>export</code>. Why? Integration, QA, and Staging might all be on the same box</li>
  <li>Anything in the vhost config (won't work for cli)</li>
  <li>A statically-named file (i.e., something just named <strong>server.ini</strong> won't work)</li>
  </ul>