Deploy Laravel app to Elastic Beanstalk(Amazon EC2)

Laravel is an open source, model-view-controller (MVC) framework for PHP. This tutorial walks you through the process of generating a Laravel application, deploying it to an AWS Elastic Beanstalk environment, and configuring it to connect to an Amazon Relational Database Service (Amazon RDS) database instance.

1. Zip whole source code into a zip file.

Sample of zip file as following.

  • + app
     + public
     + …

Note: You don’t care to database connection in this step. We will setting them in [Environment Properties] later

2. Create a new environment for Elastic Beanstalk

Access to Elastic Console.

1. Tier: Chon web server.
 2. Platform: php
 3. Application code: Upload your source code (Ziped in step 1)
 4. Click Create environment.

This action will be take a few minutes.

3. Config Document root
 After create environment successful, you can access to Url of Environment. But you will see 403 error.

the reason is Laravel config document root is [public] folder. So you need to change it in [Configuration/Software Configuration]

Click Apply and try again.

Wow, congratulation, you have done with Laravel and Elastic Beanstalk. Only final step, it is Config database :)

4. Config database
 Access [Configuration/Data Tier/Create a new RDS database]

After create database successful, access [Configuration/Software Configuration] again and fill info [Environment Properties] as following

Note: Usually, database name is [ebdb]. However, you can view database detail at [Configuration/Data Tier/View in RDS Console]

DONE. You have been DONE. At this step, laravel can access to database normal.

BONUS++: Use MySQL workbench to access database.

1. Create key pair for EC2 instance. Access EC2 console/NETWORK & SECURITY/Key Pairs
 Create keypair and download it.

Run this command to set keypair is not publicly viewable.

chmod 400 demo.pem

2. Back to Elastic Beanstalk console. Choose Configuration/Instances. select the key pair for [EC2 key pair]. If you don’t see the new keypair then click button [refresh]

Click Apply and wait…
 Note: After this step, maybe the old your instance will be terminated and new instance will be created with your keypair.

Don’t care the old instance, from now we work only with the new instance.

3. Use MySQL workbench to access database.
 See my sample config

DONE. That all. Have fun :)