Step-by-step guide on how to launch an Amazon EC2 t2.micro instance, create a security group that allows inbound traffic on HTTP and SSH, and install Apache web server with a custom webpage using a BASH script

Darius M
3 min readDec 13, 2022

--

Prerequisites

  • Basic understanding of vi/vim
  • AWS free tier account
  • Basic knowledge of linux server
  • ssh
  1. Sign in to the AWS Management Console and navigate to the EC2 dashboard.

2. Click on the “Launch Instance” button to start creating a new EC2 instance.

3. Select the Amazon Linux AMI and choose the t2.micro instance type (which is eligible for the free tier).

4. In the next step, click create security group. Where is says “anywhere” you can either leave it or change it to “My IP” by clicking the down arrow. This will make it so only your ip can connect to the instance via ssh.

5. Select an existing key pair or create a new one, and then click on the “Launch Instances” button.

5. Review the instance settings and click on the “Launch” button to launch the EC2 instance.

Once the EC2 instance is launched, you can access it via SSH using the private key file that you selected or created in the previous step.

  1. Click “connect”

2. Once you are logged in to the EC2 instance, create your bash script by typing.

$vim file_name.sh

3. Copy code snippet, paste into your editor quit and save.

# Install Apache web server
sudo yum update -y
sudo yum install -y httpd
# Start Apache web server
# Change ownership of var directory and select files within so we can write to it
sudo chown -R ''user:user /var/www/html''
sudo service httpd start
# Create a custom webpage
echo "<html><body><h1>Hello World!</h1></body></html>" > /var/www/html/index.html

This script will update the package repository, install Apache, start the Apache service, and create a simple “Hello World” webpage.

After running the script, you can access the custom webpage by going to the public IP address of the EC2 instance in a web browser.

That’s it! You have successfully launched an Amazon EC2 t2.micro instance in a public subnet, created a security group that allows inbound traffic on HTTP and SSH, and installed Apache with a custom webpage using a BASH script.

--

--

Darius M

Cloud Engineer ☁️ IT Specialist| Linux | Dev Ops Enthusiast Nerdy about all things self improvement and Crypto.