1. Go to this page and download the library: Download phpdot/env 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/ */
use PHPdot\Env\Env;
// Once, at the top of your bootstrap
Env::init(
schema: __DIR__ . '/env.schema.php',
paths: __DIR__ . '/.env',
);
// Anywhere in your app — pure array lookup
env('APP_PORT'); // int(8080)
env('APP_DEBUG', false); // bool — default returned if key missing or no Env initialized
env('APP_ENV'); // AppEnv::PRODUCTION
use PHPdot\Env\EnvEditor;
use PHPdot\Env\Schema\EnvSchema;
use PHPdot\Env\Enum\AppEnv;
$editor = new EnvEditor(__DIR__ . '/.env', new EnvSchema($schema));
$editor->set('DB_HOST', 'new-host.example.com');
$editor->set('APP_ENV', AppEnv::STAGING);
$editor->remove('LOG_LEVEL');
$editor->save();