symfony/dotenv
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Symfony's dotenv component acts as a comprehensive solution for managing and registering environment variables from a .env file into your PHP application. The goal of Symfony dotenv is to parse .env
files and make the environment variables within these files accessible through either $_SERVER
or $_ENV
.
Symfony's dotenv component is conveniently easy to use. Initiate by installing it through Composer using the command:
$ composer require symfony/dotenv
Once installed, you can load environment variables from your .env file with a block of PHP code that might look something like this:
use Symfony\Component\Dotenv\Dotenv;
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/.env');
Symfony's dotenv supports the loading of multiple .env files:
$dotenv->load(__DIR__.'/.env', __DIR__.'/.env.dev');
Overwriting already existing environment variables can be performed with the overload()
method:
$dotenv->overload(__DIR__.'/.env');
Additionally, you can also load .env
, .env.local
, and .env.$APP_ENV.local or .env.$APP_ENV
using the loadEnv()
method:
$dotenv->loadEnv(__DIR__.'/.env');
It's crucial to remember to replace __DIR__.'/.env'
with the actual path to your .env file.
The comprehensive documentation for Symfony's dotenv component is located in Symfony's main repository. For contributions, you can refer to Contributing, to report issues, you can visit Report issues and to send pull requests, navigate to send Pull Requests. All these resources are available in the main Symfony repository.