Deploying a Web App with AWS: VPC, EC2, and RDS Simplified"

Pre-requisite:
1)VPC Setup with 2 public and 2 private, internet gateway and corresponding route tables.

2)launching ec2 instance in public subnet.

3)Create a RDS database
3.1)create and DB subnet group in two Availability zone(AZ).

3.2)Create a RDS Database

note: intialialize database name :corp
note: security group with inbound rule of vpc cidr

4)Install Apache webserver and PHP packages and configure webapp on ec2.

Installing mariabd mysql version

note: endpoint can be seen here

Install Apache web server and PHP packages

#change user to root
sudo su

#install required packages
dnf update -y
dnf install -y httpd php php-mysqli mariadb105

#start webserver service
systemctl start httpd
systemctl enable httpd

Configure DB connection settings
$cd /var/www
$mkdirinc
$cd inc
Create a new file called dbinfo.inc [using vi ] and add following content. Replace the values for the parameters based on your environment.
ref:aws-networking-exercises/Deploy-2-Tier-Web-Application at main · chetanagrawal/aws-networking-exercises · GitHub

Create application file corp.php in /var/www/html directory. a. You can use the corp.php file from github repo: https://github.com/chetanagrawal/aws-networking-exercises/tree/main/Deploy-2-Tier-Web-Application

Install mqsql client in the ec2 instance

# install pip (Amazon Linux 2023 does not have one by default)
dnf install -y pip

# install dependencies
dnf install -y mariadb105-devel gcc python3-devel

# install mysqlclient
pip install mysqlclient

Connect to MySQL (MariaDB) and query data

#Connect to database instance. Replace database endpoint with your database endpoint
mysql -h <database endpoint> -u admin –p

#Connect to database and query data

MySQL [(none)]> connect corp 
MySQL [corp]> select * from EMPLOYEES;

open the browser and hit the url publicip/corp.php

finally setup the public DNS in aws route 53

Open browser and access your webapp using http://YOUR_DOMAIN_NAME/corp.ph

Reference:

1)Udemy:AWS VPC and Networking in depth: Learn practically in 8 hrs