AWS EB undefined RDS_HOSTNAME with Database hosts array empty

懵懂的女人 提交于 2021-02-11 14:35:34

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/65481464/aws-eb-undefined-rds-hostname-with-database-hosts-array-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!