Deploying WordPress with HTTPD on AWS EC2 and MySQL on AWS RDS

Aryanshu Kumar
4 min readJul 27, 2023

WordPress is a popular and versatile content management system (CMS) used by millions of websites around the world. If you’re looking to deploy WordPress on the cloud, Amazon Web Services (AWS) provides a scalable and reliable infrastructure to do so.

In this guide, we’ll walk you through the steps to set up WordPress using the Apache HTTP Server (HTTPD) on an AWS EC2 instance and a managed MySQL database on AWS RDS (Relational Database Service).

Prerequisites

Before starting the setup process, make sure you have the following prerequisites:

  1. An AWS account with appropriate access rights to create EC2 instances and RDS instances.
  2. Familiarity with AWS services and basic knowledge of WordPress installation.

STEP 1: Launch an AWS EC2 Instance

Let’s start by launching an AWS EC2 Instance:

  1. Log in to your AWS Management Console.
  2. Navigate to the EC2 Dashboard and click on “Launch Instance
  3. Give the instance name as “WordPress”.
  4. Select Amazon Machine Image (AMI) that fits your needs. Choose an image with the latest version of your preferred Linux distribution. I will be using the Amazon Linux 2023 AMI".
  5. Choose an instance type based on your requirements. For a small-scale WordPress website, a t2.micro instance should suffice.
  6. Configure instance details, such as the number of instances, network settings, and storage. Make sure to add a security group that allows HTTP (port 80) and HTTPS (port 443) inbound traffic.
  7. Review the configurations and click on the “Launch instance”.

Now, next step is to create an instance of MySQL database on AWS RDS.

Step 2: Set Up a MySQL Database on RDS

  • Go back to the AWS Management Console and navigate to the RDS Dashboard.
  • Click “Create Database” and select “Easy Create.”
  • Choose the MySQL engine and select the desired version.
  • In the Templates section, choose the appropriate template. I will be selecting “Free Tier”.
  • Configure the database settings, such as DB instance name, DB instance size, username, and password. Make sure to note down the database endpoint, username, and password as you’ll need them later.
  • Configure the connectivity settings, including the VPC, subnet group, and security group.
  • Now, we need to connect our “WordPress” EC2 instance to the DB instance. In the Connectivity section, select Connect to an EC2 compute resource and select the WordPress instance.
  • Review the settings and create the database.

After this, when the status of the RDS instance shows “Available”, you are ready to proceed to next steps.

Create a database for WordPress to use:

  • Connect to the EC2 instance using SSH.
  • Install MySQL server to connect to the database instance:
wget https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm
sudo yum install mysql80-community-release-el9-1.noarch.rpm -y
dnf repolist enabled | grep "mysql.*-community.*"
sudo dnf install mysql-community-server -y

Now, connect to the database and create a database “wordpress

mysql -h <database_endpoint> -u <database_username> -p
CREATE DATABASE wordpress;

Step 3: Install and Configure Apache HTTPD

Once the EC2 instance is running, connect to it using SSH.

  • Update the package list and install Apache HTTPD:
sudo yum update -y
sudo yum install httpd -y

Step 4: Install WordPress on EC2 Instance

  • Connect to your EC2 instance using SSH.
  • Install PHP and MySQL extension.
sudo yum install php php-mysqli -y
  • Download and extract the latest WordPress package:
cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xvf latest.tar.gz
sudo rm latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress/
  • Configure WordPress to connect to the RDS database:
cd /var/www/html
sudo mv wp-config-sample.php wp-config.php
sudo vim wp-config.php
  • In the “wp-config.php” file, update the following information:
define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_username' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST', 'your_database_endpoint' );

Last thing we need to do in the EC2 instance is to start the Apache HTTPD server:

sudo systemctl start httpd

Step 5: Install WordPress

  • Open a web browser and enter your EC2 instance’s public IP or domain name.
  • Follow the WordPress installation wizard to set up your website, including site title, admin username, password, etc.

Conclusion

Congratulations! You’ve successfully navigated the process of setting up WordPress with Apache HTTPD on an AWS EC2 instance and connecting it to a MySQL database on AWS RDS. By following the steps outlined in this guide, you’ve harnessed the power of AWS’s cloud infrastructure to create a scalable and reliable environment for your WordPress website.

Moreover, AWS offers a vast ecosystem of services that you can explore to enhance your WordPress setup further. From content delivery networks (CDNs) to improve website loading speeds to security services for enhanced protection, AWS has a solution to fit almost any requirement.

Happy Reading!!

--

--