DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Learn More About AWS DevOps Architecture and Tools
  • How to Install VPN on Linux?
  • Reasons Why You Should Get a Cloud Computing Certification
  • Optimize AWS Solution Architecture for Performance Efficiency

Trending

  • The Role of AI in Identity and Access Management for Organizations
  • Understanding IEEE 802.11(Wi-Fi) Encryption and Authentication: Write Your Own Custom Packet Sniffer
  • How to Convert XLS to XLSX in Java
  • Dropwizard vs. Micronaut: Unpacking the Best Framework for Microservices
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. How to Launch an Instance and Host a Website With AWS EC2

How to Launch an Instance and Host a Website With AWS EC2

Take a look at how this tutorial that demonstrates how to create a website and host it with AWS EC2.

By 
Vipul Singh user avatar
Vipul Singh
·
Updated Aug. 16, 19 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
45.5K Views

Join the DZone community and get the full member experience.

Join For Free

In this tutorial, we will learn how to launch an EC2 Server, the Ubuntu Linux Virtual Server and host a website by serving index.html.

What is AWS?


Amazon Web Services (AWS) is an Amazon subsidiary which offers cloud-computing services at very affordable rates, therefore making its customer base.

Key AWS Services are EC2, RDS, S3, and CloudFront. There are a total of 140+ services which covers compute, storage, databases, analytics, networking, mobile, developer tools,
management tools, IoT, security, and enterprise applications.

Amazon EC2 Instance

Amazon Elastic Compute Cloud (Amazon EC2) provides scalable computing capacity in the AWS Cloud. In other words, it provides us with a virtual server with different capacities to best suit your needs. Amazon EC2 enables you to scale up or down to handle changes in requirements or spikes in traffic with ease

An on-demand EC2 instance from AWS is one in which the user can rent the virtual server per hour and use it to deploy his/her own applications.

Step 1: Launch an Instance



  • Log into the AWS console.

  • From the top right corner of the EC2 dashboard, choose the AWS Region in which you want to launch the EC2 server.

  • From the dashboard, choose Launch Instance.

Choose Amazon Machine Image (AMI)

Amazon Machine Image or more commonly known as AMI which includes an operating system, and required software/Applications which depends on AMI.




For our example, we will use Ubuntu Server 18.04 LTS (HVM), SSD Volume Type (This image is free tier eligible).

Click Select to choose AMI.

Choose EC2 Instance Types

In the next step, we need to choose the instance type. For our case, we will use t2.micro which is free tier eligible.


Configure the Instance

For our case, we can leave default settings.

Number of Instance – How many Instances you wish to launch, one in our case.

Purchasing Options – Launching in On-Demand pricing (We can also choose spot instance)

Read more on Spot Instances.

I will write a detailed description on full settings later.


Click on Next: Add Storage.

Add Storage

Elastic Beanstalk (EBS) Volume is a Virtual Hard Disk in the cloud.

Volume type Root indicates that Root volume will be partition from where our OS will boot.

We can add additional partitions if we want by clicking Add New Volume.

Delete on Termination means the EBS will be deleted if we delete the EC2 instance.


Add Tags (optional)

Add tags provides a key-value pair to mark your instance, It can be used for better cost analysis.

It is very useful in case of large infrastructures with many Instances.

Click Next: Create a Security Group.

To read more on Tags read here.

Configure Security Groups

Security Groups are like firewalls that define what type of traffic we want to allow.

Since we wish to SSH (port – 22) into our EC2 Server and allow web traffic through HTTP (port – 80) and HTTPS (port – 443).

We will also set the source as My IP for SSH and for web traffic i.e., HTTP and HTTPS we will put Anywhere.



Click Review and Launch.

Review Instances

Review the instance settings and hit launch.

We will get a dialog where we will create a Public and Private key pair. The private key is stored in Instance and the public key is given to user do not let anyone know your public or private key otherwise they may use it to compromise your virtual machines.



Click on Download Key Pair to download key pair and keep it safe.

After a successful launch of instance, you will be taken to the Instance screen.

When the status of Server change from pending to running, you can SSH into your Server to perform access.

SSH into our machine and install the webserver.

Check your public address from instance details or assign an elastic IP.


After allocating address you must attach it to your Server.

Choose an Instance from the drop-down menu and click Associate to attach it to Server.



Now we need to SSH into our server (Here we are using AWS Dashboard but we can also use putty or terminal to access SSH, more on that later ).

ssh -i <path_to_key_pair_file> ubuntu@<public_ip_from_dashboard>


Let’s sign it to superuser (root) by –

 sudo su 

Now let’s update all services/packages and install apache web server –

apt-get update

apt-get install apache2



Now let’s start the service:

 service apache2 start Server index.html

You must have your files to be served

By default apache2 web server serves a index.html from location /var/www/html, now lets copy your code and paste in this directory (/var/www/html).

We need to reload apache2 web server now. Type the following command:

 service apache2 reload 

Now let’s check on the browser if our website through index.html is served or not.

Copy public address or Elastic IP of your Server from EC2 console by selecting your Server and paste it on the browser.

AWS Amazon Web Services Amazon Machine Image Host (Unix) Cloud computing Database Web server Web Service

Published at DZone with permission of Vipul Singh. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Learn More About AWS DevOps Architecture and Tools
  • How to Install VPN on Linux?
  • Reasons Why You Should Get a Cloud Computing Certification
  • Optimize AWS Solution Architecture for Performance Efficiency

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!