-
-
Notifications
You must be signed in to change notification settings - Fork 23
Environments management #1
Comments
I'd use https://github.com/vlucas/phpdotenv for handling it. |
Usage example:
Please do not name the ENV file |
Personally I put gitignored |
I prefix variable names with project ID such as |
Technically this would make no problems, but... My point regarding a name different from Actually, while I wanted to link to https://github.com/direnv/direnv - as an example for another usage. What I actually wanna say is, that there should be a "env" file for your "control environment" in the top level, which might contain variables like The file ( TL;dr
|
We do that for newly introduced variables, the ones from the template are prefixed with
( |
I'm doing so because I'm running multiple projects at the same server w/o any containers. |
But all your projects share the credentials of all the other projects via ENV variables then? |
Almost. I'm still using |
Exclude environment variables from logging: https://github.com/dmstr/phd5-app/blob/master/src/config/common.php#L132-L142 |
Config must be diferrent formats: yml, php, ini etc. Env it's only ini. For small projects env is most suitable but not middle and big projects Config generator should be independed component |
.env isn't going to replace regular configs. It's a source of values that were, in case of advanced app, stored in |
Another implementation: https://github.com/symfony/dotenv |
@samdark how can i configure different log targets for different environments with env? |
Variant 1:$loggerConfig = [
'traceLevel' => getenv('LOG_TRACE_LEVEL'),
'targets' => [],
];
if (getenv('LOG_ENABLE_FILE_TARGET')) {
$loggerConfig['targets'][] = [
'class' => 'yii\log\FileTarget',
// ...
];
}
return $loggerConfig; Variant 2:'components' => [
'log' => [
'targets' => getenv('IS_PRODUCTION') ? require 'production.log.php' : require 'development.log.php';
]
] Variant 3:Use |
And i need to use local config php files :) Why .env? |
Ok, second popular task. How can i configure local queue driver? Again use local php files. |
.env as file is for development purposes mainly. In production you'd use containers or set variables via nginx config or something like that. It depends very much on the toolset used but environment variables are quite common. See https://12factor.net/config |
I prefer as a more flexible dotenv: https://github.com/josegonzalez/php-dotenv |
I think processing and loading configuration is rather complex task. This plugin performs complex process of assembling whole config stack:
Pros of this solution:
Here is how entry script looks when the plugin is used: use hiqdev\composer\config\Builder;
use yii\di\Container;
use yii\helpers\Yii;
(function () {
require_once __DIR__ . '/../vendor/autoload.php';
$container = new Container(require Builder::path('web'));
Yii::setContainer($container);
$container->get('app')->run();
})(); Single line
You can read more about use of the composer-config-plugin at it's README. So, "environments management" is implemented. Closing this issue. |
The text was updated successfully, but these errors were encountered: