.env · generator · Laravel

Laravel .env Generator

Laravel reads .env via vlucas/phpdotenv during bootstrap. This generator produces a Laravel 11 compatible file with APP_KEY, MySQL, Redis, queue, and mailer settings.

.env for Laravel · 13 keys
Customize →
APP_NAME=Laravel
APP_ENV=local
APP_KEY=bZl6QxTWJyBQrS5yqSvLAsW_2Shz6TpJg-uPgwCHSl3eWK4y
APP_DEBUG=true
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
REDIS_HOST=127.0.0.1
REDIS_PORT=6379

Secrets regenerate on every page load. Want to combine stacks (e.g., Next.js + Stripe + Supabase)? Use the full generator.

How to use this .env in Laravel

  1. 1.Save as .env in the project root.
  2. 2.Run php artisan key:generate to regenerate APP_KEY (or keep the one below).
  3. 3.For production, run php artisan config:cache — this freezes config at build time.
  4. 4.Only access env() inside config/*.php files — not anywhere else in the app.

Gotchas

  • Calling env() outside config/*.php returns null when config:cache is active.
  • APP_KEY must be exactly 32 bytes. Use php artisan key:generate, never generate manually.
  • Laravel's queue config reads QUEUE_CONNECTION, not QUEUE_DRIVER (pre-9 name).

Common keys explained

APP_KEY

Required. Used for encryption + session cookies.

APP_ENV

local | production | testing. Controls error verbosity.

APP_DEBUG

Never true in production.

DB_CONNECTION

mysql | pgsql | sqlite.

REDIS_HOST

Redis for cache + sessions + queues.

MAIL_MAILER

smtp | mailgun | ses | log. log is great for dev.

Related tools

Other stacks