This project automates the deployment of a WordPress site on an AWS EC2 instance with an RDS MySQL database. The stack includes:
- ✅ AWS EC2 Instance with Docker
- ✅ AWS RDS MySQL database
- ✅ Dockerized WordPress
- ✅ Ansible for automation
- ✅ Terraform for infrastructure as code
- ✅ Cloudflare for domain pointing (subdomain support)
- ✅ Automatic WordPress installation via WP-CLI
- AWS account with credentials configured
- Cloudflare account with API Token & Zone ID
- Terraform installed (
>= 1.2.0) - Ansible installed
- SSH key pair (for EC2 access)
.envfile in the root directory
- AWS Account with IAM Access
- Terraform (
>= 1.2.0) - Ansible installed
- Cloudflare Account with API Token & Zone ID
- SSH key for EC2 access
git clone https://github.com/joshiharshal/EC2-RDS-Wordpress.git
cd EC2-RDS-Wordpress
terraform init
terraform apply -auto-approvechmod +x deploy.sh
./deploy.shThis script:
- Retrieves instance and database details
- Creates a
.envfile with database credentials - Copies
.envto the instance - Runs the Ansible playbook
- Deploys WordPress with Docker
Create a .env file in the root of the project by copying the example:
cp .env.example .env
# --- Database Configuration (Auto-injected by script) ---
WORDPRESS_DB_HOST=<RDS Host will be auto-injected>
WORDPRESS_DB_USER=admin
WORDPRESS_DB_PASSWORD=adminpassword
WORDPRESS_DB_NAME=wordpress_db
# --- WordPress Configuration ---
WORDPRESS_SITE_TITLE=My Awesome Blog
WORDPRESS_ADMIN_USER=admin
WORDPRESS_ADMIN_PASSWORD=admin123
WORDPRESS_ADMIN_EMAIL=admin@example.com
# --- Cloudflare Configuration ---
CLOUDFLARE_API_TOKEN=your_cloudflare_api_token
CLOUDFLARE_ZONE_ID=your_cloudflare_zone_id
SUBDOMAIN=
ROOT_DOMAIN=- Website: http://harshal.joshiharshal.cloud
- Admin Panel: http://harshal.joshiharshal.cloud/wp-admin
- Admin Credentials:
- Username:
admin - Password:
Admin@123
- Username:
To delete all resources:
terraform destroy -auto-approve- Harshal Joshi - GitHub