Deploying A Wordpress Website Utilising AWS EFS As Shared File Storage
Scenario:-
We will be deploying an Wordpress website which will be utilising an EFS for shared file storage, RDS instance for the database storage, apache as a web server.
Infrastructure Setup:-
We need to create an vpc named as test-vpc. It is going to have 2 availability zones. There will be 2 public subnets, 2 private subnets. For cost cutting purpose i will be creating only one NAT gateway in one AZ. But for high availability you should be having the NAT gateway per AZ.
In subnet-public1 we will be creating an bastion server named as bastion. It will be used to connect to our private EC2 instance.
Now we will be creating an EFS named as test-EFS which will be created in the same vpc which we created earlier.
The main advantage of EFS is that it can accessed through multiple EC2 instance & from different availability zones in the same region
After this we will be creating the 2 private instance in the subnet-private1.
Make sure the security group attached to the private instance allow traffic only from the bastion server IP address.
AWS provides auto mount option for the shared file system while creating an EC2 instance, we will be selecting the same.
Login to both the private EC2 instance from the bastion server & check if the directory has been mounted or not at the given path /mnt/efs/fs1.
Configuring Load Balancer & RDS Instance:-
We will be creating an Application Load Balancer(ALB) from the AWS console. Select the same vpc as the previously created.
Create the target group having the 2 private EC2 instances as the target.
After creating the load balancer try opening the dns url you will get an error at this stage as the instances are not serving the application currently.
Now create the RDS of type MYSQL in the same vpc which will be responsible for storing the secrets/database related storage. Also in the advance configuration you will find an option to create a database by default on DB creation we will name it as mydb.
Note that the RDS security group should allow in inbound the security group of private EC2 instance so that the EC2 can interact with DB easily.
Check the connection if you can connect with the DB through database.
Deploying WordPress:-
For deploying the Wordpress with need to install httpd package, php, Wordpress file etc.
Execute the below commands on both the private EC2 instance for the required package installation.
sudo yum update -y sudo yum install httpd -y sudo systemctl start httpd sudo systemctl enable httpd sudo yum install php php-mysqlnd php-gd php-xml php-mbstring -y sudo systemctl restart httpd
Now the below steps need to be executed from one single instance only as the mounted directory content is going to be shared same with both the instances.
cd sudo wget https://wordpress.org/latest.tar.gz sudo tar -xzvf latest.tar.gz sudo mv wordpress/* /mnt/efs/fs1 cd /mnt/efs sudo chown -r apache:apache fs1/* sudo vi fs1/wp-config-sample.php
Here the path /mnt/efs/fs1 will act as a Default Document root folder location.
Update the database name, credentials, db hostname in the wp-config-sample.php file.
Now update the default root server path by editing the /etc/httpd/conf/httpd.conf file as below.
Execute the systemctl restart httpd.service to load the updated configuration.
Try accessing the website using the load balancer DNS url, now it should be accessible.
You should create an user with credentials to access the wordpress website as below.
Now you can upload different files, themes, plugins etc which will stored in the EFS which will be common among all EC2 instance.
Summary:-
So in this project we deployed an Wordpress website on the EC2 instance. For high availability we should use different availability zones. The AWS EFS acted as the shared file storage among different EC2 instances. The RDS instance of type MYSQL acted as a default database. We created an Application Load Balancer which was redirecting traffic towards our backend private EC2 instances. In the end we installed the apache & other required packages for the Wordpress website deployment.