[英]Laravel Elastic Beanstalk app deployed in CodePipeline giving 500 SERVER ERROR
I've created a Laravel app locally.我在本地创建了一个 Laravel 应用程序。 (This is working fine) (这工作正常)
After, deployed that app to AWS Elastic Beanstalk with a.zip file.之后,使用 .zip 文件将该应用程序部署到 AWS Elastic Beanstalk。 (This is working fine) (这工作正常)
Then, created a simple pipeline using AWS CodePipeline to grab data from a particular GitHub repo and deploy to that specific AWS Elastic Beanstalk environment.然后, 使用 AWS CodePipeline 创建一个简单的管道,以从特定的 GitHub 存储库中获取数据并部署到该特定的 AWS Elastic Beanstalk 环境。 I see that any push I make to that particular repo, the CodePipeline does then deploy to that particular AWS Elastic Beanstalk environment.我看到我对该特定存储库所做的任何推送,CodePipeline 都会部署到该特定 AWS Elastic Beanstalk 环境。
The problem is that the instance now has问题是实例现在有
with the following Recent Event与以下最近的事件
Environment health has transitioned from Warning to Severe.环境健康已从警告转变为严重。 100.0 % of the requests are failing with HTTP 5xx. 100.0% 的请求以 HTTP 5xx 失败。 ELB processes are not healthy on all instances. ELB 进程并非在所有实例上都运行良好。 Application restart completed 42 seconds ago and took 7 seconds.应用程序重新启动在 42 秒前完成,耗时 7 秒。 ELB health is failing or not available for all instances. ELB 运行状况失败或不适用于所有实例。 One or more TargetGroups associated with the environment are in a reduced health state: - awseb-AWSEB-CVIEEN5EVRFC - Warning与环境关联的一个或多个 TargetGroup 的健康状况降低 state:-awseb-AWSEB-CVIEEN5EVRFC - 警告
and if I go to its URL I get a如果我 go 到它的 URL 我得到一个
500 | 500 | SERVER ERROR服务器错误
Based on the comments.根据评论。
The issue was caused by missing .env
file in the deployment package/artifact that CodePipeline deploys.该问题是由 CodePipeline 部署的部署包/工件中缺少.env
文件引起的。 This was caused by the file not being committed into the GitHub repository.这是由于文件未提交到 GitHub 存储库中造成的。
To determine the cause, the CodePipeline's artifact was inspected.为了确定原因,检查了CodePipeline 的工件。 The artifact can be found in CodePipeline's bucket or in EB Application versions (in the Source column) and it is an objects a random name without an extension.该工件可以在 CodePipeline 的存储桶或 EB 应用程序版本(在 Source 列中)中找到,它是一个没有扩展名的随机名称的对象。 In OP's case it was S40pAMw
.在 OP 的情况下,它是S40pAMw
。 It should be noted that this object is just a zip
file without extension.需要注意的是,这个object只是一个没有扩展名的zip
文件。 To inspect it content, adding the extension to the download object allowed for straight forward opening of the zip
archive.要检查它的内容,将扩展添加到下载 object 允许直接打开zip
存档。
(Please see @JackPrice-Burns answer for alternative way of dealing with env variables). (有关处理环境变量的替代方法,请参阅@JackPrice-Burns 答案)。
The solution was to commit the missing file into the repository.解决方案是将丢失的文件提交到存储库中。 Once that was done, the CodePipeline was triggered完成后,触发 CodePipeline
and once the deployment finished the Health of the Elastic Beanstalk instance changed to Ok部署完成后,Elastic Beanstalk 实例的运行状况更改为 Ok
and the 500 |和 500 | SERVER ERROR was now gone服务器错误现在消失了
This issue specifically was caused by missing environment variables.此问题具体是由缺少环境变量引起的。
It is BAD practice to commit.env or any files containing secrets to GitHub or any other source control system. commit.env 或任何包含 GitHub 或任何其他源代码控制系统机密的文件是不好的做法。
In the ElasticBeanstalk console you can go to Configuration -> Software and add environment variables at the bottom of the page (screen shot attached).在 ElasticBeanstalk 控制台中,您可以 go 到 Configuration -> Software 并在页面底部添加环境变量(附屏幕截图)。 These environment variables will be picked up by Laravel.这些环境变量将被 Laravel 拾取。 Set all variables that are in the.env on that settings page and do not commit the.env.在该设置页面上设置 .env 中的所有变量,并且不要提交 .env。
Another good practice to follow is not committing your vendor folder.另一个要遵循的好习惯是不提交您的供应商文件夹。 AWS CodePipeline allows you to create another step which can build your source code. AWS CodePipeline 允许您创建另一个可以构建源代码的步骤。 This build step can take in your source control code, run composer install (to generate the vendor folder) and then send that to Elastic Beanstalk for deployment.此构建步骤可以接收您的源代码控制代码,运行 composer install(以生成供应商文件夹),然后将其发送到 Elastic Beanstalk 进行部署。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.