# No application encryption key has been specified

Laravel needs APP_KEY to encrypt cookies and data, and found it empty. Check .env and the cached config first, and generate a key only when there is none.

Message:

```text
No application encryption key has been specified.
```

Exception:

```text
Illuminate\Encryption\MissingAppKeyException
```

## What it means

Laravel tried to create its encrypter and found the `app.key` configuration value empty. That value comes from the `APP_KEY` environment variable. Every request that goes through the web middleware needs the encrypter, because Laravel encrypts its cookies, so the error appears on the first page you open.

## Why it happens

- There is no key in `.env`. The `.env.example` that ships with Laravel has an empty `APP_KEY=`, so a `.env` copied from it on a new server or a fresh clone has no key until `php artisan key:generate` runs.
- The configuration was cached before the key was set. Once `php artisan config:cache` has run, Laravel no longer loads `.env`. Adding the key afterwards changes nothing until you cache again.
- The PHP process that serves the site cannot read `.env`. When the file is missing from the application root or not readable by that user, Laravel starts without it, and the key is empty.

## How to fix it

First look in `.env`, and check that the user PHP runs as can read it:

```bash
grep '^APP_KEY=' .env
ls -l .env
```

If `.env` already has a key, do not generate one. Make sure that user can read the file, then rebuild the cached configuration, or clear it with `php artisan config:clear` if you do not cache:

```bash
php artisan config:cache
```

Running `key:generate` here destroys the working key. The command reads the empty cached key, so it skips the production confirmation, and it writes the new key in front of the old one on the same line.

Only generate a key when `.env` has none, and know first what it protects. Laravel encrypts every cookie with it, including the session cookie, and everything you encrypt with the `Crypt` facade. If you change the key, every logged-in user is logged out, and data encrypted with the old key can no longer be decrypted. If a server lost its key, find the old value and put it back. Otherwise generate one. The command writes it into `.env`:

```bash
php artisan key:generate
```

If it answers "No APP_KEY variable was found in the .env file", add an empty `APP_KEY=` line and run it again. If you cache your configuration, run `php artisan config:cache` afterwards.

To move to a new key later, list the old one in `APP_PREVIOUS_KEYS`. Laravel encrypts with the current key and tries the previous keys when decrypting:

```ini
APP_KEY="base64:your-new-key"
APP_PREVIOUS_KEYS="base64:your-old-key"
```

## Find it in production

Every page served through the web middleware answers 500, and with `APP_DEBUG=false` the visitor sees the plain "Server Error" page. Laravel reports the exception: `MissingAppKeyException` is not on the `internalDontReport` list in the framework's exception handler, and it is written to `storage/logs/laravel.log` at error level. The built-in health route at `/up` does not set cookies, and in a test without a key it still answered 200 while every page failed, so a health check on `/up` alone misses this. [Ranetrace uptime monitoring](/features/uptime-monitoring) requests the site about every minute and alerts you once it has been down for two minutes.

Reproduced on Laravel 13.45, PHP 8.5, 5 December 2026.

Read more: https://laravel.com/docs/encryption

## Related

### Terms

- [Configuration caching in Laravel](https://ranetrace.com/glossary/configuration-caching-in-laravel.md)
- [Uptime monitoring](https://ranetrace.com/glossary/uptime-monitoring.md)

### Other errors

- [SQLSTATE\[HY000\] \[2002\] Connection refused](https://ranetrace.com/error-guides/laravel-sqlstate-2002-connection-refused.md)
- [419 Page Expired](https://ranetrace.com/error-guides/laravel-419-page-expired.md)
- [laravel.log could not be opened in append mode: Permission denied](https://ranetrace.com/error-guides/laravel-log-file-permission-denied.md)

Read this guide in a browser: https://ranetrace.com/error-guides/laravel-no-application-encryption-key
