Mysql &引用;“拒绝连接”;创建弹性豆茎环境时
我将按照本教程在弹性Beanstalk环境中设置Laravel: 我已经在全新安装的Laravel上检查了两次,只是想看看它是否有效,两次都有效 现在,我又经历了一遍,但这次是在我的主要拉威尔项目上。我已经仔细检查了教程中的所有内容,我相信我没有遗漏任何内容 但是,当我使用教程中的此命令创建环境时(当然要填入值): 我得到以下输出错误:Mysql &引用;“拒绝连接”;创建弹性豆茎环境时,mysql,laravel,amazon-web-services,laravel-5,amazon-elastic-beanstalk,Mysql,Laravel,Amazon Web Services,Laravel 5,Amazon Elastic Beanstalk,我将按照本教程在弹性Beanstalk环境中设置Laravel: 我已经在全新安装的Laravel上检查了两次,只是想看看它是否有效,两次都有效 现在,我又经历了一遍,但这次是在我的主要拉威尔项目上。我已经仔细检查了教程中的所有内容,我相信我没有遗漏任何内容 但是,当我使用教程中的此命令创建环境时(当然要填入值): 我得到以下输出错误: Printing Status: INFO: createEnvironment is starting. INFO: Using elasticbeanst
Printing Status:
INFO: createEnvironment is starting.
INFO: Using elasticbeanstalk-us-east-1-487650495335 as Amazon S3 storage bucket for environment data.
INFO: Created security group named: sg-018fe470
INFO: Created load balancer named: awseb-e-7-AWSEBLoa-1M3V7HA824OQ0
INFO: Created security group named: sg-7489ec08
INFO: Environment health has transitioned to Pending. Initialization in progress (running for 19 seconds). There are no instances.
INFO: Created Auto Scaling launch configuration named: awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingLaunchConfiguration-RZPSBCGFS6HY
INFO: Added instance [i-09cc6faf451ef3670] to your environment.
INFO: Created Auto Scaling group named: awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingGroup-BQI6UG2OLL7E
INFO: Waiting for EC2 instances to launch. This may take a few minutes.
INFO: Created Auto Scaling group policy named: arn:aws:autoscaling:us-east-1:457680865345:scalingPolicy:a3629314-6d24-4871-a0a1-59d74a1087c2:autoScalingGroupName/awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingGroup-BQI6UG2OLL7E:policyName/awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingScaleDownPolicy-1SM372VEND7T6
INFO: Created Auto Scaling group policy named: arn:aws:autoscaling:us-east-1:457680865345:scalingPolicy:b03a08fb-e39f-4dc5-8e00-f81f8059fc56:autoScalingGroupName/awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingGroup-BQI6UG2OLL7E:policyName/awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingScaleUpPolicy-AS65NNA5M4PP
INFO: Created CloudWatch alarm named: awseb-e-7xdtjzn4bn-stack-AWSEBCloudwatchAlarmLow-1D9SO13U3HBR0
INFO: Created CloudWatch alarm named: awseb-e-7xdtjzn4bn-stack-AWSEBCloudwatchAlarmHigh-1FUCKP1GWED3A
ERROR: [Instance: i-09cc6faf451ef3670] Command failed on instance. Return code: 1 Output: (TRUNCATED)...
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
Script php artisan optimize handling the post-install-cmd event returned with error code 1.
Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/10_composer_install.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
ERROR: Create environment operation is complete, but with errors. For more information, see troubleshooting documentation.
如您所见,在post install cmd中运行php artisan optimize
时,会显示SQLSTATE[HY000][2002]连接被拒绝
如果我尝试在命令行上连接MySQL RDS数据库,它会成功连接,因此看起来连接不是问题
我花了一段时间才找到post-install cmd的含义,但我在我的composer.json
文件中找到了它:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.3.*",
"doctrine/dbal": "^2.5",
"embed/embed": "^2.7",
"pda/pheanstalk": "~3.0",
"guzzlehttp/guzzle": "^6.2",
"intervention/image": "^2.3",
"approached/laravel-image-optimizer": "2.3.0",
"php-ffmpeg/php-ffmpeg": "0.9.3",
"laravelcollective/html": "^5.3",
"tymon/jwt-auth": "0.5.*",
"brozot/laravel-fcm": "^1.2",
"league/flysystem": "^1.0",
"cybercog/laravel-ban": "^2.1",
"pragmarx/firewall": "^1.0",
"predis/predis": "^1.1",
"aws/aws-sdk-php": "^3.31",
"dusterio/laravel-aws-worker": "^0.1.9",
"fideloper/proxy": "^3.3",
"aws/aws-sdk-php-laravel": "^3.1",
"league/flysystem-aws-s3-v3": "^1.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.0",
"symfony/css-selector": "3.1.*",
"symfony/dom-crawler": "3.1.*"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist"
}
}
对我来说,看起来没有什么不合适的地方
有什么问题吗
更新
我刚刚尝试将我的项目的composer.json
的内容复制并粘贴到新安装的Laravel中,它成功地创建了一个弹性Beanstalk环境,因此看起来我的composer.json
不是问题
可能是什么
更新#2
查看电子商务日志
,我发现:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `categories` where exists (select * from `topics` where `topics`.`category_id` = `categories`.`id`) order by `name` asc)
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000] [2002] Connection refused
调用此查询的唯一位置是我的AppServiceProvider.php
类。所以我删除了它,以及我添加到类中的所有其他内容,但是我仍然得到了与上面完全相同的错误,即使我删除了那个查询调用
为什么?回答我自己的问题,我的AppServiceProvider.php
文件(在boot()
方法中)中的代码导致它失败
我所做的是将所有代码包装在boot()
方法中:
public function boot()
{
if (!$this->app->runningInConsole())
{
// Code here
}
}
public function boot()
{
if (!$this->app->runningInConsole())
{
// Code here
}
}