Languages

Envlet for PHP

Client->inject() fills putenv and $_ENV. Laravel, Symfony, and plain PHP read them the way they always did.

Packagistenvlet/envlet

Set up

Three steps. The host keeps one secret and everything else arrives at boot.

  1. 01

    Install

    One Composer package. Laravel, Symfony, and plain PHP.

    Terminal
    composer require envlet/envlet
  2. 02

    Set one secret

    ENVLET_TOKEN in the environment of PHP-FPM, the container, or the CLI.

    PHP / production / environment variables
    ENVLET_TOKENenvlet_••••••••the only secret the host keeps
    DATABASE_URL••••••••moved to Envlet
    STRIPE_KEY••••••••moved to Envlet
    SENTRY_DSN••••••••moved to Envlet
  3. 03

    Inject at boot

    Create a Client and call inject() in your front controller before config loads.

    public/index.php
    use Envlet\Client;
    
    $envlet = new Client();
    $envlet->inject();
    
    $stripe = new StripeClient(getenv("STRIPE_KEY"));

Three calls

inject for most apps. load when you want a map. get when you want one value.

use Envlet\Client;

$envlet = new Client();
$envlet->inject();

$stripe = new StripeClient(getenv("STRIPE_KEY"));

Typed

envlet types writes this file from the variables in your environment, with a load() that fills the shape below. Run it with --check in CI and a renamed variable fails the build.

Terminal
envlet types
envlet types --check
EnvletEnv.php
<?php // Generated by envlet types for the "production" environment.

declare(strict_types=1);

use Envlet\Client;
use Envlet\EnvletException;

final class Env
{
    public function __construct(
        public readonly string $databaseUrl,
        public readonly bool $debug,
        public readonly mixed $flags,
        public readonly string $mode,
        public readonly int $port,
        public readonly string $stripeKey,
    ) {
    }

Questions

Will my app start if Envlet is down?

No. The SDK retries for a few seconds, then fails so you notice. It never starts your app with half an environment.

What does the host need?

One variable, ENVLET_TOKEN. Everything else arrives at boot.

Can I still set some values on the PHP host?

Yes. A value the host already set wins. Pass override if you want Envlet to win instead.

Stop pasting .env files.

One command. The right values for whoever runs it.