简体   繁体   中英

How to setup Laravel application in AWS Elastic Beanstalk using external RDS database

I want to start deploying my laravel app to production. To avoid changing AWS config in the near future, I decided to try to add continuous integration. To do this I'm using elastic beanstalk and pushing the code there using another AWS tool. All this is working perfectly. I put a test message in /public/index.php to output "hello world" and it works as expected when going to the URL. When I remove this text and run my laravel app as normal, I get a 500 internal server error. I'm not sure all what elastic beanstalk does on deployment for laravel apps. Because of this I'm not sure if this error is occurring from a bad DB connection or laravel app not fully setup yet.

I created an RDS DB instance outside of elastic beanstalk. I am able to access this from sequel pro and I added the database I will use to store all my data. I added all the necessary db connection values (host, port, database, username, password) to /config/database.php and the elastic beanstalk server configuration environment variables.

I've searched online for days for info but haven't found anything specific to this. Also part of my issue is a lack of understanding of how laravel is setup during a deployment in beanstalk. Is there something with /.ebextensions that will help me accomplish these goals?

When I deploy my code I need to make sure all vendor files are installed through composer and then I also need to make sure all database migrations/changes happen. I want to automate as many steps as possible so I can just push up code changes and server will change code and keep working.

I also want to make sure there isn't anything I'm missing for setting up my db connection. Are there any other files in laravel I need to setup or something in elastic beanstalk I need to have configured? I'm keeping my db open to all connections and then I can tighten restrictions later

EDIT: My database may not be configured correctly yet, but that appers to not be source of the issue. I think my issue is knowing what scripts and how to run them during deployment. I want to make sure composer and php artisan migrate is ran to keep everything up to date. How can I do this with elastic beanstalk?

This is a little off topic but with my experience I do not recommend using beanstalk to achieve a good workflow pushing and deploying. I recommend you to use Forgelaravel.com to deploy your GitHub repository. In forge Laravel you will be able to create a server from AWS and it will automatically create database connections and stuffs, then with just one click you can deploy to the server and keep a good workflow.

Given that we're speaking of a Laravel application, this 500 Server Error

在此处输入图片说明

often occurs when one is creating new infrastructure. Why? It's likely to forget to add the environment variables to the EB environment.

Simply go to that EB environment configuration, then under software modify to include at least the following environment properties

  • APP_DEBUG (can be, for example, false)
  • APP_KEY (this is the key generated with php artisan key:generate )
  • APP_NAME (tiagoPeres)

在此处输入图片说明

Then the issue will be gone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM