How to host a WordPress website in AWS EC2 instance – Part 1
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
This will be a 3-part series where in part 1 we are going to create an EC2 instance in AWS cloud to host our WordPress website, in the part 2 we will install and configure our WordPress website and in part 3 will complete the setup by enabling DNS and TSL/SSL for our WordPress website.
For those who are completely new to AWS cloud, an EC2 instance is basically a server that is hosted in AWS cloud and we are going to provision this cloud server in this blog post.
Create an AWS EC2 instance to host a WordPress website:
Prerequisites:
Step 1: Login to AWS Management Console and navigate to EC2 service.
Step 2: Select your region and click “Launch Instance”.
Note: AWS has datacenters in multiple geographic locations called region and unless you are using a CDN solution, its recommended to host your website near your target audience.
Step 2: Select “Amazon Linux 2” AMI for your EC2 instance.
Note: AMI or Amazon Machine Image is a template containing OS and other Applications pre-configured and is used to deploy new EC2 instance. AWS provides AMI for all type of OS and architecture and we are using “Amazon Linux 2” AMI which contains a strip down version of Linux.
Step 3: Select the instance type and click “Next configure instance default”
Note: Instance type basically defined the resource (CPU, RAM and Network) allocation to your server.
Step 4: Configure EC2 instance details.
We will keep default configuration options for the moment which if required can be changed once the server is provisioned. Click “Next Add Storage”.
Step 5: Configure storage options.
Again, we will keep the default and move to next step.
Step 6: Optionally you can add a tag to easily identify your server if you have multiple servers.
Click “Next: Configure Security Group”.
Step 7: Create the security group configuration for your EC2 instance.
Note: Security group is basically the firewall to your server where you configure which port to open. Since we are creating a website, we need to open port 80 and 443 for HTTP and HTTPS communication from anywhere. You also need to open port 22 for connection to your server using SSH. I have provided my local system public IP address but if you don’t have the public IP address then though not recommended, you can open the SSH port to accused from anywhere like we did for HTTP and HTTPS.
Step 8: Click on the “Launch” to deploy your server in the AWS cloud.
Step 9: Provide key pairs details and click “Launch instances”.
Select “Create new key pair” provide a name. Download the private key and store in a safe location. This key will be used later to connect to your server over SSH. Click “Launch instances” to launch your EC2 instance.
You now have a brand-new server in AWS cloud, click on the instance id to navigate to your server.
Next, we are going to assign a Public static IP address to our server so that IP address does not changes after every reboot of the instance.
Step 10: Under “Network & Security” click “Elastic IPs” and then click on “Allocate Elastic IP address”.
Step 11: Select “Amazon’s pool of IPv4 addresses”, optionally you can create a tag to easily identify this elastic IP address. Click “Allocate”.
Step 12: Next, we will associate this elastic IP address with our EC2 instance, click “Associate Elastic IP address” under “Actions”.
Step 13: Select your EC2 instance and private IP address and click “Associate”.
Note: Copy this IP address for later use, our website will use this IP address.
Next, we will connect to the EC2 instance.
Step 14: Connect to your EC2 instance –
Using Browser:
Select the instance and click “Connect”.
Select the “EC2 Instance Connect” tab and click “Connect”.
Using external tools :
Open Putty or MobaExterm or any other tool that you are using and provide your private SSH keys, Public IP address and Username to connect to your AWS EC2 instance. For example, below is a screenshot for MobaExterm connection:
Using command line:
1 2 3 |
## Open a new terminal chmod +400 /some/path/to/your/ssh/key/file ssh -i /some/path/to/your/ssh/key/file <user_name>@<public_ip> |
Hope you have enjoyed this 1st part where we have created the EC2 instance. In the second part we will install and setup our WordPress application.