How to Create an EC2 Instance within AWS and Install Apache
Hello ☁️Cloud Readers!
Today my team and I have been tasked with helping a company start to shift from using on premises servers to using servers in the cloud. Rather than purchasing all the infrastructure in a data center they asked us to create an EC2 instance in AWS to host their new website. And we are gonna do just that.
Important Essentials
- Stable Internet Connection
- AWS Account
- Command Line
- Cloud Server Environment/Terminal/PowerShell
- Vim or a similar Text Editor
- Patience
Key Commands
sudo yum update -y
sudo yum install -y httpd
systemctl start httpd.service
systemctl enable httpd.service
whoami
pwd
What is AWS?
AWS or Amazon Web Service is one of the worlds most popular cloud computing venders. It provides a multitude of services such as, reduction of cost, or security and compliance features that cater to your specific needs when it comes to protecting your data.
To launch an EC2 Instance, we need an AWS Account.
It is important to note that we are also doing all of this for FREE. AWS offers a Free Tier of 750 hours per month for 12 months.
There are several ways you can launch an instance within the console. First we need to search for “EC2” within AWS.
After we launch an instance, the next prompts asks to name the instance we are creating and which distribution we would like to use.
For instance type, I am going to select t2.micro, which is the default type. AWS offers several other distributions and options for you instance, but for the sake of this task, we are sticking with free tier eligible options.
Next, I am going to create a key pair. It does give you the option to skip this step, However it is NOT recommended and in order to SSH into our instance, a Key Pair is required.
The .pem file will automatically show up in your Downloads folder, incase you ever wonder where it is.
Now we are going to edit the Network Settings. These are the current settings:
I want to make changes to the Firewall by making the Security Group allow inbound traffic on HTTP for 0.0.0.0/0 (which refers to all IPv4 addresses) and allow traffic on SSH from my IP address. This is simply to ensure that I am the only who will have access to SSH into this EC2 Instance. I have also selected the HTTP option because we are installing Apache. Now the network settings should look something like this:
Once that is done, the initiation of my instance can start.
Instances takes a minute to initialize, but you can refresh as much as you like to check the status.
Once the instance is up and running, I can now SSH into the server. To do this, all I need to do is select the instance I just created, and click connect on the right hand side. A prompt will come up, and i will be given instructions on how to SSH.
When SSHing into an EC2 Instance, you need a username, a key, and an IP Address. Notice, it is significantly different and more detailed than SSHing into a Cloud Server Environment.
Now its time to open up my preferred client, which is PowerShell, and follow the instructions.
I have run into a acommon error. I have a Key and authorization, but it is still denying access. It is because I am currently working from my root or home directory. I have to change directories in order to reference the key pair created earlier.
I am now in my EC2 instance.
Now, I am officially ready to install Apache. In order to do this, I am going to create a Bash Script using Vim.
All that is left is to run the script and check the Public IP of our EC2 Instance. You can go back and reference the IP address located in the Instance Summary within AWS.
Note: You can also Stop, Reboot, or Terminate an Instance within the Summary as well. It is highly encouraged to Stop instances when you are completely finished with them. Doing this well help save some of your compute capacity for other projects.
And there you have it, as always, thanks for reading! 😎