Get environment variables in symfony2 parameters.yml

Question:

I’m trying to get my symfony2 app running on elastic beanstalk. I’m trying to get environment variables (RDS_USER, RDS_PASSWORD, etc…) in my parameters.yml in order to get the database credentials.
The thing is symfony2 needs the environment variables to be prefixed by SYMFONY__ so I could I get these variables without prefixes ?

Answer:

You can load a php file as a resource:

And from there it’s easy:

UPDATE:
Since the original answer, a new solution was provided (thanks to @darragh-enright for pointing it out) using env-map feature of incenteev-parameters component in composer.json.

Any mapped parameter would be overwritten by value from environment variable. For more info on env-map see documentation.

Leave a Reply