Apache Web Server Setup on AWS using EC2, EBS, S3 via AWS CLI

RUBEL AGRAWAL
3 min readOct 20, 2020

--

To do tasks-

  • create a key pair
  • create a security group and allow port no 22 and 80
  • create an EBS volume
  • launch an ec2 instance with the newly created key pair and security group
  • setup apache webserver
  • attach the newly created EBS volume to the instance
  • mount this EBS volume to the /var/www/html folder
  • create a web page inside /var/www/html folder
  • create an S3 bucket and upload an object and give permission as public to both object and the bucket
  • start the webserver

keypair creation, security group creation, EC2 launch, EBS volume creation, attaching the EBS volume to the EC2 instance, user creation — for these tasks you can refer to the below URL:

To add the ingress rule for port no 22 and port no 80 use the following command:

aws ec2 authorize-security-group-ingress — group-id “sg-0c5d429e5f04d0548” — protocol “tcp” — port 22 — cidr “0.0.0.0/0”

aws ec2 authorize-security-group-ingress — group-id “sg-0c5d429e5f04d0548” — protocol “tcp” — port 80 — cidr “0.0.0.0/0”

adding ingress rule for port no 22 and 80

Starting and connecting to the already created instance-

aws ec2 start-instances — instance-ids “i-03386370c72f8a859”

ssh -i “keyname” username@ec2–13–233–172–45.ap-south-1.compute.amazonaws.com

starting already created instance
connecting to the instance using ssh

Setup Apache Web Server using the below command:

sudo su root (to login to root account)

yum install httpd

Create a partition for the EBS volume, format it and mount it to /var/www/html directory

  • fdisk /dev/xvdf (to create the partition)
  • mkfs.ext4 /dev/xvdf (to format the created partition)
  • mount /dev/xvdf /var/www/html (to mount the partition at /var/www/html)
creating partition
format the partition
mount the partition
list of all the partitions

Now create a web page and copy it in /var/www/html directory or directly you can create a webpage inside /var/www/html directory

creating web page inside /var/www/html

Now create an S3 bucket and upload an object and give permission as public to both object and the bucket

aws s3api create-bucket — bucket “servermedium” — create-bucket-configuration LocationConstraint=ap-south-1

creating a bucket named as servermedium

Now upload an object in the created bucket with public access

aws s3api put-object — bucket servermedium — body “C:\Users\Rubel\Desktop\rubel_agrawal.png” — acl “public-read” — key “rubel.jpg”

Now copy the address of the object in the web page so that it can be viewed by the public

s3 object URL in the file which is there in EBS

Start the Apache Web Server

starting Apache Web server

--

--

RUBEL AGRAWAL
RUBEL AGRAWAL

No responses yet