Christian Bergau
Christian Bergau

Reputation: 646

Symfony 2 how to create a parameters_dev.yml?

i just started coding with Symfony 2. On my local machine i setup my database using app/console doctrine:database:create and doctrine:schema:create which works great.

The problem i have is, local i have diffrent parameters defined in parameters.yml than on my production environment. How can i define paramters for dev and for prod? I've already tried to create a parameters_dev.yml but this did not work.

Should i maybe create a paramters.yml on my prod server and copy it after deployment so i dont have my DB password in version control?

Upvotes: 1

Views: 1247

Answers (2)

Gaston Rodriguez
Gaston Rodriguez

Reputation: 21

In Symfony 2.7 I had to add this to appKernel.php:

public function registerContainerConfiguration(LoaderInterface $loader)
{
     $loader->load($this->getRootDir().'/config/parameters_'.$this->getEnvironment().'.yml');
     $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}

And then create both parameters_dev.yml and parameters_prod.yml.

Don’t forget to add this:

imports:
 - { resource: parameters.yml }

on the first line of each new ymls.

Upvotes: 2

Lazy Ants
Lazy Ants

Reputation: 27

parameters.yml should't be handled by version control. You have to set it on ignore in .gitignore. Only parameters.yml.dist has to be versioned

more over if you use symfony 2.3 and install vendors using composer on prod you will be prompt to enter all the setting from parameters.yml.dist so parameters.yml will be generated automatically

Upvotes: 4

Related Questions