Symfony parameters list

The Symfony parameters files are very neat but you should know how to use them. Let’s focus on how to keep track of the full list of your application parameters.

A list of all parameters

An interesting question that often arises is: ok, I use different parameters on each server / environment, but how do I keep an official list of all parameters? This is especially important when new parameters are added later during development.

A quick solution is to set dummy (not sensitive) parameters in the parameters.yml file, and then override them in:

  • parameters_prod.yml
  • parameters_dev.yml
  • parameters_test.yml

and so on.

You commit the main parameters.yml, since it’s only used as a reference list and does not contain actual data.

But we can do better: this solution has been standardized with the use of a special file. Let’s see how it works.

The “dist” file

Turns out Symfony already provides a parameters.yml.dist file whose purpose is exactly to act as a reference.

All parameters are listed there, with – where it makes sense – a sensible default value. This file is committed and deployed with the application, so be extra careful not to put any password, api key, secret in this file.

Automatic check

Even more interesting is the fact that – since Symfony 2.3 – a special bundle will check this file during composer install and:

  • it creates a default parameters.yml file if it’s missing
  • ask you to define values for all parameters defined in the dist file which are missing in your local parameters file.