找不到支持的加密器。密码和/或密钥长度无效

我正在使用 Laravel 构建一个项目。它在 localhost 上运行良好,但是当我将它上传到服务器时(服务器已经安装了 comodo ssl) ,我收到以下错误:

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

有人能帮忙解决这个错误吗?

92627 次浏览

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.

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

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

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

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

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

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,

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.

solved with:

php artisan key:generate

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.

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.

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.

I fixed it by running this:

php artisan config:cache

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',

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',

Do not use "" Quotation marks with the values inside the .env file or OS envs.

Avoid APP_KEY_CIPHER="AES-256-CBC" instead use APP_KEY_CIPHER=AES-256-CBC.