Branding, UI Design / 20 June 2023 / by Qubit

Ecommerce Web Application Hosting on AWS

assets/img/blog/audio-to-text/speech-to-text-post.webp In this guide, I will be hosting a fully functional ecommerce web application on AWS. This includes creating a secure VPC, setting up an EC2 instance, configuring an RDS database, and deploying a LAMP-based web server to host your application. By the end, you’ll have a scalable, cloud-hosted ecommerce solution.

Architecture

Alt text


Steps 1: Create VPC

Start by creating a VPC to isolate your ecommerce environment with at least two availability zones for high availability.

  • Navigate to the VPC console and select “VPC and More.”
  • Configure your VPC with a CIDR block and subnets across multiple availability zones.
  • Ensure that the necessary internet gateway and route tables are set up to allow connectivity.

Alt text

Alt text

Alt text

Alt text

Alt text

Outcome: Your VPC should look like this:

Alt text


Steps 2: Create EC2 instance
  1. Launch a new EC2 instance using the Amazon Linux AMI.
  2. Create a new key pair for SSH access.

Alt text

Alt text

Create key pair

Alt text

Alt text

Edith network settings
  • Edit the network settings to associate the EC2 instance with the VPC created earlier.
  • Enable auto-assign public IP and configure security group rules to allow HTTP, HTTPS, and SSH access.

Alt text

  • Select the ecom vpc
  • enable auto assign public IP

Alt text

  • Still under network add security group rules HTTP & HTTPS
Ensure that the security group has rules for:

- **HTTP**: Port 80
- **HTTPS**: Port 443
- **SSH**: Port 22

Alt text

Alt text

Alt text

Alt text

Connect to the EC2 Instance
  • Use your key pair to SSH into the instance.
  • Update the package cache using:

Alt text

  • Update apt cache
sudo apt update

Alt text


Steps 3: Create MSQL RDS
  • Launch a MySQL RDS instance.
  • Configure the database with the following:

Alt text

Alt text

Alt text

	database:

	name: ecom-database
	Username; admin123
	password: mypassword

Alt text

Select the VPC

Alt text

  • Associate the RDS instance with the same VPC as the EC2 instance.
  • Ensure that the EC2 instance is on a public subnet for RDS connectivity.

Alt text

Alt text

Connect the EC2 instance to RDS:

Use the EC2 instance to connect to the RDS database:

mysql -h ecom-database.cslgmy1hb3xc.us-east-2.rds.amazonaws.com -u admin123 -p

If connection fails, ensure the EC2 security group allows inbound MySQL traffic on port 3306.

To connect to the RDS subnet this is neccessary

  • Go to your EC2 instance
    • click on Actions > Networking > connect RDS Database

Alt text

Alt text


Steps 4: Setup EC2 (Web Server )
Install LAMP Stack:
sudo apt update
sudo apt install lamp-server^

Alt text

  • Install MSQL Client
sudo apt install mysql-client

Alt text

  • Verified that apache is installed
cd /var/www/html

Alt text

Clone the ecom site from GitHub
sudo git clone https://github.com/Jhoode/Electronix-Website.git

Alt text

Update the connection file (connection.inc.php) with the RDS endpoint, username, and password.

cd Electronix-Website/ecom/

Alt text


Step 5: Setup Database
Connect to the database
mysql -h ecom-database.cslgmy1hb3xc.us-east-2.rds.amazonaws.com -u admin123 -p

Note: if this does not connect you directly to the data base you need to go to the EC2 security group and add the mysql ports 3306 from anywhere.

Alt text

Note: if you don’t see the database (ecom) just create a new

create database ecom;

Alt text

use ecom
show tables;

Alt text

Create tables

copy the ecom.sql from the git repo

Alt text

Copy everything from line 30 to 353

Alt text

Paste in the ecom database

Alt text

show tables;

Alt text

Exit the database

Alt text

Update the following

  • Database endpoint
  • Database username
  • Database password
  • EC2 instance name
  • EC2 public IP

Alt text

Go to the Url:

3.145.170.165/Electronix-Website/ecom/

Alt text

Alt text

Note: go into the appache to point the server to the index.apache


Conclusion

You’ve successfully deployed a scalable ecommerce application on AWS using VPC, EC2, RDS, and a LAMP stack. This architecture is highly scalable and can be further enhanced with load balancers, caching layers, and auto-scaling groups for production readiness. `

Tags: