DEV Community

Edith Ogechi Odo
Edith Ogechi Odo

Posted on Edited on

Steps I took in Deploying a PHP File Manager on AWS with Docker, Amazon S3, RDS and IAM Roles

As part of my DevOps Engineering training at Abuja Data School, I worked on deploying a PHP File Manager application on AWS.

The goal was to move beyond simply running an application locally and understand how different AWS services can work together to support a real-world application.

In this project, I used Amazon EC2 to host the application, Amazon RDS for database management, Amazon S3 for image storage, and IAM roles to manage permissions securely.

Here's how I approached the project.

  1. Project Architecture

The application uses a three-tier approach involving the application server, database, and object storage.

Architecture components

1) Amazon EC2: Hosts the PHP application.
2) Docker: Containerizes the application.
3) Amazon RDS: Stores image metadata, including titles, filenames, and file sizes.
4) Amazon S3: Stores the actual uploaded image files.
5) IAM Role: Grants the EC2-hosted application permission to access S3 without hardcoding AWS access keys.
6) AWS SDK for PHP: Enables the application to interact with S3.

  1. Launching the EC2 Instance

I started by launching an Ubuntu EC2 instance.

I configured the security group to allow:
a) SSH access for server administration.
b) TCP port 8000 for accessing the web application.

After launching the instance, I connected to it through SSH.

  1. Installing Docker

I installed Docker and Docker Compose on the EC2 instance.

Docker was important because I wanted the application to run in an isolated and reproducible environment. I verified the installation before proceeding.

  1. Cloning the Application Repository

I cloned the project repository onto the EC2 instance:

git clone https://github link
cd php_file

I inspected the project structure to understand the PHP application before proceeding.

  1. Creating the RDS Database

Next, I created an Amazon RDS MySQL database.

I configured the database and created the application schema.

The database was responsible for storing image metadata rather than the actual image files.

I also configured the database connection details as environment variables so that sensitive credentials would not be hardcoded in the application.

  1. Creating the S3 Bucket

I created an S3 bucket named ' php-file-manager-images'.

The bucket was kept private, with Block Public Access enabled.

The application would use the bucket to store uploaded images and retrieve them when users accessed the application.

This separation allowed the database and object storage to handle different responsibilities.

  1. Configuring IAM Permissions

Instead of placing AWS access keys inside the application, I created an IAM role named:

'EC2-PHP-FileManager-S3-Role'

I attached the role to the EC2 instance and configured its S3 permissions.

This allowed the application to obtain AWS credentials through the EC2 instance role.

  1. Integrating Amazon S3 into the PHP Application

I installed the AWS SDK for PHP using Composer:

composer require aws/aws-sdk-php:^3.0

I then modified the application's configuration and action files to integrate S3.

The application was updated to support:

  • Uploading images to S3.
  • Retrieving images from S3.
  • Replacing existing images.
  • Deleting images from S3.
  • Saving image metadata in RDS.
  1. Creating the Dockerfile

I configured the Dockerfile using the PHP Apache base image.

The container required PHP extensions for MySQL connectivity and XML support.

I also configured PHP upload limits to support image uploads.

The application was then prepared to run inside Docker.

  1. Configuring Docker Compose

I used Docker Compose to configure the application container.

The configuration included:

  • Application port mapping from EC2 port 8000 to container port 80.
  • Database environment variables.
  • AWS region and S3 bucket configuration.
  • Application source and Composer dependency volumes.

I stored sensitive configuration values in a .env file and excluded that file from Git using '.gitignore' .

  1. Building and Running the Application

I built and started the application using:

docker compose up -d --build

I checked the running container:

docker ps

I also verified that the AWS SDK was available inside the container and tested connectivity to RDS and S3.

  1. Testing the Application

Finally, I accessed the application through the EC2 public IP and port 8000.

I tested the core functionalities:

  • Uploading an image.
  • Displaying an uploaded image.
  • Editing image details and replacing an image.
  • Deleting an image.

The operations worked successfully, with image files stored in S3 and their metadata stored in RDS.

Lessons I Learned With this Project:

This project helped me understand;

  1. How to deploy a containerized application on AWS EC2.
  2. How to connect a PHP application to Amazon RDS.
  3. How to use Amazon S3 for object storage.
  4. How IAM roles provide application-level AWS permissions.
  5. How Docker Compose simplifies application configuration.
  6. Why separating application data from file storage is useful in cloud architecture.

This project gave me practical experience integrating multiple AWS services into one working application.
It also reinforced the importance of security, service integration, and proper application configuration during cloud deployment.

I'm looking forward to building on this experience as I continue my journey in DevOps Engineering.

AWS #DevOps #Docker #AmazonS3 #AmazonRDS #CloudComputing #PHP

Top comments (0)