How To Use Single Database Server For Multiple LightSail WordPress Instance For Load Balancing
Tags: aws, lightsail, awsrds, wordpress
Published: 2021-10-19 11:35:33

---
title: How To Use Single Database Server For Multiple LightSail WordPress Instance For Load Balancing 
published: true
description: 
tags: aws, lightsail, awsrds, wordpress
//cover_image: https://direct_url_to_image.jpg
---
#### Setup WordPress on Lightsail
Step 1: Choose your Region
![Choose a Region](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0r6h46c5mhyefr133end.PNG)

Step 2: Select Operation System I am Using (Linux)
![Choose a OS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cnqkou4l3wetjt4p97jk.PNG)

Step 3:
![Choose a Instance Plan](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/knzolyfnldmglmj85jii.PNG)

Step 4:
![Set Instance Name and Size](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t00yeb41baapr82l53kc.PNG)


Step 5:
![Lightsail server running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n6r3rcbn95ms7ouoqmgk.png)

#### Setup VPC Peering
Step 1:
Click Account
![VPC Peering](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fhqn8anaqn76qqw8xxgo.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2v9urmntqj0syjaqmimk.png)

Step 3:
Now Go To Your AWS Console and Search RDS & Click on RDS
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j57zz380w7li627igs49.png)

Step 4:
Now Click Create Database
![Create Database](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mpgdjbh8a282g10xfx7y.png)
 
Now Choose Standard Create
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s02ycddfgipnekoynbom.png)

Now Choose Aurora and Select Amazon Aurora with MySQL compatibility
![Amazon Aurora with MySQL](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0c70djfi6qq4brh6z1i.png)
 
Now Choose a Aurora Mysql Version
![Aurora Mysql Version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bumqndmi94onufgpwe9e.png)
 
Now Put a Database Name and Set Password
![Database Name and Set Password](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/neho1wobggcsu1ljzjjr.png)
 
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.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0hrmae9lnegpqiqwm28i.png)

How Choose your VPC. Choose the VPC which you select During Peering Option
![VPC](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mikjih6cwpsmckum19u3.png)
 
For Other Configurations Please go through AWS Aurora Documentation. (keep This as it is)
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/65zvbror5wg4m21ltkdr.png)

Now Click Create Database
![Create Database](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oazco5k15gywtvothd7x.png)

Our Database is Created Successfully
![Database is Created Successfully](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ludu57fyvf97rfutivom.png)
Now Store the Credentials in Safe Place we need it later.
![Credentials ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mik1b99rh7g4ktkrh4g7.png)
 
 
#### Setup Security Group Inbound Rules
Here we select Mysql Instance Option a instance is created. Now Click on this instance.
![Mysql Instance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zrdcs91v61lka0dyzdpi.png)
Now Click On The Security Group
![Security Group](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9wswc0exczuotgtwwm4v.png)

Click Inbound Rule
![Inbound Rule](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7stgvb3ezbl3h8hkurbs.png)
Click Edit Inbound Rule
![Edit Inbound Rule](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qi3uxhadiorflg852e2p.png)
Now Add Lightsail Private IP Block to Mysql Aurora Port to Access the Database
Ligthsail Environment Private IP
![Ligthsail Environment Private IP](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nhfcnh551bwnl9tolavq.png)
Add in the Security Group
![Port](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0m6a8di5xx29hksde59v.gif)

#### Export WP Database
Step 1:
First Access Your Instance With your Browser
![SSH](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/89ccf1rglv0303socpn6.png)
LightSail Terminal
![SSH](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s8himw7frt8xyc22i8f2.png)

Step 2:
Find Mysql Password
![Mysql Password](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/djtn1rsd4lgbomuhsttk.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ylkwle29s15nszhdwpwo.png)

#### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oazrwfudhtoo0xm0e0i2.png)
Data Base Import Command : /. dbname.sql (Put Your DB Name)
![Data Base Import Command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ve2axssu5ptj540f57os.png)
Import Successful
![Import Successful](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fqo12idn7hvw7wluvoc5.png)
Exit Mysql
![Exit Mysql](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ovlgnmch0z335bhym1z8.png)
 
 
#### Update WP Configuration File to Point the RDS

Step 1 :
Go to wp-config File
![wp-config File](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ztx111w4dt8h8ibe8d7t.png)
  
Step 2:
![set username and Password](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pveyluo42gh3k39xz8a3.png)

Now Press Crtl+X and Type 'Y' For Save and Hit Enter.
![Save File](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cnuh5xen18rtwu2n16li.png
)

Now Check Your Site.

![HomePage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tsh71tc6gt3729g2v0by.png)
 

#### 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/ctlscript.sh status
![Running Services](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/untb3mehe9j6kh3qo6ug.png)

Now Run This Command to Stop MariaDB Services
![Stop MariaDB Services](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aty3u9w3kuprdq7knvc6.png)

Now Check again Running Services
![MariaDB stop](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4w680kk8nf710alpux6v.png)
 
Now Prevent MariaDB to start again When you server restart. Just you have to rename the ctlscript.sh file.
![rename script](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9zpf5xpb9ry0paab310r.png)

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
[Click](https://www.fiverr.com/mimahmedjoy/setup-your-websites-on-azure-aws-gcp-digital-ocen)