数据库主机数组为空的AWS EB未定义RDS_HOSTNAME [英] AWS EB undefined RDS_HOSTNAME with Database hosts array empty

查看:94
本文介绍了数据库主机数组为空的AWS EB未定义RDS_HOSTNAME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前在使用带有RDS的AWS EB的Laravel项目中.

我跑步时

  php artisan migration --seed 

然后我得到

PHP注意:未定义的索引:第5行/var/app/current/config/database.php中的RDS_HOSTNAME

PHP注意:未定义的索引:第6行/var/app/current/config/database.php中的RDS_USERNAME

PHP注意:未定义的索引:第7行/var/app/current/config/database.php中的RDS_PASSWORD

PHP注意:未定义的索引:第8行/var/app/current/config/database.php中的RDS_DB_NAME

数据库主机数组为空.(SQL:从*中选择*information_schema.tables其中table_schema =?和table_name =迁移和table_type ='BASE TABLE')

我没有使用.env文件,而是在EB配置中定义了这些变量,例如

和我的./config/database.php文件

已测试将变量的前缀更改为RDS_而不是EB中的DB_,但这不能解决问题.

解决方案

根据Elastic Beanstalk文档

Currently in a Laravel project using AWS EB with RDS.

When I run

php artisan migrate --seed

then I get

PHP Notice: Undefined index: RDS_HOSTNAME in /var/app/current/config/database.php on line 5

PHP Notice: Undefined index: RDS_USERNAME in /var/app/current/config/database.php on line 6

PHP Notice: Undefined index: RDS_PASSWORD in /var/app/current/config/database.php on line 7

PHP Notice: Undefined index: RDS_DB_NAME in /var/app/current/config/database.php on line 8

and

Database hosts array is empty. (SQL: select * from information_schema.tables where table_schema = ? and table_name = migrations and table_type = 'BASE TABLE')

I'm not using a .env file but defining these variables in EB configuration, like

and my ./config/database.php file

Tested changing the variables' prefix to RDS_ instead of DB_ in EB but that didn't solve the problem.

解决方案

Per the Elastic Beanstalk documentation here:

Note: Environment properties aren't automatically exported to the shell, even though they are present in the instance. Instead, environment properties are made available to the application through the stack that it runs in, based on which platform you're using.

So Elastic Beanstalk is going to pass those environment variables to the Apache HTTP server process, but not the Linux shell where you are running that php command.

Per the documentation here, you need to use the get-config script to pull those environment variable values into your shell.

So you'll need to do this for all

/opt/elasticbeanstalk/bin/get-config environment -k RDS_USERNAME

which will print the value of RDS_USERNAME. Then export it to use in other commands

export RDS_USERNAME="value"

Do that for all - RDS_HOSTNAME, RDS_USERNAME, RDS_PASSWORD and RDS_DB_NAME. Then if you run

export

you must be able to see RDS_HOSTNAME, RDS_USERNAME, RDS_PASSWORD and RDS_DB_NAME and the respective value in front.

Once that's done and you run

php artisan migrate --seed 

you'll then get as expected

这篇关于数据库主机数组为空的AWS EB未定义RDS_HOSTNAME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