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:
1 2 3 4 |
# app/config/config.yml imports: - { resource: parameters.php } |
And from there it’s easy:
1 2 3 4 5 |
// app/config/parameters.php $container->setParameter('rds.user', getenv('RDS_USER')); // if set via apache SetEnv use: //$container->setParameter('rds.user', apache_getenv('RDS_USER')); |
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
.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
"extra": { "incenteev-parameters": { "file": "app/config/parameters.yml", "env-map": { "database_host": "RDS_HOSTNAME", "database_port": "RDS_PORT", "database_name": "RDS_DB_NAME", "database_user": "RDS_USERNAME", "database_pass": "RDS_PASSWORD" } } } |
Any mapped parameter would be overwritten by value from environment variable. For more info on env-map
see documentation.