Lab 04: Deploying a Code on the Virtual Machine¶
Introduction¶
In this lab, you will deploy a simple web application on the Linux Virtual Machine (VM) you created in Lab 03. We will use Apache, one of the most popular web servers, to host a “Hello World” HTML page.
By the end of this lab, you will: - Understand what Apache is and why it is used. - Learn where to run commands (inside the VM vs. outside on Windows). - Install and configure Apache inside your Linux VM. - Deploy and access a simple HTML web page from both inside the VM and your host machine.
Step 1: What is Apache?¶
Apache HTTP Server is free and open-source software that delivers web pages to users. When someone types your VM’s IP address into a browser, Apache responds by sending back the web page files.
Why Apache? - Easy to install and beginner-friendly. - Stable and widely used across the world. - Perfect for learning how web servers work.
Step 2: Tools You Will Use¶
- Inside the VM: Linux Terminal (open from the VM’s desktop menu).
- Outside the VM (Host Windows 11): A web browser like Microsoft Edge or Chrome to test access from your PC.
- Text Editor inside VM: We will use
nano(a simple text editor in Linux).
Keyboard shortcuts in nano:
- Save:
Ctrl + O, then press Enter. - Exit:
Ctrl + X.
Step 3: Creating a Sample Code¶
We will create a simple HTML file called index.html.
Here is the code:
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a simple webpage deployed on Apache.</p>
</body>
</html>
Do not create it yet — we will add it later inside Apache’s web directory.
Step 4: Setting Up Apache (Inside the VM)¶
-
Open a Terminal inside your VM.
-
Update package lists:
sudo apt update -
Install Apache:
sudo apt install apache2 -y -
Start Apache:
sudo systemctl start apache2 -
Enable Apache to start automatically when the VM boots:
sudo systemctl enable apache2 -
Verify Apache is running:
If successful, open a browser inside your VM and go to:systemctl status apache2You should see the Apache welcome page.http://localhost
Step 5: Deploying the Code (Inside the VM)¶
-
Navigate to Apache’s default web directory:
cd /var/www/html -
Remove the default
index.html:sudo rm index.html -
Create a new
index.html:sudo nano index.html -
Paste the HTML code (from Step 3). Save with
Ctrl+O, press Enter, then exit withCtrl+X. -
Set proper permissions:
sudo chown -R www-data:www-data /var/www/html sudo chmod -R 755 /var/www/html
Step 6: Accessing the Webpage¶
From Inside the VM¶
- Open Firefox (or the browser installed in your VM).
- Enter:
You should see your Hello World page.
http://localhost
From the Host Machine (Windows 11)¶
-
Find your VM’s IP address inside the VM terminal:
Look for a line likeip addrinet 192.168.x.x(not 127.0.0.1). -
Open your browser on Windows 11 and type:
Example:http://<vm-ip>http://192.168.1.55
If your VM networking is set to Bridged Adapter (from Lab 03), you will see the webpage from your host machine.
Troubleshooting Tips¶
- Apache not running: Restart with:
sudo systemctl restart apache2 - Permission denied error: Check permissions on
/var/www/html. - Page not opening on host: Ensure VM network is set to Bridged Adapter in VirtualBox.
- Firewall issues: Allow Apache:
sudo ufw allow 'Apache Full'
✅ You have now successfully deployed and accessed a simple HTML web page hosted on your VM using Apache!