laravel-stack-env maintained by aaix
Database driver, service hostnames, ports, queue and mail transport are the same for everyone
working on a project — they follow from its stack, not from who checked it out. Put them in a
committed .env.stack and a fresh clone runs without a single manual setting. Nobody's .env
repeats them, .env.example stops listing them, and no config/*.php has to be touched.
Highest wins:
- Real environment variables — container, shell, CI
.env— the developer's own file, not in version control.env.stack— committed, applies to everyone- The
env()fallback inconfig/*.php
Every key is decided on its own: .env overrides exactly the keys it defines and leaves the rest
of .env.stack in place.
Setup
composer require aaix/laravel-stack-env
1. Register the loader in bootstrap/app.php. On the slim skeleton the file returns the
builder expression directly, so assign it first:
$app = Application::configure(basePath: dirname(__DIR__))
// ...
->create();
$app->singleton(
\Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables::class,
\Aaix\LaravelStackEnv\LoadEnvironmentVariables::class,
);
return $app;
On the classic skeleton $app already exists — put the same singleton() call next to the other
bindings, above return $app;.
2. Create .env.stack in the project root and commit it. Make sure .gitignore does not
swallow it: a .env* pattern would, and the layer only reaches your colleagues and CI once the
file is in the repository.
DB_CONNECTION=mysql
DB_HOST=mysql
REDIS_HOST=redis
QUEUE_CONNECTION=redis
That is the whole integration. Check it with php artisan config:show database.
License
MIT.