For a Yii 1 web application, I am using the symfony/dotenv
library to read and load environment variables from a .env file. To do this, I added a code in the index.php file,
require 'vendor/autoload.php'; //autoload for composer
if(file_exists('/path/to/.env')){
$dotenv = new Symfony\Component\Dotenv\Dotenv();
$dotenv->load(__DIR__.'/path/to/.env');
}
else{
// Missing .env file
exit;
}
This works well with the web application. However, for Yii console applications, this does not work because index.php is not being loaded. Can this be done inside the console.php file? How?