数据库主机数组为空

huangapple go评论56阅读模式
英文:

Database hosts array is empty

问题

我正在使用弹性 Beanstalk 部署我的 Laravel 项目。我已经在 AWS Beanstalk 配置中设置了我的环境属性。

当我 SSH 到 Beanstalk EC2 并输入任何 php artisan 命令,比如 php artisan migrate,我收到错误消息:"Database hosts array is empty. (SQL: select * from information_schema.tables where table_schema = ? and table_name = migrations and table_type = 'BASE TABLE')"。

我有一个有效的 RDS 数据库和正常工作的 Laravel 项目。为什么我不能输入任何 artisan 命令?当我手动复制到 Beanstalk EC2 时,artisan 命令是有效的。为什么它不监听 AWS 环境属性?

英文:

I am using elastic Beanstalk deployment for my Laravel project.I have set up my env properties in AWS beanstalk configuration.
数据库主机数组为空

When i ssh to beanstalk ec2 and type any php artisan commands like php artsan migrate, i got the error "Database hosts array is empty. (SQL: select * from information_schema.tables where table_schema = ? and table_name = migrations and table_type = 'BASE TABLE')".
I have a valid RDS database and working laravel project.Why can't i type any of the artisan commands.The artisan commands are working when i am manually copying to the beanstalk ec2.Why it is not listening to aws env properties ?

答案1

得分: 1

如果在手动将项目复制到Elastic Beanstalk EC2实例并通过SSH运行它们时,工匠命令正常工作,但通过SSH运行它们时不正常,这表明环境变量在使用SSH时没有正确加载。

当您手动复制项目时,环境变量可能是从项目目录中的.env文件中获取的。然而,通过SSH运行命令时,需要显式设置环境变量。

A. 使用以下命令通过SSH登录到EC2实例:

ssh -i your-key.pem ec2-user@your-instance-ip

B. 将当前工作目录更改为您的Laravel项目的根目录。例如:

cd /var/www/html/your-laravel-project

C. 在运行工匠命令之前,使用export命令为环境变量设置前缀。例如:

export DB_HOST=your-db-host
export DB_USERNAME=your-db-username
export DB_PASSWORD=your-db-password
php artisan migrate

通过在运行工匠命令之前显式导出环境变量,您确保这些变量已设置并可供Laravel应用程序使用。

如果有许多环境变量需要设置,手动导出每个变量可能会很繁琐。在这种情况下,您可以考虑创建一个脚本,该脚本导出所有所需的环境变量,然后运行工匠命令。

英文:

If the artisan commands work when you manually copy the project to the Elastic Beanstalk EC2 instance but not when you run them through SSH, it suggests that the environment variables are not being loaded properly when using SSH.

When you manually copy the project, the environment variables might be sourced from the .env file present in your project directory. However, when running commands through SSH, the environment variables need to be set explicitly.

A. SSH into the EC2 instance using the command:

ssh -i your-key.pem ec2-user@your-instance-ip

B. Change the current working directory to the root directory of your Laravel project. For example:

cd /var/www/html/your-laravel-project

C. Run the artisan commands prefixed with the export command to set the environment variables explicitly. For example:

export DB_HOST=your-db-host
export DB_USERNAME=your-db-username
export DB_PASSWORD=your-db-password
php artisan migrate

By explicitly exporting the environment variables before running the artisan commands, you ensure that the variables are set and available for the Laravel application to use.

If you have many environment variables to set, it might be cumbersome to manually export each one. In that case, you could consider creating a script that exports all the required environment variables and then runs the artisan command.

huangapple
  • 本文由 发表于 2023年6月19日 19:56:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76506379.html
  • amazon-elastic-beanstalk
  • amazon-web-services
  • environment-variables
  • laravel
  • laravel-artisan
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定