Archival Notice
This guide was written for legacy WordPress migrations using PHP 7.4 on CentOS 7. Please note that PHP 7.4 and CentOS 7 have reached End of Life (EOL), and modern WordPress releases require PHP 8.1+. Please adapt package installations and syntax to current environment standards.
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
WordPress Migration Complete
Your WordPress CMS is now fully migrated, decoupled, and operating securely on AWS EC2 and RDS!