Php AWS API路由返回500
我最近将我的Laravel API部署到AWS ElasticBeanStalk 我想测试API是否正在运行,所以我做了一个简单的路由来返回一条消息。在本地,它运行良好: 输出:Php AWS API路由返回500,php,api,amazon-web-services,Php,Api,Amazon Web Services,我最近将我的Laravel API部署到AWS ElasticBeanStalk 我想测试API是否正在运行,所以我做了一个简单的路由来返回一条消息。在本地,它运行良好: 输出:欢迎 但在AWS上,我得到: 输出:哎呀,好像出了什么问题。(输出两次) 这是一个500错误,没有很多其他有用的信息 我打开了调试模式并得到: RuntimeException in EncryptionServiceProvider.php line 29: No supported encrypter found
欢迎
但在AWS上,我得到:
输出:哎呀,好像出了什么问题。
(输出两次)
这是一个500错误,没有很多其他有用的信息
我打开了调试模式并得到:
RuntimeException in EncryptionServiceProvider.php line 29:
No supported encrypter found. The cipher and / or key length are invalid.
查找此错误并发现,该错误表示将我的config\app.php
密码更改为:
'cipher' => 'AES-256-CBC',
但它已经是那个价值了
然后它说要确保.envAPP_键是32位,而我的是32位
本地主机和aws应用程序之间的请求头看起来类似。虽然存在差异,但我认为没有一个会返回500。我使用SSH连接AWSEC2以验证路由是否相同
路线:
Route::group(['middleware' => 'cors'], function(Router $router) {
Route::get('/', function () {
return 'Welcome';
});
哎呀,忘了将环境变量添加到AWS应用程序实例
1) 转到应用程序->配置->软件配置
2) 在本地.env
中添加环境变量,并为生产指定唯一值
3) 通过SSH将环境变量注册到服务器中,验证环境变量是否已在EC2上注册,然后运行cd/opt/elasticbeanstalk/support
并运行cat环境变量
。应列出环境变量
4) 然后使用源环境变量执行环境变量
5) 输出环境变量以验证它们是否在应用程序中设置:echo ENV$APP_KEY
将吐出您设置的环境值您的服务器上应该有错误日志。我会寻找答案,而不是猜测问题出在哪里。
class EncryptionServiceProvider extends ServiceProvider
{
Encryption Service Provider:
public function register()
{
$this->app->singleton('encrypter', function ($app) {
$config = $app->make('config')->get('app');
$key = $config['key'];
$cipher = $config['cipher'];
if (Encrypter::supported($key, $cipher)) {
return new Encrypter($key, $cipher);
} elseif (McryptEncrypter::supported($key, $cipher)) {
return new McryptEncrypter($key, $cipher);
} else {
throw new RuntimeException('No supported encrypter found. The cipher and / or key length are invalid.');
}
});
}