Skip to main content

FAULT TOLERENT WORDPRESS SITE



Here we have a fault tolerent wordpress site.Briefly we will go through steps for creating it.

1.Create vpc and subntet
As first step we will create a vpc and 3 subnets under it.Then create a NAT gateway and an internet gateway.In routing table route 2 subnets(private subnets) to NAT gatway and other (public subnet) to internet gateway.

2.Create security policy
We will create 3 security policies each one for RDS, web server and load balencer.

3.Create S3 acess role
Next step is to create an role for ec2 having administration access over s3.

4.Create s3 Buckets
Here first we will create two buckets.one image bucket and a content bucket first in ohio region. Here the content bucket is for backup of our web content and image bucket is linking with cloud front for lower latency in uploaded images in our site.We will also create a nother bucket in N.virgenia which act as a backup bucket.We will enable cross region replication from content bucket achieve this.(https://goserverspace.blogspot.com/2018/04/aws-s3-cross-region-replication.html)

5.Create RDS instance
Next we have to create RDS instances.we have to enable multi-az while creating RDS  instance so that if one az fails we can get content from other az. Once the RDS is created we will create a read replica for it in N.virgenia. This is as a part of disaster recovery stratagy. So that if the entire region fails we could get the database contents back.(If you face any issues in creating RDS just follow https://goserverspace.blogspot.com/2018/06/aws-rds-creating-rds-instance.html)

6.Create cloud front
Create a cloud front pointing to our image bucket. We will provide the details of these cloudfront in .htacces

7.Create ec2 instance and install wordpress in it.
Spin up an ec2 instance and install wordpress in it. (If you have any issues in installing wordpress just follow https://goserverspace.blogspot.com/2017/09/wordpress-in-centos.html ).Dont forget to give database details inside wp-config.php file. Here we have to specify the end point that we get from RDS dashboard.

8.Sync the web contents with S3 bucket
In this step we will create a small script to syncing our web contents as well as uploads directory with s3 buckets.Our script will look as follows.


#!/bin/bash
aws s3 sync --delete /var/www/html s3://contentbucket/
sleep 10s
aws s3 sync --delete /var/www/html/wp-content/uploads s3://imagebucket/
sleep 10s
aws s3 sync --delete s3://contentbucket/ /var/www/html

Now save the file as myscript.sh(you can give your own name)
Give  executable permission to our file
#chmod +x myscript.sh

Now we have to create a cronjob to execute this script every 2 minutes.For that open /etc/crotab file and give following contents.

*/2 * * * *  root  /myscript.sh

This is done so that proper syncing of webcontents will occur on later when we put our web server under load balencer.

Also execute following command
#echo "server is healthy" > /var/www/html/healthy.html
This healthy.html file is for healthchecks by our load balencer.

Next in apache conf file(/etc/httpd/conf/httpd.conf) make

Allowoverride none to  AllowOverride All

Now restart httpd service
#service httpd restart

Now open .htaccess file and provide following entries

#vi .htaccess

Options +FollowSymlinks
RewriteEngine on
rewriterule ^wp-content/uploads/(.*)$ http://cloudfrontendpoint/$1 [r=301,nc]

# BEGIN WordPress

# END WordPress

Dont forget to replace cloudfront end with our cloudfront endpoint.This .htaccess file will redirect requests to our uploads directory to cloud front.

9.Create an Application load balencer with our all subnets spread across multiple availability zone.Also add this instance to ELB. For healthcheck create an index.html.

10. Register domains with Route53
Next we have to register our domain with R53. Don't forget to update ns records of aws in our domain provide.Create an A record pointing to our dns name.

11.Provide url of our website on a browser and install wordpress.
Now our word press site is ready.Test by uploading photos and writing posts.

12.Create an image from our word press ec2 instance.

13.Launch an auto scaling group with our wordpress ami that we just created. Then attach our load balencer to this autoscaling group.Now try to access our website with our url.Everything is done.Now we can detach the instance earlier we created and terminate it.(If you face issues in creating ELB with autoscaling group follow https://goserverspace.blogspot.com/2018/03/configuring-load-balencer-with.html)

14.Next step is to secure our infrastructure.As a part of it we had done two things.One we can attach an ssl certificate to ELB.We can use aws certificate manager for that. Next is to create an open vpn server so that users can login to our machines only through it.