Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
EC2 Web Server | EC2 Overview
Introduction to Cloud Computing
course content

Contenido del Curso

Introduction to Cloud Computing

Introduction to Cloud Computing

1. Introduction to Cloud Technologies
2. AWS S3 Overview
3. EC2 Overview
4. RDS Management

bookEC2 Web Server

Usually, EC2 instances are used to host servers. These servers can perform various functions; it could be a web application server, an online gaming server, or a server with computational power that you can use for your tasks.

Simply put, you rent a computer located remotely, which is consistently maintained. This means you don't have to worry about your server and can focus on other things.

The point I'm getting at is that in this chapter, we'll see how to set up a web server on your instance and host our portfolio HTML page.

Setting Up a Web Server

Just like that, a computer can't become a server. As you may have already understood, an instance is just a regular computer that we rent. We need to install a web server and turn our instance into a server where we can host our web application (website).

We'll be using the Apache web server called httpd.

To install the httpd server on your instance, use the following command:

To check if everything is installed correctly, use the following command:

Next, we need to ensure that httpd will automatically start after the instance is rebooted.

To do this, we need to enable httpd using the following command:

And we will get the response with httpd file system and server location:

Great, you have successfully installed the Apache httpd Server on your instance. Now let's move on to hosting HTML pages on the web server.

Transfering Files to Instance

Now we need to ;transfer the HTML file from our local device* to the instance. To do this, we will use the scp command for secure file transfer from the local machine to the server.

Open the terminal or command prompt on your computer and execute the following command:

  • /path/to/your-key.pem — the path to your private key;
  • /local/path/to/your-file.html — the path to the HTML file you want to transfer;
  • ec2-user — the standard username for Amazon Linux AMI;
  • your-ec2-public-ip — the public IP address of your EC2 instance.

Let's use this command to transfer our portfolio HTML page.

Note

To display this page as the home page, we need to rename the file to index.html. You can do this locally right away, or on the instance, as I will do.

Now let's switch to our instance console and check if the file has been transferred using the ls command:

As you can see, the file has been successfully transferred to the directory we specified.

Placing the File in the Web Server Directory

By default, Apache HTTP Server on most Linux distributions uses the directory /var/www/html to store web pages. You should move your HTML file to this directory using the mv command:

Now our file is in the desired folder. All we need to do now is rename the file and start our server.

Launch the Server

To rename the file, we can also use the mv command specifying the old and new filenames. Let's navigate to the directory where our file is located and use the necessary command:

You can also check the contents of the file using the cat command.

Now that our HTML file is in the desired directory, all we need to do is start the server.

This is done with the following command:

As you can see, the server is now active and ready to use.

To view our HTML page, you need to navigate to the public IPv4 address of your instance.

Note:

Notice that the server is running on port 80, which means it's using the HTTP protocol. Some browsers default to the HTTPS protocol, so your page may not display. To fix this issue, manually change "https" to "http" in the URL.

This is the website we've hosted:

Thus, we've installed a web server on our instance and hosted our HTML portfolio page on our server.

Great job!

1. What software do you install on an EC2 instance to set up a web server?
2. How can you transfer an HTML file from your local computer to the EC2 instance?
3. Which directory is typically used by Apache HTTP Server to store web pages on most Linux distributions?
What software do you install on an EC2 instance to set up a web server?

What software do you install on an EC2 instance to set up a web server?

Selecciona la respuesta correcta

How can you transfer an HTML file from your local computer to the EC2 instance?

How can you transfer an HTML file from your local computer to the EC2 instance?

Selecciona la respuesta correcta

Which directory is typically used by Apache HTTP Server to store web pages on most Linux distributions?

Which directory is typically used by Apache HTTP Server to store web pages on most Linux distributions?

Selecciona la respuesta correcta

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 6
some-alt