PHP getenv always returns false

  environment-variables, php, symfony

The getenv() always returns false. I am using Symfony dotenv library and loading my variables from a .env file in the root of my project.

use SymfonyComponentDotenvDotenv;
use SymfonyComponentDotenvExceptionPathException;

if (!getenv('APP_ENV')) {
    try {
        (new Dotenv())->load(__DIR__ . '/../.env');
    } catch (PathException $ex) {
        echo $ex->getMessage();
        exit(1);
    }
}

var_dump(getenv('APP_ENV')); // bool(false)

But when I dump the super global I can see my variables

var_dump($_ENV); // array:1["APP_ENV" => "dev"]

So what am I missing?

Source: Symfony Questions

One Reply to “PHP getenv always returns false”

LEAVE A COMMENT