Answers.Body: <p>Craft doesn't need an <code>.env</code> file. Using an <code>.env</code> file with the <a href="https://github.com/vlucas/phpdotenv" rel="nofollow noreferrer">phpdotenv library</a> is just a recommendation included in the <a href="https://github.com/craftcms/craft" rel="nofollow noreferrer">project template</a> for convenience. Craft just <a href="https://github.com/craftcms/cms/blob/4.0.5.1/src/helpers/App.php#L74-L96" rel="nofollow noreferrer">uses <code>$_SERVER</code> and <code>getenv</code></a> to access environment variables – it doesn't care whether they're set in the environment directly or if they came from the <code>.env</code> file using the phpdotenv library.</p>
  <p>Make sure your environment variables are getting set in the container that includes your Craft installation, so they're available to the PHP process. Then your deployment should work without problems.</p>
  <blockquote>
  <p>I've also tried deploying an empty .env file to the container, or an .env file that contains a single, common setting (CP_TRIGGER=admin).</p>
  </blockquote>
  <p>This won't do anything unless you also use the phpdotenv library to parse the <code>.env</code> file.</p>
  <p>In Craft 3.x you'll <em>also</em> need to reference that environment variable in your <code>config/general.php</code> as in the example <a href="https://craftcms.com/docs/3.x/config/#config-files" rel="nofollow noreferrer">provided in the documentation</a>:</p>
  <pre class="lang-php prettyprint-override"><code>// -- config/general.php --
  'cpTrigger' =&gt; craft\helpers\App::env('CP_TRIGGER') ?: 'admin',
  </code></pre>
  <p>In Craft 4.x, appropriately named environment variables are <a href="https://craftcms.com/docs/4.x/config/#config-environment-variables" rel="nofollow noreferrer">used automatically</a>, so all you would need is an environment variable like: <code>CRAFT_CP_TRIGGER=admin</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-23T13:41:18.683Z
Answers.Text: It is also worth mentioning that `.env` files ideally shouldn't be used in production environments at all, because of the performance cost of reading an additional file on every request.
Answers.UserDisplayName: Tim Kelty
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-23T09:06:36.040Z
Answers.LastActivityDate: 2022-06-23T14:25:37.223Z
Answers.LastEditDate: 2022-06-23T14:25:37.223Z
Answers.UserDisplayName: MoritzLost
Body: <p>In trying to set up a CI/CD process to containerize Craft 3 and deploy to Azure App Service, I succeed in building a container that runs Craft, however, each time the container gets redeployed, I either have to run <code>php craft setup</code> or the GUI setup again.</p>
  <p>To avoid this, I've already set environment variables for the database connections, etc. in the App Service's configuration. I've also tried deploying an empty .env file to the container, or an .env file that contains a single, common setting (<code>CP_TRIGGER=admin</code>). In both cases, that does not make a difference.</p>
  <p>What is the way to get Craft to run in a new environment without requiring a .env file?</p>
  <p>The container is built in a multi-stage process, using composer:latest to create a Craft project and then craftcms-nginx:8.1 for the actual container that's deployed.</p>
  
Tags: <install><deployment>
Title: Run Craft CMS 3 (or 4) without a .env file?
ThreadText: # Run Craft CMS 3 (or 4) without a .env file?
  
  (Asked by: username_0 on 2022-06-23)
  
  In trying to set up a CI/CD process to containerize Craft 3 and deploy to Azure App Service, I succeed in building a container that runs Craft, however, each time the container gets redeployed, I either have to run `php craft setup` or the GUI setup again.
  
  To avoid this, I've already set environment variables for the database connections, etc. in the App Service's configuration. I've also tried deploying an empty .env file to the container, or an .env file that contains a single, common setting (`CP_TRIGGER=admin`). In both cases, that does not make a difference.
  
  What is the way to get Craft to run in a new environment without requiring a .env file?
  
  The container is built in a multi-stage process, using composer:latest to create a Craft project and then craftcms-nginx:8.1 for the actual container that's deployed.
  
  **Tags:** install, deployment
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-06-23. Score: 1
  
  Craft doesn't need an `.env` file. Using an `.env` file with the [phpdotenv library](https://github.com/vlucas/phpdotenv) is just a recommendation included in the [project template](https://github.com/craftcms/craft) for convenience. Craft just [uses `$_SERVER` and `getenv`](https://github.com/craftcms/cms/blob/4.0.5.1/src/helpers/App.php#L74-L96) to access environment variables – it doesn't care whether they're set in the environment directly or if they came from the `.env` file using the phpdotenv library.
  
  Make sure your environment variables are getting set in the container that includes your Craft installation, so they're available to the PHP process. Then your deployment should work without problems.
  
  > I've also tried deploying an empty .env file to the container, or an .env file that contains a single, common setting (CP\_TRIGGER=admin).
  
  This won't do anything unless you also use the phpdotenv library to parse the `.env` file.
  
  In Craft 3.x you'll *also* need to reference that environment variable in your `config/general.php` as in the example [provided in the documentation](https://craftcms.com/docs/3.x/config/#config-files):
  
  ```php
  // -- config/general.php --
  'cpTrigger' => craft\helpers\App::env('CP_TRIGGER') ?: 'admin',
  
  ```
  
  In Craft 4.x, appropriately named environment variables are [used automatically](https://craftcms.com/docs/4.x/config/#config-environment-variables), so all you would need is an environment variable like: `CRAFT_CP_TRIGGER=admin`
  
  > **Comments:**
  > **username_2**: It is also worth mentioning that `.env` files ideally shouldn't be used in production environments at all, because of the performance cost of reading an additional file on every request.  
  
  ---
  
  