kimbee-team/dotenv-dump

Dumps environment variables from `.env` to `.htaccess` or plain PHP-file.

Installs: 166

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.0.0 2018-07-15 17:08 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:48:31 UTC


README

The DotEnvDumpBundle parses.env files via DotEnv and export environment variables in .htaccess (SetEnv directive) or .php (return array) formats.

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.

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.

So if you're using Apache, you can pass these variables via SetEnv directive in .htaccess file.

Or you can just cache them into .env.php file and replace in your front controller (index.php):

(new Dotenv())->load(__DIR__.'/../.env');

with something like

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%.

It's a safe to invoke command few times in a row.

Example

bin/console dotenv:dump --htaccess .htaccess will prepend (or replace if already exists) in the .htaccess following content:

###> .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:

<?php return array (
  'APP_ENV' => 'dev',
  'APP_SECRET' => '6d15395b9c94f12f97fa31edc9c0c6f0',
);

Installation

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

$ 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:

$ 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.

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:

<?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