{"__v":0,"_id":"5777c96e5b2b430e00b982c9","category":{"version":"5777c9635b2b430e00b982a5","project":"54348ec95b10711400c6c445","_id":"5777c9635b2b430e00b982aa","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-12-03T21:36:49.014Z","from_sync":false,"order":4,"slug":"bonus-guides","title":"Bonus Guides"},"parentDoc":null,"project":"54348ec95b10711400c6c445","user":"5435e00ad7d8700800bbec51","version":{"__v":1,"_id":"5777c9635b2b430e00b982a5","project":"54348ec95b10711400c6c445","createdAt":"2016-07-02T14:02:11.084Z","releaseDate":"2016-07-02T14:02:11.084Z","categories":["5777c9635b2b430e00b982a6","5777c9635b2b430e00b982a7","5777c9635b2b430e00b982a8","5777c9635b2b430e00b982a9","5777c9635b2b430e00b982aa"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.2.0","version":"1.2.0"},"updates":["548c836f111b960b006f5311","5491c5a112d0c00b00c80cf3","54a500c14ebd6e0b0096c6e2","56924c7072d4580d0081e935","56939be45f1c951900644b18"],"next":{"pages":[],"description":""},"createdAt":"2014-12-03T22:12:57.952Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"never","params":[],"url":""},"isReference":false,"order":11,"body":"Since our Phoenix apps are simply Elixir applications, they  have the same configuration and structure as other Mix projects. Recall that Mix is the build tool used by most Elixir apps.\n\n#### .ex and .exs Files Types\n\nThe config for our Phoenix app is stored in a combination of `.ex` and `.exs` files. Although both file types are Elixir scripts, they are compiled differently.\n\nOur `.exs` files are compiled in memory each time they are run (such as on reload), which makes them ideal for storing configuration details and scripts that change often (such as standalone tasks during development).\n\nWhereas `.ex` files are compiled to `.beam` files that run on the Erlang Virtual Machine (BEAM), which makes them useful for storing higher level configuration that changes less frequently (such as endpoint and OTP supervisor/worker config). \n\n\n#### Config Files and Environments\n\nOur `mix.exs` config file is located in the root folder of our app and contains some important overall config details relating to our app, including compilation paths, dependencies and aliases.\n\nPhoenix applications are intended to be run with configuration particular to different environments, such as 'development' or 'production'. This allows for an improved developer experience and smoother workflow when deploying apps to production. By default, the `/config` folder at the root of our app will include the following config files:\n\n`config.exs`, which is our master config file that is common across all our environments. It contains overall app config such as our logging and endpoint details, such as our app url and root directory. Additionally, towards the bottom of this file, we also take the important step of importing the configuration specific to our current environment.  We can easily switch between the different configuration files for our environments by adjusting the value for the `Mix.env` environment variable below when we start/deploy our app; for instance, we'd set the value to `\"#prod.exs\"` for our production environment.\n\n```elixir\n...\n# Import environment specific config. This must remain at the bottom\n# of this file so it overrides the configuration defined above.\nimport_config \"#{Mix.env}.exs\"\n...\n```\n\n`dev.exs`, which is used to store config details specific to our development environment, such as debugging settings and our database connection details.\n\n`prod.exs`, which is used to store config for our production environment, since these settings often need to be different and more strict than our dev or test environments. For instance, in production we use stronger hashing of passwords, which would slow down performance during development or testing, but is an unavoidable expense for a production app.\n\n`prod.secret.exs`, which is used to store sensitive configuration details relating to our production environment (such as passwords or API keys), and is thus generally excluded from the version control in our code repository.  Note that config details from this file can be imported into our other files as appropriate.\n\n`test.exs`, which is used to store any config details specific to our testing environment.\n\nWe should open each of these files and familiarize ourselves with the contents. \n\nIn addition to these default development (`dev.exs`), test (`test.exs`) and production (`prod.exs`) environment configurations, Phoenix supports the use of custom environment configurations that we can manually add as we get more advanced.\n\n#### Umbrella Apps\n\nUmbrella apps enable multiple child applications to run together, which can help to reduce the overall complexity of our app by separating different functionality into smaller apps that run together. While a full discussion of Umbrella Apps extends beyond the scope of this Guide, for now it's worth simply noting that the configuration of an Umbrella app is slightly different (and in some ways a bit simpler) than what's outlined above, since much of the configuration details will reside in the config for each of the children apps.\n\n#### Summary\n\nConfig is an important topic and essential to every app we build. The important points to take away from this guide are that:\n- Our `.ex` and `.exs` files are used to store the configuration for our app.\n- Our `.exs` files are compiled in memory each time they are run which makes them ideal for storing configuration details.\n- Mix apps include config for development, test and production environments by default, and custom environments can be manually added.\n- We can store our sensitive production config in our `prod.secret.exs` file, outside of version control.","excerpt":"","slug":"configuration","type":"basic","title":"Configuration"}
Since our Phoenix apps are simply Elixir applications, they have the same configuration and structure as other Mix projects. Recall that Mix is the build tool used by most Elixir apps. #### .ex and .exs Files Types The config for our Phoenix app is stored in a combination of `.ex` and `.exs` files. Although both file types are Elixir scripts, they are compiled differently. Our `.exs` files are compiled in memory each time they are run (such as on reload), which makes them ideal for storing configuration details and scripts that change often (such as standalone tasks during development). Whereas `.ex` files are compiled to `.beam` files that run on the Erlang Virtual Machine (BEAM), which makes them useful for storing higher level configuration that changes less frequently (such as endpoint and OTP supervisor/worker config). #### Config Files and Environments Our `mix.exs` config file is located in the root folder of our app and contains some important overall config details relating to our app, including compilation paths, dependencies and aliases. Phoenix applications are intended to be run with configuration particular to different environments, such as 'development' or 'production'. This allows for an improved developer experience and smoother workflow when deploying apps to production. By default, the `/config` folder at the root of our app will include the following config files: `config.exs`, which is our master config file that is common across all our environments. It contains overall app config such as our logging and endpoint details, such as our app url and root directory. Additionally, towards the bottom of this file, we also take the important step of importing the configuration specific to our current environment. We can easily switch between the different configuration files for our environments by adjusting the value for the `Mix.env` environment variable below when we start/deploy our app; for instance, we'd set the value to `"#prod.exs"` for our production environment. ```elixir ... # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. import_config "#{Mix.env}.exs" ... ``` `dev.exs`, which is used to store config details specific to our development environment, such as debugging settings and our database connection details. `prod.exs`, which is used to store config for our production environment, since these settings often need to be different and more strict than our dev or test environments. For instance, in production we use stronger hashing of passwords, which would slow down performance during development or testing, but is an unavoidable expense for a production app. `prod.secret.exs`, which is used to store sensitive configuration details relating to our production environment (such as passwords or API keys), and is thus generally excluded from the version control in our code repository. Note that config details from this file can be imported into our other files as appropriate. `test.exs`, which is used to store any config details specific to our testing environment. We should open each of these files and familiarize ourselves with the contents. In addition to these default development (`dev.exs`), test (`test.exs`) and production (`prod.exs`) environment configurations, Phoenix supports the use of custom environment configurations that we can manually add as we get more advanced. #### Umbrella Apps Umbrella apps enable multiple child applications to run together, which can help to reduce the overall complexity of our app by separating different functionality into smaller apps that run together. While a full discussion of Umbrella Apps extends beyond the scope of this Guide, for now it's worth simply noting that the configuration of an Umbrella app is slightly different (and in some ways a bit simpler) than what's outlined above, since much of the configuration details will reside in the config for each of the children apps. #### Summary Config is an important topic and essential to every app we build. The important points to take away from this guide are that: - Our `.ex` and `.exs` files are used to store the configuration for our app. - Our `.exs` files are compiled in memory each time they are run which makes them ideal for storing configuration details. - Mix apps include config for development, test and production environments by default, and custom environments can be manually added. - We can store our sensitive production config in our `prod.secret.exs` file, outside of version control.