DEV Community

Mim Ahmed for AWS Community Builders

Posted on

How To Use Single Database Server For Multiple LightSail WordPress Instance For Load Balancing

Setup WordPress on Lightsail

Step 1: Choose your Region
Choose a Region

Step 2: Select Operation System I am Using (Linux)
Choose a OS

Step 3:
Choose a Instance Plan

Step 4:
Set Instance Name and Size

Step 5:
Lightsail server running

Setup VPC Peering

Step 1:
Click Account
VPC Peering

Step 2:
Click Advanced Tab and Click Virginia (us-east-1) or you may choose your VPC Region.

It May Takes 30/40 Seconds and Blue Tick Will Come

Lightsail Advanced Option

Step 3:
Now Go To Your AWS Console and Search RDS & Click on RDS

Step 4:
Now Click Create Database
Create Database

Now Choose Standard Create

Now Choose Aurora and Select Amazon Aurora with MySQL compatibility
Amazon Aurora with MySQL

Now Choose a Aurora Mysql Version
Aurora Mysql Version

Now Put a Database Name and Set Password
Database Name and Set Password

Now Select your instance size for your database and replica option if you need. Here i select a Small instance and no replica option hence i don't need any Replica.

How Choose your VPC. Choose the VPC which you select During Peering Option

For Other Configurations Please go through AWS Aurora Documentation. (keep This as it is)

Now Click Create Database
Create Database

Our Database is Created Successfully
Database is Created Successfully
Now Store the Credentials in Safe Place we need it later.

Setup Security Group Inbound Rules

Here we select Mysql Instance Option a instance is created. Now Click on this instance.
Mysql Instance
Now Click On The Security Group
Security Group

Click Inbound Rule
Inbound Rule
Click Edit Inbound Rule
Edit Inbound Rule
Now Add Lightsail Private IP Block to Mysql Aurora Port to Access the Database
Ligthsail Environment Private IP
Ligthsail Environment Private IP
Add in the Security Group

Export WP Database

Step 1:
First Access Your Instance With your Browser
LightSail Terminal

Step 2:
Find Mysql Password
Mysql Password

Step 3:
Now Run this command To Export Database & Use Your Password

mysqldump -u root -p bitnami_wordpress > wpdatabase.sql --databases --add-drop-database

Export Database

Import Database into AWS Aurora RDS

Step 1:
Access The Database From Terminal
Command : sudo mysql -u admin -p -h 'Your Host Link'
RDS Access
Data Base Import Command : /. dbname.sql (Put Your DB Name)
Data Base Import Command
Import Successful
Import Successful
Exit Mysql
Exit Mysql

Update WP Configuration File to Point the RDS

Step 1 :
Go to wp-config File
wp-config File

Step 2:
set username and Password

Now Press Crtl+X and Type 'Y' For Save and Hit Enter.
Save File

Now Check Your Site.


Stop local Mysql Service

Now You Can Stop Local Mysql Server. Because we don't need it Anymore. All Request Now Serve from Amazon RDS.

Check Running Services:
Command: sudo /opt/bitnami/ status
Running Services

Now Run This Command to Stop MariaDB Services
Stop MariaDB Services

Now Check again Running Services
MariaDB stop

Now Prevent MariaDB to start again When you server restart. Just you have to rename the file.
rename script

When you need to run the script file again just rename again and remove the '.disable' from the filename.

Now you can do the same thing on your another instance to add the RDS End Point. Now Both of your instance sharing the same RDS.

Thanks for Reading This Article.

If you need any support for you AWS Project. You Can Knock Me


Top comments (0)