HOST=localhost
symfony/dotenv library
- Add
symfony/dotenv
library tocomposer.json
file:
"require": {
"symfony/dotenv": "^5.0"
}
- Install library from the command line:
composer install
- Load environment variables from
.env
file:
<?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