# Handling environment-specific configuration in Zend Expressive apps

**URL:** <https://discourse.laminas.dev/t/handling-environment-specific-configuration-in-zend-expressive-apps/594>\
**Category:** Mezzio\
**Created:** [May 20, 2018, 3:13pm UTC](https://discourse.laminas.dev/t/handling-environment-specific-configuration-in-zend-expressive-apps/594 "2018-05-20T15:13:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtymek](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/mtymek/32/343_2.png) [@mtymek](https://discourse.laminas.dev/u/mtymek)\
**Post date:** [May 20, 2018, 3:13pm UTC](https://discourse.laminas.dev/t/handling-environment-specific-configuration-in-zend-expressive-apps/594/1 "2018-05-20T15:13:16Z")

</div>

I’m looking for some good practices for handling environment-based configuration variables (database endpoints, credentials for external services, etc) in Zend Expressive apps.

["12 factor” methodology](https://12factor.net/config) encourages to keep them in server’s environment variables. Providers like AWS have built-in support for propagating them, simplifying application deployment and management.

Symfony deals with this problem with DotEnv component. In development mode, all variables can be defined in “.env” file. In ZF ecosystem, components tend to keep this data in `ConfigProviders`. While this is a bit easier to understand at the beginning (the app has only one “config”), it makes it harder work on a project with a bigger team and more complex deployment strategies.

So, what’s your way of handling credentials between different environments? Is anyone here using environment variables to store this configuration? How exactly?

---

<div class="post-metadata">

**Author:** ![ocramius](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ocramius/32/23_2.png) [@ocramius](https://discourse.laminas.dev/u/ocramius)\
**Post date:** [May 20, 2018, 9:11pm UTC](https://discourse.laminas.dev/t/handling-environment-specific-configuration-in-zend-expressive-apps/594/2 "2018-05-20T21:11:18Z")

</div>

I do use environment variables, and I have a `GetEnv()` class (functional interface via `__invoke()`) that asserts that the environment variable is successfully retrieved via `\getenv()`.

You can simply use it in any of the configuration files, since the configuration files are just PHP files.

`.env` loading is something I leave to `docker-compose`.

---

<div class="post-metadata">

**Author:** ![matthew](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/matthew/32/14_2.png) [@matthew](https://discourse.laminas.dev/u/matthew)\
**Post date:** [May 21, 2018, 3:09pm UTC](https://discourse.laminas.dev/t/handling-environment-specific-configuration-in-zend-expressive-apps/594/3 "2018-05-21T15:09:10Z")

</div>

I’m doing similar to @ocramius — using `getenv()` or a wrapper directly in my `*.global.php` files, and then defining the env variables in my docker configuration or AWS configuration.

---

<div class="post-metadata">

**Author:** ![shadowhand](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/shadowhand/32/104_2.png) [@shadowhand](https://discourse.laminas.dev/u/shadowhand)\
**Post date:** [May 27, 2018, 1:40pm UTC](https://discourse.laminas.dev/t/handling-environment-specific-configuration-in-zend-expressive-apps/594/4 "2018-05-27T13:40:05Z")

</div>

Ditto to what @ocramius and @matthew said. We have plain PHP configuration files that use `getenv()` to grab sensitive values. Provisioning ENV variables is left to the devops team.
