aws-ec2-web-application

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage

About The Project

This project is built to host a PHP application in AWS EC2 instance.

Built With

The project is built using,

  • AWS resources
  • Terraform
  • Ansible

Getting Started

Prerequisites

  • Create a free tier AWS account.
  • Create an IAM user with programmable access and make a note of the access and secret keys.

Installation

  1. Clone the repo
    git clone https://github.com/listentolearn/aws-ec2-dynamic-website
  2. Install Terraform
  3. Install Ansible

Usage

Hosting this application involves three parts.

Part 1: Standing up the Infrastructure

The infrastructure is setup in AWS using Terraform.

  1. cd into the infrastructure folder in the cloned repository.
  2. Run the following commands in order
    • terraform init
    • terraform plan
    • terraform apply

This will provision the required infrastructure and provides the EC2 instance public IP as the output.

Part 2: Installing the application

The next step is to install the required softwares in the EC2 instance and deploy the php application along with the MySQL database. This is done using ansible.

  1. Open the inventory.yml file under ansible directory and replace 0.0.0.0 with the public IP copied at the end of part 1.
  2. Replace the contents of the ./ansible/secrets/ssh.private with your private key. This is the private key corresponding to the public key used in Part 1 while provisioning the infrastructure using terraform.
  3. Run the ansible playbook using the below command
    • ansible-playbook -i inventory.yml application.yml

Part 3: Tear down the application

Run the below command to tear down the application.

- terrafrom destroy