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.

1 Answer 1


Craft doesn't need an .env file. Using an .env file with the phpdotenv library is just a recommendation included in the project template for convenience. Craft just uses $_SERVER and getenv 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:

// -- config/general.php --
'cpTrigger' => craft\helpers\App::env('CP_TRIGGER') ?: 'admin',

In Craft 4.x, appropriately named environment variables are used automatically, so all you would need is an environment variable like: CRAFT_CP_TRIGGER=admin

  • 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.
    – Tim Kelty
    Jun 23, 2022 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.