DotEnvDumpBundle
The DotEnvDumpBundle
parses.env
files via DotEnv and export environment variables in .htaccess
(SetEnv directive) or .php
(return array) formats., (*1)
The main purpose of this bundle to use it as a part of a deploy process for a shared hosting where you can't edit environment variables., (*2)
During development, you'll use the .env
file to configure your environment variables. On your production server, it is recommended to configure these at the web server level., (*3)
So if you're using Apache, you can pass these variables via SetEnv directive in .htaccess
file., (*4)
Or you can just cache them into .env.php
file and replace in your front controller (index.php):, (*5)
(new Dotenv())->load(__DIR__.'/../.env');
with something like, (*6)
if (file_exists(__DIR__.'/../.env.php')) {
$variables = require_once __DIR__.'/../.env.php';
(new Dotenv())->populate($variables);
}
Usage
bin/console dotenv:dump [--htaccess] [--php] [path-to-output-file] [path-to-env-file]
Invoked with no parameters will export to .htaccess
in the %kernel.project_dir%
., (*7)
It's a safe to invoke command few times in a row., (*8)
Example
bin/console dotenv:dump --htaccess .htaccess
will prepend (or replace if already exists) in the .htaccess
following content:, (*9)
###> .env ###
SetEnv "APP_ENV" "dev"
SetEnv "APP_SECRET" "6d15395b9c94f12f97fa31edc9c0c6f0"
###< .env ###
bin/console dotenv:dump --php .env.php
will rewrite .env.php
file with the following content:, (*10)
<?php return array (
'APP_ENV' => 'dev',
'APP_SECRET' => '6d15395b9c94f12f97fa31edc9c0c6f0',
);
Installation
Applications that use Symfony Flex, (*11)
Open a command console, enter your project directory and execute:, (*12)
$ composer require kimbee-team/dotenv-dump
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the
following command to download the latest stable version of this bundle:, (*13)
$ composer require kimbee-team/dotenv-dump
This command requires you to have Composer installed globally, as explained
in the installation chapter
of the Composer documentation., (*14)
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:, (*15)
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new \KimbeeTeam\DotenvDump\KimbeeTeamDotenvDumpBundle(),
);
// ...
}
// ...
}
License
This bundle is released under the MIT license, (*16)