You are currently viewing WordPress Website Deployed with Docker Compose on AWS Cloud

WordPress Website Deployed with Docker Compose on AWS Cloud

Deploying a WordPress website using Docker Compose allows you to run WordPress and its database in isolated containers, making setup, management, and scaling much simpler. With Docker Compose, you can define your entire WordPress environment—including WordPress itself and a MySQL database—in a single configuration file.

Update your system

sudo apt update && sudo apt upgrade -y

Install required packages before Docker

sudo apt install -y ca-certificates curl gnupg lsb-release

Add Docker’s official GPG key

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Add Docker repository

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Update repo and install Docker Engine + Compose plugin

sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

Check Docker and Compose versions

sudo docker --version && docker compose version

Create project folder

mkdir wordpress-docker

Enter the folder

cd wordpress-docker

Open the file with nano (or any text editor):

nano docker-compose.yml

Paste the content you provided:

version: '3.8'

services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  wordpress:
    image: wordpress:latest
    ports:
      - "80:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    depends_on:
      - db

volumes:
  db_data:

Save and exit nano: Press CTRL + O → Enter → CTRL + X.

Run Docker Compose

sudo docker compose up -d

This will:

1. Pulls images (Downloads the WordPress and MySQL images from Docker Hub if they are not already on your server)

2. Creates containers (Builds the wordpress and db containers as defined in your docker-compose.ym)

3. Starts containers in the background (-d = detached mode)

After running this, check that both containers are running:

sudo docker ps

If everything works, you should see wordpress and db containers listed as Up.

Access WordPress

Open your browser and go to: (http://<your-server-public-ip>/)

You will see the WordPress installation page. Complete it:

  • Site Title
  • Admin Username & Password
  • Email

Done! WordPress is running.

(A). Update package lists

sudo apt update

(B). Install Nginx

sudo apt install nginx -y

(C). Enable Nginx to start on boot

sudo systemctl enable nginx

(D). Start Nginx

sudo systemctl start nginx

(E). Create a new site configuration

sudo nano /etc/nginx/sites-available/mindgnite

(F). Add the server block (Paste the following inside:)

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

(G). Test Nginx configuration

sudo nginx -t

(H). Restart Nginx

sudo systemctl restart nginx

Create Nginx site configuration

sudo nano /etc/nginx/sites-available/wordpress

Paste this server block inside

Enable the site

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/

Remove the default site (optional, to avoid conflicts)

sudo rm /etc/nginx/sites-enabled/default

Test Nginx configuration

sudo nginx -t

Restart Nginx

sudo systemctl restart nginx

Update package lists

sudo apt update

Install Certbot for Nginx

sudo apt install certbot python3-certbot-nginx -y

Request and apply SSL certificate

sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

#Your Webpage is working On Online………..