Yii2 Support for loading environment variables from DotEnv files using vlucas/phpdotenv. Required PHP >=7.4.
composer require wearesho-team/yii2-dotenv:^1.2
This package includes Bootstrap.
You need to prepend it to application bootstrap list:
<?php
use Wearesho\Yii2\DotEnv;
return [
'id' => 'app',
'bootstrap' => [
DotEnv\Bootstrap::class,
// ... other bootstraps
],
'components' => [
// ... components definitions
],
];
You should set environment variables YII_ENV
and YII_DEBUG
.
It will be used to define Yii2 constants:
YII_ENV
(prod/dev/test), defaultdev
YII_DEBUG
(0/1), default1
(true)
See autoload file constants.php for details.