lirien/env

A minimal and straightforward .env file loader for PHP

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 0

Forks: 0

Open Issues: 1

pkg:composer/lirien/env

1.0.1 2025-12-09 15:05 UTC

This package is auto-updated.

Last update: 2026-01-09 15:22:19 UTC


README

Latest Version PHP Version Total Downloads License

A minimal and straightforward .env file loader for PHP 8.1+.

Ideal for small to medium-sized projects that need simple environment variable loading without additional dependencies.

Installation

composer require lirien/env

Usage

use Lirien\Support\Env;

// Load the .env file (typically at application bootstrap)
Env::load(__DIR__ . '/../.env');

// Retrieve a variable
$appName = Env::get('APP_NAME');

// Set a variable at runtime (e.g. in tests)
Env::set('APP_ENV', 'testing');

Example .env

APP_NAME=Lirien
APP_ENV=local
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=myapp
DB_USERNAME=root
DB_PASSWORD=secret

# Comments and empty lines are ignored
REDIS_HOST=127.0.0.1

Methods

  • Env::load(string $path) - Loads variables from the specified .env file

  • Env::get(string $key): string - Returns the environment variable value

  • Env::set(string $key, string value): void - Sets or overrides a variable at runtime

Tip: Always provide a default value when using Env::get() if the variable might not exist.

Security & Best Practices

  • Never commit your .env file — it must stay out of version control

  • Store the .env file outside the public web root

  • Validate and sanitize values loaded from the environment

  • Use Env::set() for tests or runtime overrides, not for permanent configuration

License

This project is licensed under the MIT License. See the LICENSE file for details.