'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?
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
@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.
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.
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
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.
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.
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.
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.
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
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.
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!
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.... =(
@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.