AWS EB 未定义 RDS_HOSTNAME,数据库主机数组为空
AWS EB undefined RDS_HOSTNAME with Database hosts array empty
目前在 Laravel 项目中使用 AWS EB 和 RDS。
当我运行
php artisan migrate --seed
然后我得到
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
和
Database hosts array is empty. (SQL: select * from
information_schema.tables where table_schema = ? and table_name =
migrations and table_type = 'BASE TABLE')
我没有使用 .env 文件,而是在 EB 配置中定义这些变量,例如
和我的 ./config/database.php 文件
测试将变量的前缀更改为 RDS_ 而不是 EB 中的 DB_ 但这并没有解决问题。
根据 Elastic Beanstalk 文档 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.
因此 Elastic Beanstalk 会将这些环境变量传递给 Apache HTTP 服务器进程,但不会传递给 Linux shell 您所在的 运行 那个 php
命令。
根据文档 here, you need to use the get-config 脚本将这些环境变量值提取到您的 shell。
因此您需要为所有人执行此操作
/opt/elasticbeanstalk/bin/get-config environment -k RDS_USERNAME
这将打印 RDS_USERNAME 的值。然后将其导出以用于其他命令
export RDS_USERNAME="value"
对所有人都这样做 - RDS_HOSTNAME、RDS_USERNAME、RDS_PASSWORD 和 RDS_DB_NAME。那么如果你 运行
export
你一定能看到RDS_HOSTNAME、RDS_USERNAME、RDS_PASSWORD和RDS_DB_NAME以及前面各自的值。
完成后,您 运行
php artisan migrate --seed
然后你会得到预期的结果
目前在 Laravel 项目中使用 AWS EB 和 RDS。
当我运行
php artisan migrate --seed
然后我得到
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
和
Database hosts array is empty. (SQL: select * from information_schema.tables where table_schema = ? and table_name = migrations and table_type = 'BASE TABLE')
我没有使用 .env 文件,而是在 EB 配置中定义这些变量,例如
和我的 ./config/database.php 文件
测试将变量的前缀更改为 RDS_ 而不是 EB 中的 DB_ 但这并没有解决问题。
根据 Elastic Beanstalk 文档 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.
因此 Elastic Beanstalk 会将这些环境变量传递给 Apache HTTP 服务器进程,但不会传递给 Linux shell 您所在的 运行 那个 php
命令。
根据文档 here, you need to use the get-config 脚本将这些环境变量值提取到您的 shell。
因此您需要为所有人执行此操作
/opt/elasticbeanstalk/bin/get-config environment -k RDS_USERNAME
这将打印 RDS_USERNAME 的值。然后将其导出以用于其他命令
export RDS_USERNAME="value"
对所有人都这样做 - RDS_HOSTNAME、RDS_USERNAME、RDS_PASSWORD 和 RDS_DB_NAME。那么如果你 运行
export
你一定能看到RDS_HOSTNAME、RDS_USERNAME、RDS_PASSWORD和RDS_DB_NAME以及前面各自的值。
完成后,您 运行
php artisan migrate --seed
然后你会得到预期的结果