Laravel Elastic Beanstalk running migrations

Viewed 18

I have setup elastic beanstalk for my laravel application. I use environment properties:

enter image description here

The application works fine, but when I run migrations this fails as the creds for the db have not been added to .env file (I wanted to run the migrations using ebextensions). Is there a way to run migrations where it uses environment properties?

The migrations run as part of the deployment.

1 Answers

I also ran into this problem. The proper solution is to not use environment properties within the EB console. I put my .env on a S3 bucket and copy it in on deploy. This also helps with maintaining ENV variables between for ex. green/blue deployments and if you ever need to upgrade EB environment platforms (for ex. when a new PHP/Python/NodeJS version is released or Amazon Linux version)

This an example for an ebextension which copies over .env variables from S3: https://github.com/rennokki/laravel-aws-eb/blob/master/.ebextensions/00_copy_env_file.config

You could also copy your .env file from the deployment folder to where your project is located with this script

sudo cp /opt/elasticbeanstalk/deployment/env /var/www/html/.env && sudo chown ec2-user:webapp .env && sudo chmod 644 .env
  • copy over env file from deployment folder with cp
  • change user and group of file with chown
  • change file rights with chmod
Related