Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel says no supported encrypter was found because of the cipher or key length

ErrorNo supported encrypter found. The cipher and / or key length are invalid.

Short answer

Laravel's encrypter needs the application key in APP_KEY, and it cannot start without a usable one. Most of the time the key is empty after a fresh clone or deploy. Check it, generate one with php artisan key:generate, then clear a cached configuration. Also look for a server-level APP_KEY that overrides the .env file.

  • Applies to Laravel 12, PHP 8.3, php artisan
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check that APP_KEY has a value in .env, and that no server environment variable shadows it. The commands print counts, not the key, so you can paste the output safely.

    grep -c '^APP_KEY=.\+' .env
    printenv | grep -c '^APP_KEY='
  2. 2Match what you see, then jump to its fix

    1. 1The first command prints 0, for example after cloning the project and copying .env.example to .envAPP_KEY is empty or missingFix
    2. 2APP_KEY is in .env now, but the error stays after the change, on a server where config:cache was run during deploymentThe configuration was cached before the key was setFix
    3. 3The second command in the first step prints 1, and the value comes from the web server, container or process manager, not from .envA server-level APP_KEY overrides the .env valueFix
    4. 4APP_KEY has a value, no cache or override exists, and the key was typed, trimmed by an editor or pasted from another projectThe key does not fit the cipher: typed by hand, cut short or copied wronglyFix

What does the error look like?

  • No supported encrypter found. The cipher and / or key length are invalid.

Cause 1 of 4

APP_KEY is empty or missing

1Check

The Laravel encryption documentation says the key option in config/app.php must be set before the encrypter is used, and that its value is driven by the APP_KEY environment variable.

grep -n '^APP_KEY' .env

2Fix

Generate the key with the Artisan command the documentation recommends. It uses PHP's secure random bytes generator and writes APP_KEY into .env.

php artisan key:generate

3Verify

Load a page that uses sessions or encrypted cookies; the error is gone.

grep -c '^APP_KEY=.\+' .env

Confirmed by laravel.com

Did this fix it?

Cause 2 of 4

The configuration was cached before the key was set

1Check

The configuration documentation says that after config:cache the .env file is not loaded during requests or Artisan commands, so a key added later is not seen until the cache is rebuilt.

ls bootstrap/cache/config.php

2Fix

Clear the cached configuration. When the key is final, cache it again as part of the deployment.

php artisan config:clear
php artisan config:cache

3Verify

Request the page again.

curl -I https://example.com/

Confirmed by laravel.com

Did this fix it?

Cause 3 of 4

A server-level APP_KEY overrides the .env value

1Check

The configuration documentation says any variable in .env can be overridden by external environment variables such as server-level or system-level variables. An old or empty APP_KEY there wins.

printenv | grep -c '^APP_KEY='

2Fix

Remove the external variable, or set it to the same key that .env holds, in the place where it is defined (the container, service file or hosting panel). Then restart the process.

# remove or correct APP_KEY where the server defines it, then restart PHP and the web server

3Verify

Run the same check in the same environment as the web process.

printenv | grep -c '^APP_KEY='

Confirmed by laravel.com

Did this fix it?

Cause 4 of 4

The key does not fit the cipher: typed by hand, cut short or copied wrongly

1Check

The configuration documentation names AES-256-CBC as the default cipher and says it requires a 32 character key. Keys made by key:generate start with base64:, as in the documentation's example, so a value without that prefix was made another way. The command prints 1 when the prefix is there.

grep -c '^APP_KEY="\?base64:' .env

2Fix

Generate a new key. Changing the key logs all users out, and data encrypted with the old key can no longer be decrypted. To keep that data readable, the documentation says to list the previous key in APP_PREVIOUS_KEYS.

php artisan key:generate
# .env, only if existing encrypted data must stay readable
APP_PREVIOUS_KEYS="base64:your-old-key-here"

3Verify

Clear any cached configuration, then load a page that uses sessions and confirm the error is gone.

php artisan config:clear
curl -I https://example.com/

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Run php artisan key:generate once as part of project setup, and keep the real key in your secret store, not in git.
  • Keep APP_KEY in the same place for every environment: .env, or the platform's secret variables, not both.
  • Run config:cache only in the deploy step, after .env or the platform variables are final.
  • Never share the key in tickets or screenshots; use counts and lengths when you ask for help.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.