您只输入控制台:
php artisan key:generate
如果您的app.php不更改此键,请手动更改。
接下来,如果你应该碰巧得到这个错误信息:
[ErrorException]
file_get_contents(/path/to/my/project/.env):无法打开流:没有这样的文件或目录
然后制作该.env.example
文件的副本,然后重试:
cp .env.example .env
php artisan key:generate
欢迎各位兄弟 发布技术文章
这里的技术是共享的
克隆了一个Laravel的项目到本地,运行是出现这个错误:
RuntimeException in EncryptionServiceProvider.php line 29:
No supported encrypter found. The cipher and / or key length are invalid.
这个是因为项目根目录下的 .env 文件中的 APP_KEY 没设置对,默认是 APP_KEY=SomeRandomString,这个要改成自己的,但也不是随便改就行,Laravel 有提供可以通过命令行生成这个 key,在项目根目录下执行:
php artisan key:generate
完成后 .env 文件中的 APP_KEY 被修改成类似:
APP_KEY=4Hdy4BkW5JB0IyYAM9z7eV6HTtoXtX1c
至于这个命令做了什么,可以看这里 \Illuminate\Foundation\Console\KeyGenerateCommand :
$key = $this->getRandomKey($this->laravel['config']['app.cipher']); if ($this->option('show')) { return $this->line('<comment>'.$key.'</comment>'); } $path = base_path('.env'); if (file_exists($path)) { file_put_contents($path, str_replace( 'APP_KEY='.$this->laravel['config']['app.key'], 'APP_KEY='.$key, file_get_contents($path) )); }
其中:
protected function getRandomKey($cipher) { if ($cipher === 'AES-128-CBC') { return Str::random(16); } return Str::random(32); }
就是说这个 key 是根据 config/app.php 中的 cipher 值来决定长度是16还是32的随机字符串,Laravel 中默认是:
'cipher' => 'AES-256-CBC',
也就是32。所以其实可以不通命令行,直接修改 key,但必须是 key 长度必须是 32 就可以了。
前一篇: 安装 yii2 出现 Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist
后一篇: PHP7 下安装 memcache 和 memcached 扩展
我正在使用Laravel建立一个项目。它在本地主机上工作正常,但是当我将其上传到服务器(服务器已安装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
任何人都可以帮助解决这个错误?
正确答案
您是否在服务器上安装了所有必需的扩展?
可能是您缺少OpenSSL扩展。此外,您是否将密钥设置为.env
文件?
尝试运行:
php artisan key:generate
答:'cipher' => ''
不设定 .env文件
77 | 您只输入控制台:
如果您的app.php不更改此键,请手动更改。 接下来,如果你应该碰巧得到这个错误信息:
然后制作该
| ||||||||
|
9 | 以前我有同样的问题,我按照这样的方式修改:转到config / app.php,更改
| ||||||||||||||||||||
|
7 | 我只是修复错误。
| |||
5 | 在根目录下,如果有 | ||
4 | 在我的情况下,我需要启用mcrypt扩展。 但首先,检查你是否已经拥有它:
检查是否加载了mcrypt模块:
如果没有显示,是因为没有加载,但是你已经安装好了吗?这样做:
再检查一下,你应该看到mcrypt而不是任何东西。这是一个好的迹象,重新加载你的应用程序,并解决你的下一个错误;)
| ||
4 | 写在控制台 你会得到如下消息: 替换应用程序键 | ||||||||
|
4 | 解决了: php artisan key:generate | ||
2 | 我设法解决部署到现在的Ubuntu服务器,这里是所有的步骤 确保PHP> = 5.5.9 确保安装了OpenSSL,Mbstring,Tokenizer和mcrypt。 在PHP(Ubuntu)中安装mcrypt:
使存储文件夹可写:
使Apache使用Lavarel /公用文件夹作为家:
对我来说主要是疑难杂症可能FTP默认情况下不复制隐藏文件: 完成上述任务后,它在Ubuntu服务器上工作 | |||
0 | 我遇到这个问题几个小时,之后我发现钥匙被缓存在bootstrap \ cache \ config.php中。删除文件和我的网站加载正常(即否则我的配置没有问题)。 我发现这是通过添加一些调试输出到boostrap \ cache \ compiled.php,使其吐出密码和密钥(在7010行附近)。然后挖出来看看它是如何拿起配置,发现它使用缓存配置文件。 | ||
0 | 添加
然后运行
| ||
0 | 请确保您的机器有此要求。
然后安装或更新您的项目
之后你有 -
复制一次并重命名为 -
并根据您的数据库配置或您需要的任何其他修改进行更改。
最后生成你的应用程序密钥 -
对于有人可能只有最后一步就够了。但是每当我克隆任何一个laravel项目时,我都有这个问题。这整个步骤使任何危险。 | ||
感谢您对此问题的关注。因为它吸引了低质量或垃圾邮件的答案,必须删除,所以现在发布答案需要在这个网站10 声望(协会奖金不算)。
你想回答这些未回答的问题之一吗?
'cipher' => 'AES-256-CBC'
的config/app.php
- Salkz 七月 20'15 在9:56php artisan key:generate
生成一个新的密钥。 - Salkz 七月 20'15 在9:59