Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

r3mmel's avatar

eb deploy in Laravel 5.3 - AWS Beanstalk

How to prevent .env to be erased each time I "eb deploy" to my beanstalk instance?

I'm using Git and EB CLI. Each time I run "eb deploy", my .env file erased and "bootstrap" and "storage" folder don't have folder permission anymore.

How to prevent this from happening? I'm following this guide for deploying Laravel on AWS. http://blog.goforyt.com/laravel-aws-elastic-beanstalk-dev-guide/

btw, I'm using AWS Free Tier.

Here's my .gitignore:

/node_modules /public/storage /storage/*.key /vendor /.idea Homestead.json Homestead.yaml .env

Elastic Beanstalk Files

.elasticbeanstalk/* !.elasticbeanstalk/.cfg.yml !.elasticbeanstalk/.global.yml

0 likes
2 replies
edev's avatar
edev
Best Answer
Level 3

Hi,

as mentioned in blog post: http://blog.goforyt.com/laravel-aws-elastic-beanstalk-dev-guide/ it is neccessary to create .ebextensions folder and put files in it. Commit and then push. Thend do: eb deploy

File: 00environmentVariables.config Content: option_settings:

  • namespace: aws:elasticbeanstalk:application:environment option_name: APP_ENV value: production
  • namespace: aws:elasticbeanstalk:application:environment option_name: APP_KEY value: [key value here]
  • namespace: aws:elasticbeanstalk:application:environment option_name: APP_DEBUG value: true
  • namespace: aws:elasticbeanstalk:application:environment option_name: APP_LOG_LEVEL value: debug
  • namespace: aws:elasticbeanstalk:application:environment option_name: APP_URL value: [hostanme of the Ec2 instance]
  • option_name: DB_HOST value: [rds instance name]
  • option_name: DB_PORT value: 3306
  • option_name: DB_DATABASE value: ebdb
  • option_name: DB_USERNAME value: [username here]
  • option_name: DB_PASSWORD value: [password here]

And second one: 01artisan.config Content:

container_commands: 01migrateSeed: command: "php artisan migrate"

Please follow instructions how to properly create this file, since they need to be yaml files.

Regards, Damir

1 like
r3mmel's avatar

@edev Thank you. I already did this and it is working. :)

in your "container_commands", did you put "php artisan optimize" in there to optimize your production after each every "eb deploy"?

I just put to commands in there and remove "migrate", I put "artisan optimize" and "artisan route:cache". Is it okay to do that?

Please or to participate in this conversation.