meetgodhani's avatar

'No supported encrypter found. The cipher and / or key length are invalid.' with Laravel 5.1

Getting this error on my Forge Instance. Even though I have set my "APP_KEY". I tried to regenerate my key several times but still getting this error. Anyway to solve this issue?

Following is full log:

[2015-06-21 17:15:10] production.ERROR: exception 'RuntimeException' with message 'No supported encrypter found. The cipher and / or key length are invalid.' in /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php:29
Stack trace:
#0 /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Container/Container.php(733): {closure}(Object(Illuminate\Foundation\Application))
#1 /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Container/Container.php(626): Illuminate\Container\Container->build(Object(Closure$Illuminate\Encryption\EncryptionServiceProvider::register;364564376), Array)
#2 /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(643): Illuminate\Container\Container->make('encrypter', Array)
#3 /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Container/Container.php(837): Illuminate\Foundation\Application->make('encrypter')
#4 /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Container/Container.php(800): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#5 /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Container/Container.php(771): Illuminate\Container\Container->getDependencies(Array, Array)
#6 /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Container/Container.php(626): Illuminate\Container\Container->build('InstaMint\Http\Middleware\EncryptCookies', Array)
#7 /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(643): Illuminate\Container\Container->make('InstaMint\Http\Middleware\EncryptCookies', Array)
#8 /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(123): Illuminate\Foundation\Application->make('InstaMint\Http\Middleware\EncryptCookies')
#9 /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(42): {closure}(Object(Illuminate\Http\Request))
#10 (): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure$Illuminate\Pipeline\Pipeline::getSlice;552322374))
#11 /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#12 (): {closure}(Object(Illuminate\Http\Request))
#13 /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure$Illuminate\Pipeline\Pipeline::getSlice;552322374), Object(Illuminate\Http\Request))
#14 /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(118): Illuminate\Pipeline\Pipeline->then(Object(Closure$Illuminate\Foundation\Http\Kernel::dispatchToRouter;85524752))
#15 /home/forge/picstats.io/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(86): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#16 /home/forge/picstats.io/public/index.php(54): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#17 {main}
0 likes
33 replies
bashy's avatar

Check the APP_KEY is correctly being pulled in? Have you got the cipher set properly as well?

meetgodhani's avatar

@bashy I have this in my app settings

'key' => env('APP_KEY', 'SomeRandomString'),
'cipher' => 'AES-256-CBC',

and I have my APP_KEY set in my .env file. But still getting same error. It works fine in my vagrant box. I get this error only on my forge instance.

bashy's avatar

Just try return it somewhere

return env('APP_KEY');
bashy's avatar

And you have the required modules?

WayneLuke's avatar

The "somerandomstring" value has to be at least 32 bytes. If you don't have a random key in your .env file, you will need to change the value in config/app.php

bashy's avatar

@WayneLuke In the screenshot the value is 32.

@meetgodhani Like the PHP extensions required to use the encryption ciphers. I guess if it's Forge, it has it already. Please check your app can actually read it, not just CLI tinker.

bashy's avatar

@kfirba "I tried to regenerate my key several times" is why I didn't suggest that.

kfirba's avatar

@bashy yup.. guess I read the title and I was like 'Oh I know this one, I had that same issue just few days ago' and instantly posted my answer :x

jpr0930's avatar

I had this same issue when trying to deploy to Heroku.

composer.json shows a key:generate step, but it didn't appear to be working. I just manually changed config/app.php to read 32-chars: "SomeRandomStringSomeRandomString" instead of the 16-char: "SomeRandomString", and then it worked fine.

Is there a risk in doing it this way? Is it possible that Heroku cannot overwrite config/app.php? Is there a better way to do this when deploying to a PaaS like Heroku?

EDIT: @Istables solution (below) is likely the better/safer route when deploying to production servers.

1 like
nickeddale's avatar

I was getting a blank error page on a fresh 5.1 install. jpr0930's solution solved this for me.

1 like
theUnforgiven's avatar

I found this on Forge and all I did was regenerate the key then add as a var in forge environment and worked a treat.

1 like
jpr0930's avatar

@Istables solution is likely the better/safer route when deploying to production servers.

imansyaefulloh's avatar

i had this problem before, and i fixed it by doing

php artisan key:generate

