DEV Community

Cover image for From Zero to Deployed: Setting Up an Azure VM with Apache2 (Step-by-Step)
Amapakabo, Joseph I.
Amapakabo, Joseph I.

Posted on

From Zero to Deployed: Setting Up an Azure VM with Apache2 (Step-by-Step)

A practical, beginner-friendly walkthrough of deploying an Azure Virtual Machine, configuring a Virtual Network, SSHing in, and hosting a live Apache2 web server — all from scratch.

TL;DR: In this post, I walk through how I deployed an Azure Virtual Machine from scratch — set up the subscription, resource group, virtual network, and finally spun up an Apache2 web server accessible via a public IP. If you're just getting into cloud engineering, this one's for you.


Why This Matters

Cloud infrastructure isn't just for big tech anymore. Whether you're building a side project, preparing for a cloud cert, or just trying to understand what "the cloud" actually means under the hood — knowing how to spin up a virtual machine and serve traffic from it is a fundamental skill.

This post documents my hands-on journey doing exactly that on Microsoft Azure. Every step is screenshotted, so you can follow along visually.

Let's get into it. 🚀


Prerequisites

Before we dive in, make sure you have:

  • An active Microsoft Azure account (free tier works fine to start)
  • Git Bash installed (or any terminal that supports SSH)
  • Basic comfort with the command line

Step 1: Create a Subscription

Everything on Azure lives under a subscription — think of it as your billing and organizational umbrella.

  1. In the Azure portal, search for "Subscriptions" in the top search bar and click on it.
  2. Click Create.
  3. Type your subscription name in the highlighted field (I named mine My VM & Apache Setup).
  4. Click Next and follow through each stage.

Creating a subscription on Azure — filling in subscription name and billing details

Once you've gone through all the tabs, you'll land on the Review + Create screen. Confirm the validation passes and hit Create.

Azure subscription Review + Create screen showing validation passed

💡 If you're on the Azure free tier, a default subscription is usually already set up for you. You can skip this step and move straight to Step 2.


Step 2: Create a Resource Group

A Resource Group is a logical container for all the Azure resources that belong to a project. It keeps things tidy and makes cleanup much easier when you're done.

  1. From the left-hand menu of your subscription, select Resource Groups, then click Create.

Azure portal showing the Resource Groups section under the subscription

  1. Enter the required details — your subscription, a region, and a meaningful name for the group. I used MyVM1-setup and selected (Africa) South Africa North as my region.
  2. Click Next through each section and finalize with Review + CreateCreate.

Create a resource group form with subscription, name, and region filled in

Your Resource Group is now live and ready to house all the resources we'll be creating.


Step 3: Create a Virtual Network (VNet)

The Virtual Network is the private network your VM will operate inside. This is where you define your IP address ranges, subnets, and traffic boundaries. Think of it as building the roads before driving the car.

3a. Create the VNet — Basics Tab

  1. Search for "Virtual Network" in the search bar and click on it.
  2. Click Create, then select your subscription and resource group.
  3. Give your VNet a name and proceed to the next tab.

Create Virtual Network — Basics tab with subscription and resource group selected

3b. Security Settings

Leave the defaults in the Security section and click Next — no changes needed here for a basic setup.

3c. Address Space & Subnets

In the Address Space tab, you'll see a default subnet already configured. I deleted it and created my own to have full control over the IP range.

Create Virtual Network — Address Space tab showing default subnet highlighted for deletion

