.env
HOST=localhost
symfony/dotenv library
- Add
symfony/dotenvlibrary tocomposer.jsonfile:
"require": {
"symfony/dotenv": "^5.0"
}
- Install library from the command line:
composer install
- Load environment variables from
.envfile:
<?php
use Symfony\Component\Dotenv\Dotenv;
require_once __DIR__.'/vendor/autoload.php';
$path = __DIR__.'/.env';
$dotenv = new Dotenv();
$dotenv->load($path);
$envVar = $_ENV['HOST'];
echo $envVar; // localhost
Leave a Comment
Cancel reply