APP_KEY is the foundation of Laravel encryption. Generating it on a new installation is straightforward, but changing it on a live application may affect sessions and previously encrypted data.
No application encryption key has been specified.
Unsupported cipher or incorrect key length.
php artisan key:generate --show
On a new installation, php artisan key:generate can be used when APP_KEY is empty. On a live application, blindly replacing the key invalidates encrypted session cookies and may make data encrypted with the previous key unreadable. Laravel 11 and later can retain previous keys through APP_PREVIOUS_KEYS during rotation.
A secure key must be generated for a new installation.
APP_KEY=APP_KEY="base64:..."Use the framework generator instead of typing a short value manually.
APP_KEY=123456php artisan key:generateIn production, preserve the old key securely and assess impact before rotation.
php artisan key:generate --forceAPP_PREVIOUS_KEYS="eski-anahtar"
APP_KEY="yeni-anahtar"Do not expose the key in shared terminal output.
grep '^APP_KEY=' .env | sed 's/=.*/=***MASKED***/'
php artisan about --only=environment
This updates APP_KEY in the .env file.
php artisan key:generate
php artisan optimize:clear
Useful when injecting the key through a deployment system or secret manager.
php artisan key:generate --show
Ensure web and queue worker processes use the same key.
php artisan config:clear
php artisan config:cache
php artisan queue:restart
Determine whether this is a new installation or a live production system.
Securely back up the existing .env and secret manager values.
Run key:generate on a new installation; assess the old key impact on production.
For Laravel 11+, plan APP_PREVIOUS_KEYS during rotation.
Refresh configuration cache and long-running workers.
Test sessions, encrypted columns, queues and API operations.
APP_KEY is empty, unreadable or cached as null.
APP_KEY format or length does not match the configured cipher.
The data was encrypted using a different APP_KEY.
Web nodes use different keys or the key was recently changed.
No matching error was found.
All web and worker nodes of the same application must use the same key. Different applications should use different keys.
If it replaces the current key, encrypted session cookies become invalid. Do not run it blindly on a live application.
Graceful key rotation was introduced in Laravel 11. Older versions require a version-specific migration plan.
We implement permanent fixes by reviewing Laravel, PHP-FPM, Nginx, Apache, MySQL, cPanel and Plesk layers together with their logs.