I have a small console command where I'd like to read some environment variables, but it does not seem to read the vars from the .env
file or the server configs in the console (php file works)
The code
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$debug = $input->getArgument('debug') === 'y' ? true : false;
$this->project = $input->getArgument('project');
$start = new DateTime();
$debug ? $io->text('<fg=green>Starting upload</>') : null;
dump(getenv('APP_ENV'));
dump(getenv('MAILER_USERNAME'));
die;
...
}
Commands to test
php bin/console app:make-backup
Output:
Starting upload
false
false
php bin/console app:make-backup --env=prod
Output:
Starting upload
"prod"
false
php bin/console app:make-backup --env=dev
Output:
Starting upload
"dev"
false
.env File
APP_ENV=dev
MAILER_USERNAME=info@xxx.com
I don't see where I am doing wrong? Issue exists on nginx and apache server, BUT using getenv('MAILER_USERNAME')
in any php-file works.