Skip to content
Indus LeveL
wordpress aws ec2 rds apache php sysadmin migration

Migrating and Securing WordPress on AWS EC2 and RDS

An enterprise sysadmin guide to migrating a legacy WordPress installation to AWS EC2 and RDS, configuring Apache Virtual Hosts, and installing PHP 7.4.

2 min read
Cover illustration representing WordPress CMS migration to AWS EC2 instances and managed RDS MySQL databases

Migrating a production WordPress website from a legacy hosting provider to Amazon Web Services (AWS) allows you to decouple your web application tier from your database tier. By running WordPress on an EC2 instance and hosting the MySQL database on a managed RDS instance, you significantly improve scalability, performance, and reliability.

In this guide, I will walk you through preparing an AWS EC2 instance, installing Apache and PHP 7.4 via the Remi repository, configuring Apache Virtual Hosts, dumping and importing MySQL databases, and updating WordPress configuration files.

Prerequisites

You will need an AWS account with privileges to launch EC2 instances and RDS MySQL databases, alongside domain management access to configure CNAME and A-records.


Step 1: Base System Update and PHP 7.4 Installation

Connect to your EC2 instance via SSH, update system packages, and configure the EPEL and Remi repositories to install PHP 7.4 alongside Apache HTTP Server.

# Update system packages
yum update -y

# Install EPEL repository
yum install -y epel-release

# Install Remi repository
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php74

# Install Apache and PHP 7.4
yum install -y httpd php php-cli php-common php-gd php-mbstring php-mysql php-pdo php-xml

Enable and start Apache:

systemctl enable httpd
systemctl start httpd

Step 2: Configuring Apache Virtual Hosts

Create a dedicated directory structure for your WordPress website and establish a clean Virtual Host configuration.

# Create web root and log directories
mkdir -p /var/www/induslevel.com/{html,log}
chown -R apache:apache /var/www/induslevel.com

Create /etc/httpd/conf.d/induslevel.com.conf:

# /etc/httpd/conf.d/induslevel.com.conf
<VirtualHost *:80>
    ServerName www.induslevel.com
    ServerAlias induslevel.com
    DocumentRoot /var/www/induslevel.com/html
    ErrorLog /var/www/induslevel.com/log/error.log
    CustomLog /var/www/induslevel.com/log/requests.log combined
    <Directory "/var/www/induslevel.com/html">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Reload Apache to apply the Virtual Host configuration:

systemctl reload httpd

Step 3: Database Migration to AWS RDS

To migrate your legacy database to your new AWS RDS MySQL instance, execute a mysqldump on your legacy server and import it directly into your RDS endpoint.

# Dump database from legacy server
mysqldump --add-drop-table -h db01.example.net -u dbocodex -p wp > blog.bak.sql

# Import database into AWS RDS instance
mysql -h wordpress-inst.cxfbeorjanfy.us-east-1.rds.amazonaws.com -u admin -p induslevel_com_db < blog.bak.sql

Step 4: Configuring WordPress (wp-config.php)

Unpack WordPress into your new web root directory /var/www/induslevel.com/html and update /var/www/induslevel.com/html/wp-config.php to connect to your RDS endpoint:

// /var/www/induslevel.com/html/wp-config.php
define( 'DB_NAME', 'induslevel_com_db' );
define( 'DB_USER', 'admin' );
define( 'DB_PASSWORD', 'Randompassword' );
define( 'DB_HOST', 'wordpress-inst.cxfbeorjanfy.us-east-1.rds.amazonaws.com' );

Step 5: Domain DNS Configuration

Update your domain registrar DNS records to point your public web traffic to your new AWS infrastructure:

www CNAME ec2-54-173-142-101.compute-1.amazonaws.com
@   A     54.173.142.101

References

Back to Blog
Share:

Follow along

Stay in the loop — new articles, thoughts, and updates.