SECURITY WARNING: Never run commands you don't understand. Always review code before execution. Use at your own risk.
PHP New Added 29 September 2026

Laravel: No application encryption key has been specified.

APP_KEY is empty in the environment Laravel actually loaded, so it cannot encrypt cookies or sessions. On a fresh clone that just means .env was never created. In production it is usually a cached config from before the key was set, or a container whose environment does not include the variable even though the .env file on disk does.

Quick fix

Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.

Quick fix
# Is the key set where Laravel looks?
grep '^APP_KEY=' .env
php artisan about | grep -i -A2 environment

# Fresh install: create .env and a key
cp .env.example .env
php artisan key:generate

# Production: a stale config cache ignores .env entirely
php artisan config:clear
php artisan config:cache

# Containers: pass the key as a real environment variable
# docker run -e APP_KEY=base64:... app

# Never regenerate the key on a live site: existing sessions and
# encrypted data become unreadable

How to diagnose PHP errors

PHP errors are dominated by per-request resource limits (memory_limit, max_execution_time) and by autoloading. Class-not-found errors are almost never missing code. They are a namespace that does not match the PSR-4 mapping, or a stale Composer autoload map. Laravel adds a caching layer that produces genuinely confusing errors when configuration is cached with the wrong environment.

If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.

  1. Read the real limits from the running process, not from a config file: php -i | grep -E 'memory_limit|max_execution_time'. CLI and FPM have separate configurations.
  2. Regenerate the autoload map with composer dump-autoload -o before investigating a class-not-found error any further.
  3. For Laravel, clear cached config and routes with php artisan optimize:clear. A config cache built in the wrong environment causes errors that survive every code change.
  4. Enable full error display in development (display_errors=On, error_reporting=E_ALL). The default production settings hide the cause.
  5. For PDO connection refusals, test the same credentials with the database's own CLI client to separate PHP configuration from database access.

Tools worth reaching for

  • php -i
  • composer dump-autoload -o
  • php artisan optimize:clear
  • Xdebug
  • tail -f storage/logs/laravel.log

Authoritative references

Primary documentation for this error, worth reading before applying any fix in production.

laravel.com laravel.com

Related PHP errors

See all 20 PHP errors →

Browse other categories

Something missing or wrong?

This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.