Laravel APP_KEY Generator
Generate secure application encryption keys for Laravel projects. These keys are used for encrypting cookies, sessions, and other sensitive data.
Format:
base64:<32 bytes>Key Size:256 bits
Cipher:AES-256-CBC
Add to .env File
.env
APP_KEY=base64:...Installation
1. Copy the key
Click on any generated key above to copy it to your clipboard.
2. Update your .env file
Paste the key as the value of APP_KEY in your Laravel project's .env file.
3. Clear config cache (if needed)
terminal
php artisan config:clearProduction Warning
Changing APP_KEY in production will invalidate all encrypted data, including user sessions, cookies, and any data encrypted with the old key. Only change it during initial setup or if you suspect the key has been compromised.
Why Laravel Needs APP_KEY
- Encrypts session data to prevent tampering
- Secures cookies containing sensitive information
- Used by Laravel's encryption facade for
encrypt()anddecrypt() - Protects CSRF tokens and other security features
- Required for signed URLs and password reset tokens
Bulk Generation
keys
Generate Locally
The recommended way is to use Laravel's built-in command:
Laravel Artisan (preferred)
$
php artisan key:generateOpenSSL
$
echo "base64:$(openssl rand -base64 32)"PHP CLI
$
php -r "echo 'base64:' . base64_encode(random_bytes(32)) . PHP_EOL;"