0

I am using elastic Beanstalk deployment for my Laravel project.I have set up my env properties in AWS beanstalk configuration. enter image description here

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

This doesnt satisfy my requirement
You can try loading the environment variables using a script or by sourcing the .env file before running the artisan commands. For example: source /var/www/html/your-laravel-project/.env php artisan migrate
It's possible that there is a conflict between the environment variables set in the AWS Beanstalk configuration and the environment variables defined in the .env file of your Laravel project. When running artisan commands manually after copying the project, the environment variables from the .env file are used, overriding the AWS environment properties. Make sure there is no conflicting configuration between the two sources.
no there is not any conflict between Beanstalk env and projects .env
try eb php artisan migrate
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.