prooxxy/magento2-dotenv

Adds support for .env files to Magento 2

Installs: 3 440

Dependents: 0

Suggesters: 0

Security: 0

Stars: 9

Watchers: 1

Forks: 0

Open Issues: 0

Type:magento2-module

1.3.0 2020-07-02 18:24 UTC

This package is auto-updated.

Last update: 2024-04-07 03:17:20 UTC


README

Adds support for .env configuration files to Magento 2.

This module was created because Magento recommends injection of variables into $_ENV through the index.php file. I believe that is a stupid suggestion.

Installation

Use composer to install this.

composer require prooxxy/magento2-dotenv

Alternative installation

If you don't have the option to use composer it's possible to copy the root of this project into the app/code/PrOOxxy/DotEnv folder of your magento installation

Make sure the module is enable before start using

php bin/magento module:enable PrOOxxy_DotEnv
php bin/magento setup:upgrade

Features

This module does only one thing once installed. It reads and parses any variables that is locate inside <magento_root>/app/etc/.env and injects it into the global $_ENV array

It does this before Magento processes other environments variables. It does override any preexisting variable with the same name.

Usage

  1. Add .env into app/etc The file must have chmod level 0644 or below
  2. Follow the official devdocs instructions for how to create the env variable format
  3. Add your newly formatted variables into the .env like so e.g

CONFIG__DEFAULT__SYSTEM__SMTP__HOST="8.8.8.8"

  1. Flush the config cache
php bin/magento cache:flush config

Compability

Magento 2 Open Source 2.3.x Magento 2 Open Source 2.4.x Magento 2 Commerce 2.3.x Magento 2 Commerce 2.4.x

License

MIT