PHP code example of envs / dotenv

1. Go to this page and download the library: Download envs/dotenv library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

envs / dotenv example snippets


use Dotenv\Dotenv;

$dotenv = Dotenv::process(__DIR__);
$dotenv->load();

$dotenv = Dotenv::process(__DIR__);
$dotenv->safeLoad();

$dotenv = Dotenv::process(__DIR__, 'myconfig.env');
$dotenv->load();

$dotenv = Dotenv::process(__DIR__, ['.env.local', '.env.example', '.env'], false);
$dotenv->load();

$s3_bucket = $_ENV['S3_BUCKET'];
$s3_bucket = $_SERVER['S3_BUCKET'];

BASE_DIR="/var/webroot/project-root"
CACHE_DIR="${BASE_DIR}/cache"
TMP_DIR="${BASE_DIR}/tmp"

$dotenv->

$dotenv->