Answers.Body: <p>These are the two approaches I usually choose from:</p>
  
  <h3>Option 1: the 'default' Craft 3 way</h3>
  
  <ul>
  <li>Create a .env file for every environment you create, and add it to your .gitignore file (if it's not yet in it). In this file, you put all environment-specific details;</li>
  <li>Craft, by default, will recognize and use those details.</li>
  <li>In your Craft config files, you can use the ENVIRONMENT as defined in your .env file to adjust the settings for one specific environment. So, the config that applies all the time is set in an array with the key '*', and the config that's specifically for the <code>dev</code> environment, is in the array that has the 'dev' key (If you use the <a href="https://github.com/craftcms/craft/blob/master/config/general.php" rel="noreferrer">default general config file</a>)</li>
  </ul>
  
  <h3>Option 2: <a href="https://github.com/nystudio107/craft-multi-environment" rel="noreferrer">the .env.php way</a></h3>
  
  <p>One of the reasons this approach exists, is that the makers of PHP dotenv (used in option 1) 'warn against using it in production' (as quoted from the README of option 2). The method as linked in the title uses a PHP file and some minor alterations to your config and index files to let you maintain a multi environment build.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-13T13:29:45.920Z
Answers.Text: The makers of phpdotenv (the lib Craft 3 uses to load .env files) warn against using it in production because of the overhead it adds to load the file on every request. It’s debatable if the “.env.php way” improves this situation in a measurable dimension. If you are really that much worried about performance in this order of magnitude (fractions of 1ms), you should better stick to `getenv()` and set the env variables on production servers via the server configuration files.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-13T12:46:43.580Z
Answers.LastActivityDate: 2018-04-13T12:53:10.603Z
Answers.LastEditDate: 2018-04-13T12:53:10.603Z
Answers.UserDisplayName: Paul
Body: <p>How do I take advantage of the new .env files? I want to setup a local and production environment in Craft 3.</p>
  
  <p>Anyone know how to do this or know of any docs out there explaining it ?</p>
  
Tags: <craft3><multi-environment><environmentvariables>
Title: How to set up multi-env in Craft 3 with .env files?
ThreadText: # How to set up multi-env in Craft 3 with .env files?
  
  (Asked by: username_0 on 2018-04-13)
  
  How do I take advantage of the new .env files? I want to setup a local and production environment in Craft 3.
  
  Anyone know how to do this or know of any docs out there explaining it ?
  
  **Tags:** craft3, multi-environment, environmentvariables
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-13. Score: 9 | Accepted answer
  
  These are the two approaches I usually choose from:
  
  ### Option 1: the 'default' Craft 3 way
  
  * Create a .env file for every environment you create, and add it to your .gitignore file (if it's not yet in it). In this file, you put all environment-specific details;
  * Craft, by default, will recognize and use those details.
  * In your Craft config files, you can use the ENVIRONMENT as defined in your .env file to adjust the settings for one specific environment. So, the config that applies all the time is set in an array with the key '\*', and the config that's specifically for the `dev` environment, is in the array that has the 'dev' key (If you use the [default general config file](https://github.com/craftcms/craft/blob/master/config/general.php))
  
  ### Option 2: [the .env.php way](https://github.com/nystudio107/craft-multi-environment)
  
  One of the reasons this approach exists, is that the makers of PHP dotenv (used in option 1) 'warn against using it in production' (as quoted from the README of option 2). The method as linked in the title uses a PHP file and some minor alterations to your config and index files to let you maintain a multi environment build.
  
  > **Comments:**
  > **username_2**: The makers of phpdotenv (the lib Craft 3 uses to load .env files) warn against using it in production because of the overhead it adds to load the file on every request. It’s debatable if the “.env.php way” improves this situation in a measurable dimension. If you are really that much worried about performance in this order of magnitude (fractions of 1ms), you should better stick to `getenv()` and set the env variables on production servers via the server configuration files.  
  
  ---
  
  