Skip to main content
Environment variables control your application’s behavior across different environments. All variables are defined in the .env file at the root of your project.

Getting Started

Copy the example environment file to create your own:
cp .env.example .env
Then generate an application key:
php artisan key:generate

Environment Variables

APP_NAME

Default: LaravelThe name of your application. Used in email notifications and other user-facing messages.
APP_NAME=Laravel

APP_ENV

Default: localThe application environment. Common values:
  • local - Development environment
  • staging - Staging environment
  • production - Production environment
APP_ENV=local
Always set APP_ENV=production in production to disable debugging features.

APP_KEY

Default: Empty (must be generated)The application encryption key. This is used for encrypting session data, cookies, and other sensitive information.
APP_KEY=
Generate this key using php artisan key:generate during setup.

APP_DEBUG

Default: trueEnables or disables debug mode. When enabled, detailed error messages are displayed.
APP_DEBUG=true
Always set APP_DEBUG=false in production to prevent sensitive information disclosure.

APP_URL

Default: http://localhostThe base URL of your application. Used for generating links and URLs.
APP_URL=http://localhost

APP_LOCALE

Default: enThe default locale for your application.
APP_LOCALE=en

APP_FALLBACK_LOCALE

Default: enThe fallback locale when a translation is not available in the current locale.
APP_FALLBACK_LOCALE=en

APP_FAKER_LOCALE

Default: en_USThe locale used by Faker for generating fake data in tests and seeders.
APP_FAKER_LOCALE=en_US

APP_MAINTENANCE_DRIVER

Default: fileThe driver for storing maintenance mode state. Options: file, cache.
APP_MAINTENANCE_DRIVER=file
# APP_MAINTENANCE_STORE=database

BCRYPT_ROUNDS

Default: 12The number of rounds to use for bcrypt hashing. Higher values increase security but require more processing time.
BCRYPT_ROUNDS=12

DB_CONNECTION

Default: sqliteThe default database connection. Supported values: sqlite, mysql, mariadb, pgsql, sqlsrv.
DB_CONNECTION=sqlite
The default SQLite connection works out of the box without additional configuration.

MySQL/PostgreSQL Configuration

These variables are commented out by default when using SQLite. Uncomment and configure them when switching to MySQL or PostgreSQL:
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=
DB_HOST: Database server hostname or IP addressDB_PORT: Database server port (3306 for MySQL, 5432 for PostgreSQL)DB_DATABASE: Database nameDB_USERNAME: Database usernameDB_PASSWORD: Database password

CACHE_STORE

Default: databaseThe cache driver to use. Options: database, file, memcached, redis, array.
CACHE_STORE=database

CACHE_PREFIX

Default: EmptyA prefix for cache keys to avoid collisions with other applications.
# CACHE_PREFIX=

SESSION_DRIVER

Default: databaseThe session storage driver. Options: file, cookie, database, memcached, redis, array.
SESSION_DRIVER=database

SESSION_LIFETIME

Default: 120Session lifetime in minutes.
SESSION_LIFETIME=120

SESSION_ENCRYPT

Default: falseWhether to encrypt session data.
SESSION_ENCRYPT=false

SESSION_PATH

Default: /The session cookie path.
SESSION_PATH=/

SESSION_DOMAIN

Default: nullThe session cookie domain.
SESSION_DOMAIN=null

QUEUE_CONNECTION

Default: databaseThe queue driver to use. Options: sync, database, redis, sqs, beanstalkd.
QUEUE_CONNECTION=database
Use sync for local development to process jobs immediately. Use database or redis for production.

LOG_CHANNEL

Default: stackThe default log channel. Options: stack, single, daily, slack, syslog, errorlog.
LOG_CHANNEL=stack

LOG_STACK

Default: singleThe channels to include when using the stack channel.
LOG_STACK=single

LOG_DEPRECATIONS_CHANNEL

Default: nullThe channel for deprecation warnings.
LOG_DEPRECATIONS_CHANNEL=null

LOG_LEVEL

Default: debugThe minimum log level. Options: debug, info, notice, warning, error, critical, alert, emergency.
LOG_LEVEL=debug

MAIL_MAILER

Default: logThe mail driver to use. Options: smtp, sendmail, mailgun, ses, postmark, log, array.
MAIL_MAILER=log
The log driver writes emails to the log file instead of sending them. Perfect for local development.

MAIL_HOST

Default: 127.0.0.1The SMTP server hostname.
MAIL_HOST=127.0.0.1

MAIL_PORT

Default: 2525The SMTP server port.
MAIL_PORT=2525

MAIL_USERNAME

Default: nullThe SMTP username for authentication.
MAIL_USERNAME=null

MAIL_PASSWORD

Default: nullThe SMTP password for authentication.
MAIL_PASSWORD=null

MAIL_ENCRYPTION

Default: Not setThe encryption method. Options: tls, ssl, or leave empty for no encryption.

MAIL_FROM_ADDRESS

Default: [email protected]The default sender email address.
MAIL_FROM_ADDRESS="[email protected]"

MAIL_FROM_NAME

Default: ${APP_NAME}The default sender name. Uses the APP_NAME value by default.
MAIL_FROM_NAME="${APP_NAME}"

REDIS_CLIENT

Default: phpredisThe Redis client to use. Options: phpredis, predis.
REDIS_CLIENT=phpredis

REDIS_HOST

Default: 127.0.0.1The Redis server hostname.
REDIS_HOST=127.0.0.1

REDIS_PASSWORD

Default: nullThe Redis server password.
REDIS_PASSWORD=null

REDIS_PORT

Default: 6379The Redis server port.
REDIS_PORT=6379

BROADCAST_CONNECTION

Default: logThe broadcast driver. Options: pusher, redis, log, null.
BROADCAST_CONNECTION=log

FILESYSTEM_DISK

Default: localThe default filesystem disk. Options: local, public, s3, ftp.
FILESYSTEM_DISK=local
Used for S3 file storage, SES email, and other AWS services.
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
AWS_ACCESS_KEY_ID: Your AWS access keyAWS_SECRET_ACCESS_KEY: Your AWS secret keyAWS_DEFAULT_REGION: AWS region (e.g., us-east-1, eu-west-1)AWS_BUCKET: S3 bucket nameAWS_USE_PATH_STYLE_ENDPOINT: Use path-style endpoint for S3 (for MinIO compatibility)

PHP_CLI_SERVER_WORKERS

Default: Commented outThe number of workers for the PHP built-in server.
# PHP_CLI_SERVER_WORKERS=4

VITE_APP_NAME

Default: ${APP_NAME}Makes the app name available to Vite for frontend builds.
VITE_APP_NAME="${APP_NAME}"

Environment-Specific Configuration

APP_NAME=Laravel
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost

DB_CONNECTION=sqlite

MAIL_MAILER=log
QUEUE_CONNECTION=sync

Security Best Practices

Never commit your .env file to version control. It contains sensitive credentials and should remain private.
  1. Always generate a unique APP_KEY for each environment
  2. Set APP_DEBUG=false in production
  3. Set APP_ENV=production in production
  4. Use strong database passwords
  5. Keep your .env file permissions restricted (readable only by the application user)
  6. Use environment-specific values for sensitive data
  7. Consider using a secrets management service for production environments

Accessing Environment Variables

In your code, access environment variables using the env() helper:
$appName = env('APP_NAME', 'Laravel');
$debug = env('APP_DEBUG', false);
The second parameter is the default value if the environment variable is not set.

Build docs developers (and LLMs) love