可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答1:
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.
回答2:
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
回答3:
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,
回答4:
I just fix error.
Shift+Click
right mouse to "open commend window here" from your root project.
- In console write:
"php artisan key:generate"
.
- Get 32 character 'Mark' to
config/app.php
like 'key' => env('APP_KEY', 'insert get 32 char key')
,//line number 81
回答5:
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.
回答6:
I fixed it by running this:
php artisan config:cache
回答7:
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
回答8:
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
回答9:
solved with:
php artisan key:generate
回答10:
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',
回答11:
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
回答12:
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.
回答13:
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.
回答14:
Please make sure you have this requirements in your machine.
- PHP >= 5.6.4
- OpenSSL PHP Extension
- PDO PHP Extension
- Mbstring PHP Extension
- Tokenizer PHP Extension
- 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.