Pages

Monday, June 11, 2018

Installing and Configuring Apache HTTP server on an EC2 Linux instance in AWS

Hello Friends,

In this post, I will elaborate:

How to Install & Configure Apache HTTP server on an EC2 Linux instance in AWS


Prerequisite:


1. An AWS Subsription
2. An EC2 Linux instance (I have taken RHEL for my comfort)
3. A client machine
4. An SFTP client to upload custom HTML files


Steps : 


Creating Security Groups for EC2 instance to allow HTTP & SSH (SFTP) traffic.


  • I am assuming that you have already created a EC2  Linux instance in your AWS subscription and it is in running status. I have chosen RHEL Linux as I am more comfortable with this flavor.
  • Go to your EC2 Dashboard and Select "Security Groups" under "Network & Security" Section.
  • Click on "Create Security Group" 

  • On the Next Screen , give security group a name, description and set "Inbound" rule to allow HTTP traffic from Anywhere and  OutBound rule for all ports, then click "Create"
  • This will allow HTTP traffic from public to EC2 instances associated with this security group.
  • You don't need to create a Security Group for SSH(SFTP) because at the time of creation of EC2 instance , you must have selected the default Security Group which allows SSH from all sources.
  • Now associate our EC2 instance with this new security group.
  • Go to EC2 Dashboard and select your EC2 instance, Click on Actions , select Networking and then select "Change Security Groups"

  • On the next screen Select the Security Group (HTTP & HTTPs) which you had created in last step (keep rest of the settings unchanged) and then click on "Assign Security Group"
  • Now your EC2 instance has been assigned with the necessary Security Groups required for allowing HTTP & SSH connection. 
  • Now we will connect to to our Linux instance.



Connecting an EC2 instance through Putty.

  • At the time of creation of your EC2 Linux instance, you must have created and downloaded the Key-Pair(.pem file).
  • This Key-Pair will be used to connect to that EC2 instance through Putty.
  • But before we could use that key-pair to connect the EC2 instance , we will have to convert it in the format which is understandable by Putty. 
  • Putty does not understand .pem format so we will convert it to .ppk (Putty Private Key) file using Puttygen tool
  • Puttygen.exe can be downloaded from This Link.
  • Now open the Puttygen.exe file on your local machine and click on File and then select "Load Private Key".

  • Browse to the location where you have saved the key-pair (.pem file) and click Open
 


  • It will load the Thumbprint of Private Key in PuttyGen Console.Now click on Save Private Key button.

  • Save the Private Key in PPK format now.

  • Since we now have converted the key-pair in Putty usable PPK format, we will use it in Putty as authentication to connect our Linux EC2 instance.
  • Now open Putty and in Session window enter following address in Host Name (Or IP Address field) 
       ec2-user@ec2-18-205-163-151.compute-1.amazonaws.com

  • Here ec2-user is the default user name for the Linux EC2 instance (for RHEL instances) and ec2-18-205-163-151.compute-1.amazonaws.com is the public DNS name of your EC2 instance. This can be found on the EC2 instance properties. 
  • Now on your Putty window , Click on the "+" sign before SSH and then click "Auth" for setting up Putty to use Private Key as authentication , click on browse and navigate to the location where you had saved the .PPK file created in PuttyGen.

  • Now Select the PPK (Private Key) file and click Open. It will load the key-pair file in to Putty.

  • Now click Open 

  • You will now see the Putty session has been established with your EC2 Linux instance with the default user (ec2-user). 
  • It will also show the IP of the host from where you have connected this EC2 instance from. (I have hidden my public IP for security purpose)


Installing Apache HTTP server on your EC2 Linux Instance 

  • Once you get the Putty session of your EC2 Linux instance, rest of the things are very straight forward.
  • Get in to Sudo (root) access by typing following command
           sudo su

  • Because these EC2 instance have internet access by default , we will directly install the Apache HTTP server from Yum repository 
  • Shoot following command on your Putty session:
         yum -y install httpd 
  • httpd is the package name of Apache HTTP server. The above command will install Apache on your EC2 instance.
  • Now permanently enable httpd service through following command 
         systemctl enable httpd


  • Once httpd service is enabled you need to start the httpd service through following command:
      systemctl start httpd

  • You have now taken all the steps to Install , Configure and enable Apache HTTP server on your EC2 Linux install. Now its time to connect

Testing:

  • To test that Apache HTTP server has been successfully installed on your EC2 Linux machine and is able to process HTTP request, try to browse the Public DNS name of your EC2 instance from your local machines browser.
  • If your browser shows the Apache Test pages (as following) then you have successfully configured the Apache HTTP server on your EC2 instance.


Happy Blogging !!!!!

























No comments:

Post a Comment