DEV Community

Cover image for How to Deploy a Website on a Public Domain with AWS EC2?
BAKRE JAMIU
BAKRE JAMIU

Posted on

How to Deploy a Website on a Public Domain with AWS EC2?

The wait is over! Welcome to Week 4.

Congratulations! ๐ŸŽ‰ I just crossed the halfway mark of this bootcamp ๐Ÿคฉ๐ŸŽŠ๐Ÿพ๐ŸŽ๐Ÿฅณ๐ŸŽ‰

Case Study: Deploying a Website
A client needs to deploy their website or blog on a public domain, making it easily accessible worldwide via a shared URL. Let's dive into the solution together.

Overview:
Let's get started!
Let's Dive in as we explore the solution together. We'll cover:

  • Deploying a website on a public domain using EC2
  • Step-by-step guide
  • Understanding EC2's features and benefits
  • Graphical illustrations
  • Hands-on steps to resolve the case study

Solution
Introducing EC2: Elastic Cloud Compute
To solve this problem, we'll utilize Amazon Web Services (AWS) popular service: EC2 (Elastic Cloud Compute). But what is EC2? ๐Ÿค”

EC2 provides scalable computing capacity in the cloud, allowing users to run and manage applications seamlessly.

Image description

Why EC2? EC2 is a popular choice for many reasons in terms of the following:

Scalability: Quickly scale up or down to match changing workloads and applications.

Flexibility: Choose from a wide range of instance types, operating systems, and configurations.

Reliability: Enjoy high uptime and reliability, with built-in redundancy and failover capabilities.

Security: Leverage robust security features, including network isolation, firewalls, and encryption.

Cost-effectiveness: Pay only for the resources you use, with no upfront costs or long-term commitments.

Integration: Seamlessly integrate with other AWS services, such as storage, databases, and analytics.

Global reach: Deploy applications in multiple regions and availability zones, with low latency and high performance.

Automation: Easily automate tasks and workflows using AWS tools and services.

Support: Access comprehensive documentation, tutorials, and support from AWS and the community.

In summary: EC2 should give me a virtual machine on your cloud platform (AWS) which is elastic in nature.

Letโ€™s dive with graphical illustrations:

Section A

Step 1: Open your AWS management console.

Image description

Step 2: Locate EC2.

Image description

Step 3: Give your server a server.

Image description

Step 4: Select AMI and instance type

Image description

Step 5: Create and type the name key.

Image description

Congratulation!, You have created your first instance.

Image description

Section B

Now, letโ€™s deploy our server. Steps to deploy server.

Step 1: Click on Connect, and it prompt this page to connect to our server. Select SSH client.

Image description

Step 2: Open your Gitbash (open SSH client).

Image description

Image description

Image description

Step 3: Make sure your directory is located at where your key and run the command line.

chmod 400 "cloud-jay-key.pem"
Enter fullscreen mode Exit fullscreen mode

Image description

Step 4: run the second command line and it request your permission: Yes / No click on Yes to continue

Image description

When you type yes. It shows this

Image description

Image description

Step 5: run this command line:

ssh -i "cloud-jay-key.pem" ec2-user@ec2-34-204-186-40.compute-1.amazonaws.com

Enter fullscreen mode Exit fullscreen mode

Image description

Step 6: check the updated version.

Image description

Step 7: install nginx, prompt yes or now. Click โ€œyesโ€ to install

Before installation of nginx ==> after installation of nginx

Image description

Image description

Image description

Step 8: checking the version of nginx

Image description

Step 9: Test if the nginx is running.

Image description

Step 10: set up inbound rules

Image description

Step 11: click on security rules then click on edit inbound rules

Image description

Step 12: select the option in sequence.

Image description

Step 13: now inbound rules in set.

Image description

Step 14: Test if the localhost is running.

Image description

Step 15: Check the status the nginx (it shows the status is disable)

Image description

Step 16: Start enable nginx and check the status if it enables or running.

Image description

Step 17: Letโ€™s confirm if nginx is running on web browser. (copy public IP address and run it on browser: e.g [google chrome, opera, Mozilla, Brave etc.]).

Image description

Image description

Image description

Congratulation!, Nginx is running on web browser.

Steps to setup an nginx webserver:

  1. Create the ec2 instance - amazon linux.
  2. Connect via ssh using the key on git bash
  3. Update the instance using (sudo yum update)
  4. Install the nginx package (sudo yum install nginx)
  5. Check if installed (nginx โ€“v)
  6. Test using (curl localhost)
  7. Check if nginx is running (sudo systemctl status nginx)
  8. Start nginx using (sudo systemctl start nginx)
  9. Check the status again using step 7
  10. Test using the public IP.
  11. Check and allow traffic on your security group by adding http port 80 rule on IPv4.

Section C

Step Letโ€™s deploy our blogspot on nginx as client requested.
Sample of the website deploy.

Image description

Step 1: We are using a readymade blogspot to deploy our first website for the client. Right click and copy link address.

Image description

Step 2: Enter the dir of nginx html (cd /usr/share/nginx/html) and ls

Image description

Step 3: enter the copied link with the command line:

sudo wget https://github.com/StartBootstrap/startbootstrap-agency/archive/gh-pages.zip
Enter fullscreen mode Exit fullscreen mode

Image description

Step 4: Unzip the file. Run the command line

sudo unzip gh-pages.zip
Enter fullscreen mode Exit fullscreen mode

you can list (view)

ls
Enter fullscreen mode Exit fullscreen mode

Image description

Step 5: now that we have deployed our website, let rename and replace it with our public IP.

Image description

Now the public IP address is replaced with the website. Letโ€™s confirm on web browser.

Image description

Image description

Image description

Congratulations! You've successfully deployed a website on a public domain, making it accessible globally. Please note that the website will be available for access within 12 hours after publication. Unfortunately, I won't be able to keep it running indefinitely due to incurred charges.

URL: 34.204.186.40

Please let me know in the comments if you're able to access the website.

That concludes our Week 4 article! Feel free to reach out to me with questions or to practice what we've covered. Remember, practice is key to mastering these skills.

We're just four weeks away from completing our junior cloud engineering journey! ๐Ÿš€

Stay awesome, everyone! Looking forward to seeing you in my next article. ๐Ÿ˜ƒ

Top comments (0)