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

PhpSslLaravel 5

Php Problem Overview


I am building a project using Laravel. It was working fine on localhost, but when I upload it to the server (the server has comodo ssl installed), I receive the following error:

RuntimeException in EncryptionServiceProvider.php line 29:
No supported encrypter found. The cipher and / or key length are invalid
in EncryptionServiceProvider.php line 29
at EncryptionServiceProvider->Illuminate\Encryption\{closure}(object(Application), array()) in Container.php line 733
at Container->build(object(Closure), array()) in Container.php line 626
at Container->make('encrypter', array()) in Application.php line 674
at Application->make('Illuminate\Contracts\Encryption\Encrypter') in Container.php line 837
at Container->resolveClass(object(ReflectionParameter)) in Container.php line 800
at Container->getDependencies(array(object(ReflectionParameter)), array()) in Container.php line 771
at Container->build('SahraSalon\Http\Middleware\EncryptCookies', array()) in Container.php line 626
at Container->make('SahraSalon\Http\Middleware\EncryptCookies', array()) in Application.php line 674
at Application->make('SahraSalon\Http\Middleware\EncryptCookies') in Pipeline.php line 123
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 118
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 86
at Kernel->handle(object(Request)) in index.php line 54

Can anyone help solve this error?

Php Solutions


Solution 1 - Php

You only type in console:

php artisan key:generate

And if your app.php not change this Key, change manually.


Next if you should then happen to get this error message:

>[ErrorException]
file_get_contents(/path/to/my/project/.env): failed to open stream: No such file or directory

Then make a copy of the .env.example file and try again:

cp .env.example .env
php artisan key:generate

Solution 2 - Php

Do you have all the necessary extensions installed on the server?

  • PHP >= 5.5.9
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension

It could be that you're missing the OpenSSL extension. Also, do you have the key set in .env file?


Try running:

php artisan key:generate


Answer: the 'cipher' => '' was not set.

Solution 3 - Php

I fixed it by running this:

php artisan config:cache

Solution 4 - Php

I have same issue before and I fixed it follow this way: Go to config/app.php, change "cipher" => "anything" to

'cipher' => MCRYPT_RIJNDAEL_128,

Solution 5 - Php

I just fix error.

  1. Shift+Click right mouse to "open commend window here" from your root project.
  2. In console write: "php artisan key:generate".
  3. Get 32 character 'Mark' to config/app.php like 'key' => env('APP_KEY', 'insert get 32 char key'),//line number 81

Solution 6 - Php

In my case, I need to enable mcrypt extension.

But first, check if you already have it:

$ sudo apt-get install -y mcrypt php5-mcrypt

Check if mcrypt module is loaded:

$ php -m | grep mcrypt

if nothing shows, is because is not loaded, but you already have installed above right? So do this:

$ php5enmod mcrypt
$ sudo service apache2 restart

Check again and you should see mcrypt instead of nothing. Thats a good sign, reload you app and go fix your next error ;)

$ php -m | grep mcrypt
mcrypt

Solution 7 - Php

In root directory, if there is .env.example file then change it to .env and then run php artisan key:generate. This worked for me.

Solution 8 - Php

write in console php artisan key:generate

you will get message like: Application key [get 32 char key] set successfully.

replace app key in config/app.php like 'key' => env('APP_KEY', 'insert get 32 char key'),//line number 81

Solution 9 - Php

solved with:

php artisan key:generate

Solution 10 - Php

if you are using app.php configuration file instead of reading key from .env file, then you can remove the env() function on key variable, ex:

'key' = env('someRandom36CharsString'),

to

'key' = 'someRandom36CharsString',

Solution 11 - Php

I managed to solve deployment to live Ubuntu server, here is all the steps

Ensure PHP >= 5.5.9

Ensure, OpenSSL, Mbstring, Tokenizer and mcrypt is installed.

To Install mcrypt in PHP (Ubuntu):

sudo apt-get install php5-mcrypt,
sudo php5enmod mcrypt

Make storage folder writable:

chmod -R 0777 storage

Make Apache use the Lavarel /public folder as home:

DocumentRoot /home/code2/public_html/Laravel-Project/public
	<Directory "/home/code2/public_html/Laravel-Project/public”> 
		 AllowOverride all 
	</Directory>

Major gotcha for me is FTP might not copy hidden files by default: .env and /public/.htaccess need to be there!

After completing the tasks above, it worked on Ubuntu server

Solution 12 - Php

I was suffering with this problem for a few too many hours before I discovered that the key was being cached in the bootstrap\cache\config.php. Deleted the file and my site loaded fine (i.e. there was otherwise no problem with my config).

I discovered this by adding some debug output to boostrap\cache\compiled.php to make it spit out the cipher and key (somewhere around line 7010). Then dug around to see how it was picking up the config and found it uses a cache config file.

Solution 13 - Php

Please make sure you have this requirements in your machine.

  1. PHP >= 5.6.4
  2. OpenSSL PHP Extension
  3. PDO PHP Extension
  4. Mbstring PHP Extension
  5. Tokenizer PHP Extension
  6. XML PHP Extension

Then after install or updating your project by

> composer update

After this you have--

> .env.example

Make a duplicate and rename it to--

> .env

and make changes according to your database configuration or any other modifications you need.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your db name
DB_USERNAME=username if any otherwise root
DB_PASSWORD= your password if not set leave blank

Finally generate your application key by--

> php artisan key:generate

For Someone may be only last step is enough. But I have this problem every time I clone any laravel project. This whole step makes this with any hazard.

Solution 14 - Php

Add "illuminate/html": "~5.0" to require section of your composer.json file. Just like this:

...
"require": {
	...
	"illuminate/html": "~5.0"
	...
},
...

Then run composer install command. When composer install gets complete. run php artisan key:generate. You will get a message like this:

Application key [get 32 char key] set successfully.

Solution 15 - Php

In some old versions of laravel you have to change the default value of cipher in /config/app.php from "AES-256-CBC" to "AES-128-CBC".

the default cipher in confing/app.php is "AES-256-CBC" which needs a 32 character string, and the cipher "AES-128-CBC" only needs 16 characters.

Entering php artisan key:generate is the simplest solution.

new versions

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

old versions

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRahmanView Question on Stackoverflow
Solution 1 - PhponavascuezView Answer on Stackoverflow
Solution 2 - PhpSalkzView Answer on Stackoverflow
Solution 3 - PhpRowayda KhayriView Answer on Stackoverflow
Solution 4 - PhpVuong TranView Answer on Stackoverflow
Solution 5 - Phpdkbn90View Answer on Stackoverflow
Solution 6 - PhpLucas SerafimView Answer on Stackoverflow
Solution 7 - PhpTirth PatelView Answer on Stackoverflow
Solution 8 - PhpMd Shahadat HossainView Answer on Stackoverflow
Solution 9 - PhpPlugue View Answer on Stackoverflow
Solution 10 - Phprüff0View Answer on Stackoverflow
Solution 11 - PhpJohn WylieView Answer on Stackoverflow
Solution 12 - PhpCiaranView Answer on Stackoverflow
Solution 13 - PhpAshfak Md ShibliView Answer on Stackoverflow
Solution 14 - PhpIlyas karimView Answer on Stackoverflow
Solution 15 - PhpedocolladoView Answer on Stackoverflow