Launching a simple EC2 Instance with Apache Web Server — Part 1
Tags: aws, ec2
Published: 2024-03-11 02:06:15

**Little backstory:** I’ve had this in my drafts for a while, wanting to do it all as one article. I’ve decided that is not the best way of presenting this information. As a newer content creator, I’ve been playing with how I want my pages to look like, and have decided to go with how it looks right now.

---

**Introduction**

In this article, I will be doing what some call “click-ops” in AWS console as that is the easiest way to get started. If you want more challenges, I will also be posting on how to use AWS CLI (an article post on this will come at a later date, when completed, I will be updating this with a link to it!) to do the same thing. I will also show how to use a Cloud Development Kit (CDK). I will be using Python in my CDK examples. I will also use AWS CloudFormation. Finally, for an even more advanced challenge, I will be creating this process again using Terraform. If you are new, the console way will be the easiest, but I also want to introduce you to the CLI, CDK, CloudFormation and Terraform as these are advanced tools used!

---

**Scope of this tutorial**

In this multi-part tutorial, we are wanting to set up an EC2 instance, configure security group(s), create a key-pair SSH Key to remote into the instance, and install Apache Web Server.

---

**Method 1:** Using AWS Console (without using userdata)

There are actually two ways we can use the AWS console to create the EC2 instance, and install Apache and run it and create the test HTML file. This method will require us to use SSH to remote into our EC2 instance to preform some steps.

**Step 1:** When you are logged into the AWS Console, search for EC2 in the search bar.

![AWS Console and searching for EC2 via the search bar.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4zyev7c4psyzew0g3qc.png)

**Step 2:** Click on Launch Instance

![EC2 console dashboard with Launch Instance button shown](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oc5cveduvfa026ric38d.png)

**Step 3: Configure your instance and install Apache and test web page**
* Give the instance a name, I called mine “Web Server Test”    * Keep the application and OS Images as is
* Keep the instance type as t2.micro
* Click on new key par and give it a name, then click on Create key pair. It’ll download a file, move it to a safe location so you don’t loose it!

![Creating a Key Pair](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0hh4oktrmp3ybdz4tamw.png)

* Under Network settings we will be keeping the selection Create Security Group. Allow SSH traffic from should be checked, and you’ll also want to check the Allow HTTP traffic from the internet. Next to SSH there is a dropdown menu that you can say any IP can connect to the instance, a custom IP or range, or your IP only. For this example, I’m keeping it as anywhere

![Creating the security group through the Launch Instance Wizard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qkjbaspm7g42ml0noft.png)

* We will leave everything else as default
* Click on Launch Instance

![showing the instance was created successfully from the wizard with a green success box with a link to view that instance.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cdmu9ixhn5z1q1aojh66.png)

* Click on the instance ID shown in the green success box

![Instance shown as running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2f8tylkz28vctdvo66h7.png)

* Click the checkbox next to the instance, then go to actions and click on Connect

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u6heinfunm0n0qa33im0.png)

* You’ll see there are four options of connecting. The only two that will work with our instance, due to the way we set it up, is EC2 Instance Connect and SSH client. If on Mac or Linux you can use command line to SSH into the instance’s command line, on Windows it is easiest to use a tool such as Putty.

![Showing the connect options, and the EC2 Instance Connect we are using in our example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lz3upox6kyi44xmu35e7.png)

* We will be using EC2 Instance connect in our case, so click on that tab, then click on connect
* After waiting a few moments, you’ll see a command line terminal for our instance.

![The command line interface via EC2 Instance Connect](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u32gmo2qevknel0gch3g.png)

* We now want to install Apache and start the service. Run the following commands in the command prompt.

```sh
sudo yum update -y # We are asking the packacge manager to install any updates
sudo yum install httpd -y # We are asking the package manager to install Apache
sudo systemctl enable httpd # We are telling the server to automatically start Apache upon start up
sudo systemctl start httpd # we are telling the server to start the Apache Server
sudo systemctl status httpd # we are telling the server to tell us the status of the Apache Server
```

![Results of some of the commands and showing that Apache is running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mvehd68fidaww8mxccfy.png)

* We are going to create a simple HTML file, run the below command to open a new file using a command line text editor

`sudo nano /var/www/html/index.html`

* Put the following code into the text editor

```html
<!DOCTYPE html>
<html>
  <head>
    <title>Test Web Page</title>
  </head>
  <body>
    <h1>Welcome to my website!</h1>
    <p>I love AWS</p>
  </body>
</html>
```

* When you are done with the file, press ctl and x, it’ll prompt you if you want to save, type Y, press enter, then press enter again.
* Go back to the EC2 Instances page, click on your instance, then click on open address under the Public IPv4 address, change the HTTPS to HTTP

![You should see your test page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ngmx3ft4etn2f5upp5t.png)

* If you see your test page, you were successful!

**Step 4: Clean Up**

* Close all windows except for the Instances window.
* Select it, then click on Instance state then click on Terminate instance so you don’t use up your free trial credits or get charged!

Congrats! You have just launched a simple EC2 Web server!

---

[Launching a simple EC2 Instance with Apache Web Server — Part 1 (AWS Console)](https://dev.to/aws-builders/launching-a-simple-ec2-instance-with-apache-web-server-part-1-33nl)

Launching a simple EC2 Instance with Apache Web Server — Part 2 (AWS Console with Userdata) (Coming Soon)

Launching a simple EC2 Instance with Apache Web Server — Part 3 (AWS CLI with user data) (Coming Soon)

Launching a simple EC2 Instance with Apache Web Server — Part 4 (Terraform with user data) (Coming Soon)