Reputation: 2006
Differnt to my local dev environmet my prod (Debian, Nginx, PHP 7.1.22) environment is not loading the .env config file.
I always get the Symfony error: Environment variable not found
.
Upvotes: 1
Views: 4917
Reputation: 2006
Just want to mention the solution to the problem which I couldn't find in the web.
Finally I checked the index.php file were the .env is initially loaded and found the following lines:
if (!isset($_SERVER['APP_ENV'])) {
if (!class_exists(Dotenv::class)) {
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
}
(new Dotenv())->load(__DIR__.'/../.env');
}
Means that if the env var APP_ENV
is already set in the web server config the .env will not be loaded.
So I checked also my nginx config for my website and removed the fpm env config line fastcgi_param APP_ENV "prod";
Now it works.
Hope this helps you, too ;)
Upvotes: 8