I’m new to AWS and cloud computing in general. For a personal project I’ve created a micro instance on amazon ec2 and installed and configured a wordpress multisite site. For the database, I use an RDS instance.
My question is, how can I create a second micro instance that serve the same content and use a load balancer to spread the traffic to these two instances? I want to do this so that so if the first EC2 instance crashes then it will get served from second instance and the site doesn’t go down.
Thanks for your help and sorry for any english related error.
As far as the wordpress installation is concerned, there are 2 main components.
The Database
need to have the database outside the auto-scaling EC2 instance. As mentioned
in your question, this is in RDS and hence it wont be a problem
The second EC2 instance
Step 1: First create an AMI of your WordPress Instance from the existing one.
Step 2: Launch a new EC2 instance from this AMI which you created from the first one. This will result in 2 EC2 instances. Instance 1 (the original one with Database) and Instance 2 (The copy of Instance 1)
However, any changes that you do in Instance 1 wont reflect in Instance 2.
If you want to get rid of this problem, consider using EFS service to create a shared volume across 2 EC2 instances and configure the wordpress installation to work from that EFS volume. This way, your installation files and other content will be in shared EFS volume commonly accessed by both EC2 instances.
You will have to move your database out of your localhost (I guess that you have it on the same micro instance), either to another ec2 instance or preferably to an RDS instance.
Afterwards you need to create a copy of your ec2 instance to another ec2 micro instance and put the both behind a load balancer.
First create the image of your existing micro ec2 instance on which you have configured word press
Second, create a classic load balancer
Third, create a launch configuration (LC) with above AMI you created.
Fourth, create auto scaling group with above LC, ELB and keep the group size count to 2.
This will make sure you have 2 instances running all time and if at all any instance goes down, ASG will create another new instance from AMI and terminate failed instance. REF-
https://docs.aws.amazon.com/autoscaling/latest/userguide/as-register-lbs-with-asg.html
Or
If you want you can use elastic bean stalk also-
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/php-hawordpress-tutorial.html
Thanks