Click Next through Tags (skip if you don't need them), then select Create in the Review + Create tab.

3d. Navigate to Subnets After Deployment

Once the VNet deploys, you'll see the success screen. Click Go to resource.

Azure VNet deployment complete — 'Your deployment is complete' screen with Go to resource button

Then, in the left-hand menu under Settings, click Subnets. Hit the + Subnet button at the top to add a new one.

VNet Subnets panel showing the + Subnet button highlighted

3e. Add Your Subnet

In the Add a Subnet pane, enter your subnet name and configure the IP address range. I used vm1-subnet with a /24 range (10.0.1.0 - 10.0.1.255 — 256 addresses). Click Add when done.

Add a subnet pane showing vm1-subnet name and 10.0.1.0/24 IP range configured


Step 4: Create the Virtual Machine

Here's where the fun begins. 🎉

  1. Search for "Virtual Machines" in the portal. You'll see the VM dashboard — currently empty.

Azure Virtual Machines dashboard showing no VMs yet with a Create button

  1. Click Create and fill in all the necessary details — name, region, image (I used Ubuntu 24.04 LTS), size, and disk (I went with a 64 GB Standard SSD).
  2. Critical step — Inbound Port Rules: Make sure these two ports are open:
    • Port 22 — for SSH access
    • Port 80 — for HTTP (public web access)

When you're satisfied with your configuration, click Review + CreateCreate.

A prompt will immediately appear asking you to generate and download your SSH key pair. This is non-negotiable — Azure does not store the private key after this point. Download it, keep it safe.

Generate new key pair modal with 'Download private key and create resource' button

Click Download private key and create resource, then Return to create a virtual machine. Wait a few minutes for the deployment to complete.

VM deployment complete screen showing Ubuntu 24.04 LTS VM successfully created


Step 5: SSH Into Your VM

With the VM up and running, it's time to connect to it. Open Git Bash and run the following:

# Navigate to your Downloads folder (where your .pem file is)
cd downloads

# Set the correct permissions on your key file (required for SSH)
chmod 400 vm1key.pem

# SSH into the VM using your key, username, and public IP
ssh -i vm1key.pem mrjoe@20.99.232.218
Enter fullscreen mode Exit fullscreen mode

🔁 Replace vm1key.pem with your actual key filename and mrjoe@20.99.232.218 with your VM's username and public IP address. You'll find the public IP on your VM's overview page in the portal.

You'll be prompted to confirm the host fingerprint — type yes and hit Enter. If the key file and username are correct, you'll be welcomed right in.

Git Bash terminal showing successful SSH connection into the Ubuntu VM

Now update the OS to make sure everything is current:

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Terminal showing sudo apt update running and fetching package lists from Azure Ubuntu repos

sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

Terminal showing sudo apt upgrade -y running and listing packages to be upgraded

Then install Apache2:

sudo apt install apache2 -y
Enter fullscreen mode Exit fullscreen mode

Terminal showing sudo apt install apache2 with package dependencies listed and confirmation prompt

Apache2 starts automatically right after installation. No extra configuration needed. ✅


Step 6: Verify Apache in Your Browser — It Works! 🎉

Open any browser and navigate to your VM's public IP over HTTP:

http://20.99.232.218
Enter fullscreen mode Exit fullscreen mode

If everything went smoothly, you'll be greeted by the Apache2 Ubuntu Default Page — the classic "It works!" screen that confirms your web server is live and publicly accessible.

Browser showing the Apache2 Ubuntu Default Page at the VM's public IP address


What We Built

Let's quickly recap what was set up end-to-end:

Component Purpose
Subscription Billing and organizational container for all Azure resources
Resource Group Logical grouping to manage and clean up project resources
Virtual Network + Subnet Private network environment for the VM to operate in
Virtual Machine (Ubuntu 24.04 LTS) The compute instance running our workload
Apache2 Web server serving HTTP traffic publicly on Port 80

Key Takeaways

  • Networking matters first. Setting up your VNet and subnets before the VM ensures your machine is dropped into the right network environment from day one.
  • Open only the ports you need. Port 22 for SSH and Port 80 for HTTP — nothing more. Security begins at the network layer.
  • Your .pem file is your key — literally. Azure will not store it for you. Lose it and you lose SSH access. Treat it like a password.
  • Apache2 just works. For a quick web server deployment on Ubuntu, it's hard to beat — install, done, live.

What's Next?

This is just the foundation. From here, you could:

  • Point a custom domain at your VM's public IP
  • Set up HTTPS with Let's Encrypt (free TLS/SSL)
  • Deploy a full web application instead of the default Apache page
  • Explore Azure Load Balancers to distribute traffic across multiple VMs
  • Lock down your VM further with Azure Network Security Groups (NSGs)

The cloud is a lot less intimidating once you've actually deployed something and watched it load in your browser. If you followed along and hit any snags, drop a comment below — happy to help.

Keep building. ☁️


#azure #cloudengineering #devops #linux #apache #virtualmachine #beginners #100daysofcloud

Top comments (0)