Set Up a Web Server on a VM Instance
Install Apache and Host a Static Website
Introduction
A Virtual Machine (VM) allows us to create a virtual server in the cloud or on a hypervisor. In this task, we set up a web server on a VM instance, install Apache Web Server, and host a simple static website.
Requirements
- VM instance (Linux – Ubuntu recommended)
- Internet connection
- SSH access to VM
- Basic command line knowledge
Step 1: Create a VM Instance
You can create a VM on:
- Google Compute Engine
- Microsoft Azure
- Amazon EC2
Choose:
- OS: Ubuntu 20.04 or 22.04
- Allow HTTP (Port 80) in firewall
Step 2: Connect to VM
Connect using SSH:
ssh username@your_vm_ip
Step 3: Update System Packages
sudo apt update
sudo apt upgrade -y
Step 4: Install Apache Web Server
sudo apt install apache2 -y
Check Apache status:
sudo systemctl status apache2
Start Apache if not running:
sudo systemctl start apache2
Enable Apache to start automatically:
sudo systemctl enable apache2
Step 5: Allow HTTP Traffic (If Required)
sudo ufw allow 'Apache'
Or allow port 80:
sudo ufw allow 80
Step 6: Test Apache Installation
Open browser and enter:
http://your_vm_ip
You should see the default Apache welcome page.
Step 7: Host a Static Website
Navigate to Apache root directory:
cd /var/www/html
Remove default file:
sudo rm index.html
Create a new HTML file:
sudo nano index.html
Add simple static website content:
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
</head>
<body>
<h1>Hello World!</h1>
<p>This is my static website hosted on Apache Web Server.</p>
</body>
</html>
Save and exit (CTRL + X → Y → Enter).
Step 8: Access Your Website
Open browser:
http://your_vm_ip
You will see:
Hello World!
This is my static website hosted on Apache Web Server.
Directory Structure
Default Web Directory:
/var/www/html/
All static files (HTML, CSS, JS, Images) should be placed here.
Advantages of Hosting on VM
- Full control over server
- Custom configurations possible
- Scalable (resize VM)
- Supports dynamic websites also
Conclusion
By installing Apache on a VM instance, we successfully created and hosted a static website. This demonstrates Infrastructure as a Service (IaaS), where users manage operating systems, applications, and configurations while the cloud provider manages hardware.
Viva Questions with Answers
1. What is a VM?
A Virtual Machine is a software-based virtual computer.
2. Which web server was installed?
Apache Web Server.
3. What is the default Apache directory in Ubuntu?
/var/www/html
4. Which port does Apache use by default?
Port 80.
5. What type of website was hosted?
A static website.
