Symfony 4 – .env is not working on production

  dotenv, environment-variables, php, symfony, ubuntu

I have a Symfony 4 project that is deployed to the Digital Ocean Ubuntu server.
In order to use some services like stripe and Amazon S3 bucket, I uploaded the .env file with the necessary keys to the server.
I am using bitbucket pipeline and capistrano to deploy the website to the server.

The problem is that the project is not getting the environment variables on the server.
It’s just working well on my local environment when I run composer run serve. On the server, I build the project and uses nginx to host it. Then it’s giving errors like AWS credentials not set or stripe keys are not set.

I’ve installed Symfony/Dotenv and also have configured the config/bootstrap.php file to load .env file both on dev/production environments.

Does anyone have an idea of why this happens?

Source: Symfony Questions