- Prerequisites
- Step 1: Launch an EC2 Instance
- Step 2: Connect to Your EC2 Instance
- Step 3: Install Docker and Docker Compose
- Step 4: Create Docker Compose File for WordPress
- Step 5: Start the WordPress and MySQL Containers
- Step 6: Configure WordPress
- Step 7: Access Your WordPress Site
- Additional Configuration (Optional)
- Reference
Prerequisites
- AWS Account
- Basic knowledge of AWS EC2 and SSH
- Docker and Docker Compose installed on your local machine
Step 1: Launch an EC2 Instance
- Log in to the AWS Management Console.
- Navigate to the EC2 Dashboard and click “Launch Instance”.
-
Choose an Amazon Machine Image (AMI): Select Amazon Linux 2 AMI (recommended).
-
Choose an Instance Type: Select the instance type (t2.micro is eligible for the free tier).
-
Configure Instance Details: Default settings are usually sufficient. Ensure the instance is in the desired VPC and subnet.
-
Add Storage: Default 8 GB is typically sufficient, but you can adjust based on your needs.
-
Add Tags:Optionally, add tags to help identify your instance.
- Configure Security Group:
- Create a new security group or select an existing one b. Add rules to allow HTTP (port 80), HTTPS (port 443), and SSH (port 22) access.
- Review and Launch:
- Review your settings and click “Launch”.
- Choose an existing key pair or create a new one for SSH access. Make sure to download the key pair if you create a new one.
Step 2: Connect to Your EC2 Instance
-
Open your terminal and navigate to the directory where your key pair (.pem file) is located.
-
Connect to your EC2 instance using SSH:
ssh -i "your-key-pair.pem" ec2-user@your-ec2-public-ip
Step 3: Install Docker and Docker Compose
- Update the package index:
sudo yum update -y
- Install Docker:
sudo amazon-linux-extras install docker -y sudo service docker start sudo usermod -a -G docker ec2-user
- Install Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
- Verify installation: docker-compose –version
Step 4: Create Docker Compose File for WordPress
- Create a new directory for your WordPress project:
mkdir wordpress && cd wordpress
- Create a docker-compose.yml file:
nano docker-compose.yml
- Add the following content to the docker-compose.yml file:
version: '3.1' services: wordpress: image: wordpress:latest restart: always ports: - 80:80 environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_USER: exampleuser WORDPRESS_DB_PASSWORD: examplepass WORDPRESS_DB_NAME: exampledb db: image: mysql:5.7 restart: always environment: MYSQL_DATABASE: exampledb MYSQL_USER: exampleuser MYSQL_PASSWORD: examplepass MYSQL_ROOT_PASSWORD: rootpassword
Step 5: Start the WordPress and MySQL Containers
- Run Docker Compose to start the containers:
sudo docker-compose up -d
- Verify that the containers are running:
sudo docker-compose ps
Step 6: Configure WordPress
-
Open your browser and navigate to your EC2 instance’s public IP address.
-
Complete the WordPress installation:
-
Choose your language.
-
Enter your site title, username, password, and email.
-
Click “Install WordPress”.
Step 7: Access Your WordPress Site
- Log in to your WordPress site:
- Go to http://your-ec2-public-ip/wp-admin.
- Enter the username and password you set during the WordPress installation.
- Customize and start blogging: You can now customize your WordPress site and start creating content.
Additional Configuration (Optional)
-
Enable HTTPS: Consider using a reverse proxy like Nginx with Let’s Encrypt to enable HTTPS for your site.
-
Backup and Monitoring: Set up regular backups and monitoring to ensure your site’s availability and security.
-
Scalability: As your site grows, consider scaling your infrastructure using AWS services like Elastic Load Balancing and RDS.
Reference
For additional details, you can refer to this comprehensive guide: How to Build a Web on AWS for Yourself.
This guide should help you get your blog up and running using WordPress on an AWS EC2 instance with Docker. Have fun