AWS-Cloud-Computing

Tutorial: Setting Up an EC2 Instance for Hosting a Web Server

Contents

  1. Introduction
  2. Account Setup
  3. Create an EC2 Instance
  4. Connect to Your Instance
  5. Set Up a Web Server using Apache
  6. Dynamic Domain Name Service
  7. Installing HTTPS
  8. Connecting to Your VM via SSH on Visual Studio Code

1. Introduction

Amazon Elastic Compute Cloud (EC2) is a powerful service that allows you to deploy virtual servers in the cloud, making it an ideal choice for hosting web servers. Whether you’re running a small personal website or managing a large-scale application, EC2 provides the flexibility and scalability to meet your hosting needs.

In this guide, we will walk you through the essential steps of setting up an EC2 instance to host a web server. By the end of this tutorial, you’ll have a functional web server ready to serve your content to the world. We’ll cover key concepts such as account setup, instance creation, security group configuration, and the installation of a web server software, like Apache.

So, whether you’re a seasoned developer or just beginning your journey in web hosting, this guide will equip you with the foundational knowledge to get your web server up and running on an EC2 instance in no time.

2. Account Setup

image

image

image

3. Create an EC2 Instance

image

image

image

image

image

image

image

image

image

image

image

image

image

4. Connect to your instance

You can connect to your instance via AWS Console, for the initial set up, I would recommend connecting via SSH and using the Key Pair created during the instance set up.

image

image

image

5. Set Up a Web Server using Apache

sudo apt update

sudo apt upgrade

image

sudo apt install apache2 apache2-utils

image

sudo systemctl enable apache2

image

image

image

**Congratulations you now have a running web server! **

sudo chown www-data:www-data /var/www/html -R

sudo usermod -a -G www-data ubuntu

sudo chown -R ubuntu:www-data /var/www

sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \; && find /var/www -type f -exec sudo chmod 0664 {} \;

sudo mkdir /var/www/bookclub

sudo mkdir /var/log/apache2/bookclub

cd /etc/apache2/sites-available/

sudo cp 000-default.conf bookclub.conf

sudo nano bookclub.conf

image

cd /etc/apache2/sites-available/

sudo a2ensite bookclub.conf

sudo a2dissite 000-default.conf

sudo systemctl restart apache2

cd /var/www/bookclub

nano index.html

image

image

6. Dynamic Domain Name Service

The AWS instance we created has a dynamic IP that is changing regularly, we can use a service such as Duckdns.org to assign a constant web address that is easy to remember.

Go to https://duckdns.org.

image

image image

image

image

cd ~

mkdir duckdns

cd duckdns

nano duck.sh

echo url="https://www.duckdns.org/update?domains=YOUR_DOMAIN&token=YOUR_TOKEN&ip=" | curl -k -o ~/duckdns/duck.log -K –

chmod 700 duck.sh

crontab -e

image

*/5 * * * * ~/duckdns/duck.sh >/dev/null 2>&1

image

./duck.sh

cat duck.log

image

image

Your new web address should now be working.

7. Installing HTTPS

sudo apt update

sudo apt install snapd

sudo snap install –classic certbot

sudo certbot –apache

image

image

image

8. Connecting to Your VM via SSH on Visual Studio Code

image

image

image

image

image

image