How to Host WordPress Websites Using AWS EC2 and RDS

Suhailul Aslam KC

January 27, 2025

WordPress is one of the most popular content management systems (CMS) in the world, powering over 40% of websites globally. Hosting a WordPress website on AWS (Amazon Web Services) provides high scalability, security, and performance. In this guide, we will walk you through the step-by-step process of hosting a WordPress website using AWS EC2 (Elastic Compute Cloud) and RDS (Relational Database Service). By the end, you’ll have a robust setup capable of handling traffic surges while keeping your data secure.

Prerequisites

Before diving into the process, make sure you have the following:

  1. An AWS account with proper access permissions.
  2. Basic knowledge of Linux commands.
  3. A registered domain name (optional but recommended).
  4. An understanding of WordPress and its basic functionality.

Step 1: Launch an EC2 Instance

AWS EC2 provides virtual servers in the cloud, which we will use to host WordPress.

1.1. Log in to your AWS Management Console

Go to AWS Console and log in.

1.2. Navigate to EC2

  • From the AWS dashboard, click on EC2 under the “Compute” category.

1.3. Launch an Instance

  • Click on the Launch Instances button.
  • Choose an AMI (Amazon Machine Image). Use Amazon Linux 2 for WordPress hosting.
  • Select an instance type. A t2.micro is eligible for the free tier and is sufficient for small to medium traffic websites.
  • Configure the instance details (leave defaults for most configurations).
  • Add storage (default 8GB is sufficient, but increase as needed).
  • Add tags for easy identification (e.g., Key: Name, Value: WordPress-Server).
  • Configure security group:
    • Add inbound rules for HTTP (port 80), HTTPS (port 443), and SSH (port 22).
    • Restrict SSH access to your IP address for security.
  • Review and launch the instance. Download the key pair (.pem file) and keep it secure.

Step 2: Set Up the EC2 Instance

Once the EC2 instance is running, connect to it and prepare the environment for WordPress.

2.1. Connect to Your Instance

  • Use an SSH client like Terminal (Mac/Linux) or PuTTY (Windows).
  • Run the following command:
ssh -i path-to-your-key.pem ec2-user@your-instance-public-ip

2.2. Install Required Software

Install the necessary software:

sudo yum install -y httpd mysql php php-mysqlnd php-fpm 

2.3. Start and Enable Apache

sudo systemctl start httpd
sudo systemctl enable httpd

2.4. Download WordPress

cd /var/www/html
sudo wget https://wordpress.org/latest.zip
sudo unzip latest.zip
sudo mv wordpress/* ./
sudo rm -rf wordpress latest.zip

2.5. Set Permissions

sudo chown -R apache:apache /var/www/html
sudo chmod -R 755 /var/www/html

2.6. Allocate and Associate an Elastic IP

  • Go to the Elastic IPs section in the EC2 dashboard.
  • Allocate a new Elastic IP.
  • Associate the Elastic IP with your EC2 instance.
  • Note the Elastic IP address, which will serve as your instance’s public IP.

Step 3: Configure AWS RDS for the Database

RDS makes it easy to set up, operate, and scale a relational database in the cloud.

3.1. Navigate to RDS in the AWS Console

  • Go to the RDS service from the AWS dashboard.
  • Click on Create database.

3.2. Configure the Database

  • Choose the database creation method as Standard Create.
  • Select MySQL as the engine type.
  • Use the Free Tier template for development purposes.
  • Configure database settings:
    • DB instance identifier: wordpress-db
    • Master username: admin
    • Master password: your-strong-password
  • Configure instance size. Select db.t2.micro for the free tier.
  • Set up storage (default 20GB should be sufficient).
  • Add a security group allowing inbound MySQL (port 3306) access from the EC2 instance.

3.3. Launch the Database

  • Review and launch your RDS instance. Note down the endpoint URL (e.g., your-db-instance.us-east-1.rds.amazonaws.com).

Step 4: Connect WordPress to RDS

4.1. Configure the WordPress Database

  • Connect to your RDS instance from the EC2 instance:mysql -h your-db-instance-endpoint -u admin -p
  • Create a database for WordPress:CREATE DATABASE wordpress;

4.2. Update WordPress Configuration

  • Open the WordPress configuration file:sudo nano /var/www/html/wp-config.php
  • Edit the database settings:
define('DB_NAME', 'wordpress');
define('DB_USER', 'admin');
define('DB_PASSWORD', 'your-strong-password');
define('DB_HOST', 'your-db-instance-endpoint');

Save and close the file.

Step 5: Finalize Setup – Pointing Domain

5.1. Configure Route 53 to Point Your Domain to the Elastic IP

  • Go to the Route 53 service in the AWS console.
  • Create a new hosted zone for your domain if not already done.
  • Add an A Record pointing your domain (e.g., www.yourdomain.com) to your EC2 Elastic IP address.
  • Save the changes and allow time for DNS propagation.

5.2. Restart Apache

sudo systemctl restart httpd

5.3. Access WordPress

  • Open a web browser and navigate to your domain (e.g., http://www.yourdomain.com).
  • Complete the WordPress installation by providing the site title, admin username, and password.

Step 6: Secure Your Setup

6.1. Add SSL from AWS Certificate Manager (ACM)

  • Navigate to Certificate Manager in the AWS console.
  • Request a public certificate for your domain (e.g., www.yourdomain.com).
  • Validate the certificate using DNS validation through Route 53.

Step 7: Scale and Optimize

7.1. Set Up Auto Scaling

  • Use AWS Auto Scaling Groups to handle traffic spikes.

7.2. Optimize Performance

  • Use Amazon CloudFront for CDN.
  • Implement caching plugins like W3 Total Cache or WP Rocket.

7.3. Regular Backups

  • Set up automatic backups for your RDS instance.
  • Use plugins like UpdraftPlus to back up WordPress files.

Conclusion

Hosting WordPress on AWS using EC2 and RDS offers a scalable, secure, and high-performing solution. By separating the database and web server, you ensure better reliability and easier maintenance. This guide provides a strong foundation, but you can further enhance your setup by integrating additional AWS services like CloudWatch for monitoring, Route 53 for DNS management, and Elastic Load Balancer for traffic distribution. With AWS, your WordPress website is ready to handle whatever the future brings!