Learn How to: “Add Files to the index.html File from S3 Bucket Storage and Run It on the Browser via Termius on an EC2 Instance”
Tags: ec2instance, webdev, beginners, aws
Published: 2023-08-17 08:13:21

Welcome to this comprehensive guide on adding files to the index.html file from a S3 bucket and running them on a browser using Termius via an EC2 instance. In this blog, we'll walk you through the steps to harness AWS services for web development and cloud computing.

**What We Will Learn and Why It Matters:**
You will learn how to use S3 for file storage, launch EC2 instances to host your web applications, and manage your instances with Termius. This knowledge is essential for web developers and cloud enthusiasts looking to securely and efficiently deploy their applications in the cloud. By the end of this tutorial, you'll have a functional web application accessible via a public IP address and ready to be explored by users worldwide.

<u>**Step-by-Step Guide:**</u>

**1. Open the EC2 Instance:**
Access your EC2 instance in the AWS Management Console and copy the "Public IPv4 address" for later use. For example: "_3.0.184.216_".

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

**2. Configure Security Group:**
Scroll down and navigate to the "Security" tab. Open the "Security groups" link, click the "Edit inbound rules" button, and add a new inbound rule for port 8081. Save the rules for later use.


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


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

**3. Connect via Termius:**
Click the "Connect" button mentioned on top of the instance details. 

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

You can choose either the "EC2 instance Connect" tab or create a new Host on Termius.

**4. Create a Termius Host:**
Open Termius, press "New HOST," and provide a meaningful label (such as "_demoinstance_"). Enter the EC2 instance's Public IPv4 address, set the username as "ubuntu," and import the key pair file.


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


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

**5. Start the Host:**
Start the host by clicking the icon on the top-right corner of the panel.


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

Now you are ready to proceed with adding an image to the index.html file from S3 and running the index.html file on the browser using the EC2 instance.

**[Instructions to Add Files to the index.html File and Run It on the Browser]**

Execute the following commands after opening the host:

1. <u>Update Package Information:</u> **sudo apt update**
2. <u>Install Apache Web Server:</u> **sudo apt install apache2**
3. <u>Open Apache Port Configuration File:</u> **sudo nano /etc/apache2/ports.conf**
4. <u>Change Working Directory:</u> **cd /var/www/html**
5. <u>List Files in the Directory:</u> **ls**
6. <u>Remove Existing index.html File (if any):</u> **sudo rm index.html**
7. <u>Create a New index.html File:</u> **sudo nano index.html**
8. Write your HTML code inside the file and include the "Object URL" link of the file you uploaded to your S3 bucket. Save the file and exit the text editor.
_Example:_ ![Link the file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s0akjkk995xceeh65t00.png)
9. <u>Edit Apache Port Configuration:</u> **sudo nano /etc/apache2/ports.conf**
Edit the port number next to "Listen" in the file. For example: "8081". Save the file. 
![8081](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x8c05zio0fsvpseaj82e.png)
10. <u>Edit Apache Default Virtual Host Configuration:</u> **sudo nano /etc/apache2/sites-enabled/000-default.conf**
Edit the port number next to "VirtualHost" in the file. For example: "8081". Save the file. ![type](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4nc1oosr4t8znkgo1t3.png)
11. <u>Restart Apache Server:</u> **sudo service apache2 restart**
12. <u>Open Your Browser and Navigate to your EC2 Instance:</u>
 Open your browser and click your instance's "Public IPv4 address". You will be redirected to a new tab. 
13. <u>Edit URL: </u>
Add ":your port number" at the end of your URL and remove the "s" from "https" in the URL. 
For example, if your Public IPv4 address is "3.0.184.216" and your port number is "8081," the URL will look like this: "http://3.0.184.216:8081/".
![browser](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lotfg5mxkiumwusk5n8h.png)

Congratulations! You have successfully added files to the index.html file from S3 and run your web application on a browser using an EC2 instance via Termius. This accomplishment marks the beginning of your exciting journey into the world of AWS, web development, and cloud computing. Now, you have the tools to deploy and manage your applications with confidence. 

Feel free to explore more AWS services and further enhance your web projects. 

Happy coding!


<u>**Reference Links:**</u>

_**Previous Blogs:**_

• [Getting Started with AWS S3: Create Your First Bucket and Upload a File](https://dev.to/awscloudclubs/getting-started-with-aws-s3-create-your-first-bucket-and-upload-a-file-192)

• [Getting Started with AWS EC2: Create Your First EC2 Linux Instance](https://dev.to/awscloudclubs/getting-started-with-aws-create-your-first-ec2-linux-instance-159h)

**_Download Termius:_** 
[https://www.termius.com/](https://www.termius.com/)