DEV Community

Khushi Nandwani
Khushi Nandwani

Posted on • Edited on

Deploying PHP Web Applications with Amazon EC2 and Aurora MySQL πŸ“¦

Architecture Diagram

πŸ“˜ Introduction

This project demonstrates the deployment of a PHP-based web application on Amazon EC2 and its integration with an Amazon Aurora (MySQL-compatible) database. The objective is to provision compute and database resources, configure secure connectivity, install a web application stack, and validate database interaction using PHP.

The project follows AWS best practices using free-tier eligible resources and focuses on clarity, reproducibility, and proper cleanup.

πŸ—οΈ Architecture Overview

The architecture consists of an Amazon EC2 instance hosting an Apache web server with PHP, connected to an Amazon Aurora MySQL-compatible database cluster within the same VPC. The EC2 instance handles application logic, while Aurora manages persistent data storage.

Communication between services is controlled using security groups, ensuring secure and private connectivity.

🧩 Architecture Components

  • Amazon EC2
    • Amazon Linux AMI
    • Apache HTTP Server
    • PHP application runtime
  • Amazon Aurora (MySQL Compatible)
    • Managed relational database
    • Dev/Test configuration
    • Single writer instance
  • Apache HTTP Server
    • Serves PHP web pages
  • PHP
    • Handles database connectivity and logic
  • MySQL Client (MariaDB)
    • Used to validate database access
  • VPC & Security Groups
    • Default VPC
    • HTTP access enabled
    • Database access restricted to EC2
  • Key Pair
    • Secure EC2 authentication

🎯 Why This Project?

  • To understand real-world EC2–RDS integration
  • To gain hands-on experience with Amazon Aurora
  • To deploy a functional web application stack
  • To practice AWS resource lifecycle management
  • To build a portfolio-ready cloud project

✨ Key Features

  • End-to-end AWS service integration
  • Secure database connectivity
  • PHP-based application logic
  • Free-tier compatible setup
  • Structured cleanup to prevent unnecessary costs

πŸ› οΈExecution Workflow

I. EC2 Instance Setup

  • Launch an EC2 instance with Amazon Linux AMI

Creating an EC2 instance

  • Select a free-tier eligible instance type (t2.micro / t3.micro)

Select a free-tier eligible instance type (t2.micro / t3.micro)

  • Create and download an RSA key pair (.pem)

Create and download an RSA key pair (.pem)

  • Allow HTTP traffic in the security group

Allow HTTP traffic in the security group

  • Launch and verify the instance

Launch and verify the instance

Launch and verify the instance

II. Amazon Aurora Database Setup

  • Create an Amazon Aurora (MySQL Compatible) database

Creating Aurora DB

Creating Aurora DB

  • Select Dev/Test template

Select Dev/Test template

  • Configure DB cluster identifier and credentials

Configure DB cluster identifier and credentials

  • Use Aurora Standard storage

Use Aurora Standard storage

  • Select burstable instance class

Select burstable instance class

  • Don't create aurora read replicas

Aurora Read Replicas

  • Connect the database to the existing EC2 instance

Connect to DB

  • Use default subnet group and VPC security group

default subnet group

default VPC SG

  • In additional configuration, give a name to initialize database name

database name

  • Create the database and wait for provisioning Creating Database

III. Connect to EC2 Instance

  • Open EC2 Dashboard

EC2 Dashboard

  • Select the instance and Click Connect

Connect

  • Choose EC2 Instance Connect

Connecting EC2 Instance

IV. Install and Configure Apache Web Server

sudo dnf update -y

Updating

sudo dnf install -y httpd

Installing httpd

sudo systemctl start httpd

Starting httpd

sudo systemctl enable httpd
Enabling httpd

V. Install PHP and Required Extensions

sudo dnf install -y php php-mysqlnd

Installing php

sudo systemctl restart httpd

Restarting httpd

sudo systemctl status httpd

Checking httpd status

php --version

Checking php version

VI. Install MySQL Client (MariaDB)

sudo dnf install -y mariadb105

Installing Mariadb

mysql --version

Checking mysql version

VII. Configure Database Environment Variables

export USERNAME=admin
export PASSWORD=newadmin12345
export DATABASE=myapp

export username and password

export servername

exporting aurora cluster endpoint name

VIII. Create PHP Application Files

  • Create a PHP page to establish database connectivity

Database Connectivity Page

Database Connectivity Page

  • Create a PHP page to count total page views stored in the database

PHP page

πŸ“‚ Full Repository

All source code, configuration steps, and documentation are available here: https://github.com/Knandwani07/aws-database-architectures/tree/main/php-ec2-aurora-deployment

IX. Restart Web Server

sudo systemctl restart httpd

Restarting the Web Server

X. Application Validation

  • Access the EC2 public IP in a browser

Accessing public IP

  • Confirm page view count increments correctly

Page view

XI. Resource Cleanup

  • Delete DB instance

Deleting DB instance

  • Delete Aurora database cluster

Deleting Aurora DB Cluster

  • Terminate EC2 instance

Terminating EC2 Instance

  • Delete key pair

Deleting Key Pair

  • Verify all resources are removed

βœ… Conclusion

This project demonstrates a complete workflow for deploying a PHP web application backed by Amazon Aurora. It provides practical experience with AWS compute, managed databases, security configurations, and application-level integration.

The structured approach ensures clarity, scalability, and cost awareness, making this project suitable for learning, portfolio use, and interview discussions.

🀝 Let’s Connect

For feedback, collaboration, or cloud discussions:

LinkedIn: https://www.linkedin.com/in/khushi-nandwani/

GitHub: https://github.com/Knandwani07

Top comments (0)