I installed a new fresh copy of laravel 5.3 using composer but I keep getting this error:
The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths. Even though my app.php file in config directory specify
'cipher' => 'AES-128-CBC',
Run
php artisan key:generate
.Do
php artisan config:clear
,Then
php artisan config:cache
And things will start working!
Follow These Steps:
Step 1: Make sure you have .env file in your application.If not run this command
cp .env.example .env
Step 2: Now run following command (
php artisan key:generate
) to generate a key and it will get saved in .env file automatically.Step 3: Run
php artisan config:cache
It will fix everything.
If the artisan command doesn't work and you get the same error in the command line, that means composer didn't do a good job at getting all the files, you should delete the vendor folder and run
composer update
again.Run this commands on your terminal:
php artisan config:clear
then
php artisan config:cache
in
.env
file give this key and you are doneStill not working?
If you are working from cli, reboot the server and it will.
Want explanation?
ok, as the error message says:
Key length for
AES-128-CBC
is 16 characters e.g ABCDEF123ERD456EKey length for
AES-256-CBC
is 32 characters e.g ABCDEF123ERD456EABCDEF123ERD456EMake sure in
config/app.php
thecipher
is set to the appropriate cipher like the two above and the key is pointing to the.env
fileAPP_KEY
variable. My app has theAES-256-CBC
cipher set, so i gave it the 32 characters key likeAPP_KEY=ABCDEF123ERD456EABCDEF123ERD456E
and everything worked just fine after that.Ok, this has basically already been answered, but I found a couple caveats that had be consternated, or constipated, one of those two...
First, as has already been said, you should ensure you have a valid
.env
file which you can accomplish in the terminal by copying the existing.env.example
file as such:$ cp .env.example .env
Then, generate your application Key
$ php artisan key:generate
Once this is done, make sure to open your .env file and ensure that the APP_KEY line looks correct - this is where my consternation came from:
APP_KEY=base64:MsUJo+qAhIVGPx52r1mbxCYn5YbWtCx8FQ7pTaHEvRo=base64:Ign7MpdXw4FMI5ai7SXXiU2vbraqhyEK1NniKPNJKGY=
You'll notice that the key length is wrong, it for some unknown reason (probably from running key:generate multiple times) has two
base64=
keys in there. Removing one is the fix to the problems I was having and this appears to be an Artisan/Laravel bug.Hope this answer helps anyone who may be struggling with the same problems or annoying bug.