DEV Community

Jonah Blessy
Jonah Blessy

Posted on • Edited on

Create a simple EC2 instance and run a webserver and access it from outside

To create a simple EC2 instance and host a basic web server, launch a virtual machine on AWS, install a web server on it, and then access it from your browser using its public address.

First, go to the AWS Console and navigate to the EC2 service. From there, click on "Launch Instance". Choose an instance type something simple like t2.micro since it’s lightweight and enough for basic testing. While setting it up, you also need to either create a new key pair or select an existing one. This key pair is important because it’s what you’ll use later to securely connect to your instance.

Next comes the network configuration. Here, we define who can access our instance. For SSH, we usually restrict access to just our own IP so that only we can log in. For HTTP, since we want to access the web server from anywhere, we allow traffic from all sources (0.0.0.0/0). Once all this is configured, we go ahead and launch the instance.

After the instance is up and running, the next step is to connect to it. You can do this using SSH. Once inside the instance, we install a web server. In this case, we use Apache. So we first update the system packages using sudo yum update -y, and then install Apache using sudo yum install httpd -y.

After installation, we start the web server so that it begins listening for incoming requests. We can also add a simple HTML page to verify that everything is working properly. This is usually done by editing files inside /var/www/html.

Finally, to access the web server from outside, we copy the public DNS of the EC2 instance and paste it into a browser. If everything is set up correctly, the webpage we created should load, confirming that our EC2 instance is successfully running a web server and is accessible over the internet.

Top comments (0)