and make sure you change ".env.example" to ".env"

mv .env.example .env
6 likes
javy1103's avatar

I just had the same problem on a project, the default cipher in confing/app.php is "AES-256-CBC" which needs a 32 character string, but the default key is "SomeRandomString," which is only 16 characters. So, you can either set the cipher to "AES-128-CBC" which only needs 16 characters, or generate a new 32 character string for the key. Entering "php artisan key:gen

gbrock's avatar

I'm having this issue.

  • I'm using Forge / Laravel 5.1
  • I have set the key properly in my .env file and regenerated in about a dozen times
  • I see the correct key value using tinker
  • The cipher is set to AES-256-CBC
  • I'm still receiving the "No supported encrypter found. The cipher and / or key length are invalid" message.
1 like
tinymondo's avatar

I have the same issue. It behaves strangely though as I had it working for a while, but then i regenerated the key and the error appeared again.

But it works when I change the cipher to AES-128-CBC and the key to 16 characters, so that's a temporary fix. But I would like to know what's wrong here, it seems a bit buggy to me.

1 like
jpr0930's avatar

@gbrock and @tinymondo ,

Generate a new key and replace "SomeRandomString" in config/app.php (5.1) with that. Or just use some random set of 32 chars there. Should work after that.

gbrock's avatar

In my case, the variables from .env (which had the correct 32-bit string) were not being propagated to the nginx configuration (which still showed "SomeRandomString"). It's the only time I've seen this happen since I started using Forge a few months ago. I've edited the nginx config manually and everything works now.

nunomira's avatar

I know this is the Forge forum, but this happened to me on Godaddy.

php artisan key:generate

solved the issue

1 like
leadiztah's avatar

hey @meetgodhani I also got this error. BUT I GOT IT WORKED!!

first check if you have .env If you haven't that file try to move .env.example to .env If you are linux just go to directory and type "mv .env.example .env" If you are windows go to directory and type "move .env.example .env"

then after that if you have .env already just type "php artisan key:generate" and then check http://localhost:8080/laravel/public/ or what ever directory you have created.

:)

3 likes
lindstrom's avatar

You can manage your environment variables directly in Forge. Go to servers -> manage and then to the Environment tab. Click edit environment and paste in your production varialbes.

FWIW, I just transitioned to deploying via Envoyer and that is what brought me here. In my haste, I added my .env variables after my first my first deployment via Manage Environment from the server tab. When I checked the site, I had the 'no supported encrypter found'. What I didn't realize is that I need to deploy again in order for Envoyer to create the symlink from /envoyer to /envoyer/current/public. Also, I should have watched the entire video of Taylor explaining this: https://laracasts.com/series/envoyer/episodes/9

hayata's avatar

i faced the same issue where changing the

'cipher' => 'AES-256-CBC',

to

'cipher' => MCRYPT_RIJNDAEL_128,

in the config/app.php fixed it.

1 like
puzbie's avatar

You can also get this error if you copy a laravel folder to a new virtual server location using a tool like Dolphin, which doesn't copy .env files by default. The solution is to use something like Midnight Commander, or learn how to configure Dolphin. I chose the former but I am sure the latter is an option.

1 like
yher136's avatar

I fixed it installing the "php7.0-mcrypt" lib and restating nginx 'sudo service nginx restart' and it works fine! Maybe is the php version, the last night it was a real headache, my box was upgraded and installed php 7.0 version and crashed!

hasangilak's avatar

sometimes its just because .env file permission is not correct on your server chmod 775 .env should solve it for you

1 like
Donika's avatar

production.ERROR: RuntimeException: No supported encrypter found. The cipher and / or key length are invalid. in C:\laragon\www\baturin\vendor\laravel\framework\src\Illuminate\Encryption\EncryptionServiceProvider.php:45

'cipher' => 'AES-256-CBC', i have key too .env file

sometimes i have this error, sometimes no i use Laragon on my local machine

composer update, key generate, config clear does not help.... =(

mcordingley's avatar

@Donika If setting the key does not work, you may be missing the mcrypt php extension on the server. Missing it will cause PHP to complain about certain constants, like MCRYPT_RIJNDAEL_128, to be undefined. If your .env file is correct, this is likely your issue.

Next

Please or to participate in this conversation.