.env
.env.*
!.env.example
.env
.env.*
!.env.example
.env
.env.*
!.env.example
// Wrong - will break with config caching
$apiKey = env('THIRD_PARTY_API_KEY'); // Right - works with config caching
// In config/services.php:
'third_party' => [ 'api_key' => env('THIRD_PARTY_API_KEY'),
], // In your code:
$apiKey = config('services.third_party.api_key');
// Wrong - will break with config caching
$apiKey = env('THIRD_PARTY_API_KEY'); // Right - works with config caching
// In config/services.php:
'third_party' => [ 'api_key' => env('THIRD_PARTY_API_KEY'),
], // In your code:
$apiKey = config('services.third_party.api_key');
// Wrong - will break with config caching
$apiKey = env('THIRD_PARTY_API_KEY'); // Right - works with config caching
// In config/services.php:
'third_party' => [ 'api_key' => env('THIRD_PARTY_API_KEY'),
], // In your code:
$apiKey = config('services.third_party.api_key');
APP_DEBUG=false
APP_ENV=production
APP_DEBUG=false
APP_ENV=production
APP_DEBUG=false
APP_ENV=production
# Application
APP_NAME="My Laravel App"
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost # Database
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my_app
DB_USERNAME=root
DB_PASSWORD= # Third-Party Services
# Get your API key from https://dashboard.service.com
THIRD_PARTY_API_KEY=
THIRD_PARTY_WEBHOOK_SECRET=
# Application
APP_NAME="My Laravel App"
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost # Database
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my_app
DB_USERNAME=root
DB_PASSWORD= # Third-Party Services
# Get your API key from https://dashboard.service.com
THIRD_PARTY_API_KEY=
THIRD_PARTY_WEBHOOK_SECRET=
# Application
APP_NAME="My Laravel App"
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost # Database
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my_app
DB_USERNAME=root
DB_PASSWORD= # Third-Party Services
# Get your API key from https://dashboard.service.com
THIRD_PARTY_API_KEY=
THIRD_PARTY_WEBHOOK_SECRET=
// config/logging.php
'channels' => [ 'stack' => [ 'driver' => 'stack', 'channels' => app()->environment('production') ? ['daily', 'slack'] : ['daily'], ],
],
// config/logging.php
'channels' => [ 'stack' => [ 'driver' => 'stack', 'channels' => app()->environment('production') ? ['daily', 'slack'] : ['daily'], ],
],
// config/logging.php
'channels' => [ 'stack' => [ 'driver' => 'stack', 'channels' => app()->environment('production') ? ['daily', 'slack'] : ['daily'], ],
],
FEATURE_NEW_DASHBOARD=true
FEATURE_BETA_API=false
FEATURE_NEW_DASHBOARD=true
FEATURE_BETA_API=false
FEATURE_NEW_DASHBOARD=true
FEATURE_BETA_API=false
// config/features.php
return [ 'new_dashboard' => env('FEATURE_NEW_DASHBOARD', false), 'beta_api' => env('FEATURE_BETA_API', false),
]; // In your code
if (config('features.new_dashboard')) { // Show new dashboard
}
// config/features.php
return [ 'new_dashboard' => env('FEATURE_NEW_DASHBOARD', false), 'beta_api' => env('FEATURE_BETA_API', false),
]; // In your code
if (config('features.new_dashboard')) { // Show new dashboard
}
// config/features.php
return [ 'new_dashboard' => env('FEATURE_NEW_DASHBOARD', false), 'beta_api' => env('FEATURE_BETA_API', false),
]; // In your code
if (config('features.new_dashboard')) { // Show new dashboard
}
// In a service provider boot() method
$required = ['APP_KEY', 'DB_HOST', 'DB_DATABASE', 'MAIL_MAILER']; foreach ($required as $var) { if (empty(config(strtolower(str_replace('_', '.', $var))))) { throw new RuntimeException("Required environment configuration is missing: {$var}"); }
}
// In a service provider boot() method
$required = ['APP_KEY', 'DB_HOST', 'DB_DATABASE', 'MAIL_MAILER']; foreach ($required as $var) { if (empty(config(strtolower(str_replace('_', '.', $var))))) { throw new RuntimeException("Required environment configuration is missing: {$var}"); }
}
// In a service provider boot() method
$required = ['APP_KEY', 'DB_HOST', 'DB_DATABASE', 'MAIL_MAILER']; foreach ($required as $var) { if (empty(config(strtolower(str_replace('_', '.', $var))))) { throw new RuntimeException("Required environment configuration is missing: {$var}"); }
} - APP_KEY — each environment needs its own encryption key
- Database credentials
- Third-party API keys (use sandbox/test keys for non-production)
- Mail credentials
- Cache and queue connection passwords - Setting environment variables as part of a CI/CD pipeline
- Rotating secrets automatically
- Syncing non-sensitive configuration across environments - For database passwords: Create a new database user with the new password. Update the .env on Deploynix. Deploy with zero-downtime deployment (the new process uses the new credentials while the old process finishes its requests with the old credentials). Once the deployment is complete, remove the old database user.
- For API keys: Many services allow multiple active API keys. Generate a new key, update .env, deploy, then revoke the old key.
- For APP_KEY: This is the most sensitive rotation because it affects encrypted data. Laravel's php artisan key:generate can be combined with the APP_PREVIOUS_KEYS environment variable to support graceful key rotation without immediately invalidating all encrypted data. - APP_ENV is set to production
- APP_DEBUG is set to false
- APP_KEY is set and unique to this environment
- APP_URL matches the actual production URL (including scheme)
- Database credentials are unique to this environment
- Mail is configured for a production mail service (not log or array)
- Queue connection is set to a persistent driver (not sync)
- Session driver is set appropriately (not file on load-balanced setups)
- Cache driver is set to a persistent store
- All third-party API keys are production keys (not sandbox/test)
- No .env.backup or .env.old files exist on the server