Step-by-Step Guide to Set Up WordPress on AWS EC2 with RDS

Ashutoshranjanpatratu
3 min readJul 30, 2023

--

Introduction: In this tutorial, we will walk you through the process of creating an AWS EC2 instance, configuring it with an Apache Webserver, and setting up WordPress with a MySQL database using AWS RDS. By the end of this guide, you will have a fully functional WordPress website running on AWS, utilizing the Free Tier resources available.

Step 1: Create an AWS EC2 Instance

  1. Open the AWS Management Console and navigate to the EC2 dashboard.
  2. Click on “Launch Instance” to start the instance creation wizard.
  3. Choose an Amazon Machine Image (AMI) for your EC2 instance (e.g., Amazon Linux 2).
  4. Select the instance type (t2.micro is eligible for the Free Tier).
  5. Configure the instance details like network, subnet, and security group settings.
  6. Review the settings and click “Launch” to create the EC2 instance.

Step 2: Configure the EC2 Instance with Apache Webserver

  1. Connect to your EC2 instance using SSH (replace “your-instance-ip” with your actual EC2 instance’s public IP):
ssh -i /path/to/your/key.pem ec2-user@your-instance-ip

2. Install Apache Webserver on the instance:

sudo yum update -y
sudo yum install httpd -y

3. Start the Apache service and enable it to start on boot:

sudo service httpd start
sudo chkconfig httpd on

You can now access the default Apache page by entering your EC2 instance’s public IP in a web browser.

Step 3: Download WordPress Application

  1. Move to the Apache webserver’s document root directory (e.g., /var/www/html/):
cd /var/www/html/

2. Download and extract the latest version of WordPress:

sudo yum install wget -y
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzf latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz

Step 4: Set Up AWS RDS MySQL Database

  1. Go to the AWS RDS dashboard and click “Create Database.”
  2. Choose “MySQL” as the database engine.
  3. Select “Free Tier” for the instance class to stay within the free usage limits.
  4. Configure the database details, such as DB instance identifier, master username, and password.
  5. Specify the database name (e.g., “wordpress_db”) and leave the rest of the settings as default.
  6. Create the RDS instance.

Step 5: Provide the Endpoint/Connection String to WordPress

  1. Once the RDS instance is created, go to the RDS dashboard, select the instance, and note down the “Endpoint” (connection string) of the database.
  2. Return to your EC2 instance and navigate to the WordPress directory
cd /var/www/html/

3. Rename the “wp-config-sample.php” file to “wp-config.php” and edit it:

mv wp-config-sample.php wp-config.php
sudo nano wp-config.php

4. Update the following database configuration parameters with your RDS credentials and endpoint:

define( 'DB_NAME', 'wordpress_db' );
define( 'DB_USER', 'your_database_username' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST', 'your_rds_endpoint' );

5. Save the changes and exit the editor.

Step 6: Complete WordPress Installation

  1. Open a web browser and enter your EC2 instance’s public IP or domain name.
  2. Follow the WordPress installation wizard to set up your website, create an admin account, and configure settings.

Conclusion: Congratulations! You have successfully set up an AWS EC2 instance with an Apache Webserver, installed WordPress, and configured it to use an AWS RDS MySQL database. Your WordPress website is now up and running, ready to be customized and published to the world. Remember to manage your AWS resources efficiently to stay within the Free Tier usage limits. Happy Learning!

--

--