Building Scalable Web Apps Using Azure: Part 1

Building Scalable Web Apps Using Azure: Part 1

Scenario:

Let's say your company needs to deploy a web application that requires a secure and scalable environment. You are tasked with creating an Azure VM that hosts a web server running on Ubuntu, which will serve a small to medium-sized user base. The VM should be accessible via SSH for administration and through HTTP/HTTPS for web traffic.

Step 1: Set Up Azure Account

  1. Sign in to the Azure Portal:

    • Go to https://portal.azure.com and sign in with your Azure account. If you don’t have an account, you can create one.

Step 2: Create a Resource Group

Resource groups are logical containers for Azure resources.

  1. Navigate to Resource Groups:

    • Search for "Resource groups" in the Azure Portal and click on it.

  2. Create a New Resource Group:

    • Click on "Create."

    • Choose your Subscription, in this example, I am using Azure subscription 1

    • Enter a Resource group name (am using eastus-rg to group all our East US resources).

    • Select a Region (e.g., "East US" as shown in the image below).

Click on "Review + create" and then "Create."

Step 3: Create the Virtual Machine

  1. Navigate to Virtual Machines:

    • Search for "Virtual Machines" in the Azure Portal and click on it.

  2. Create a New Virtual Machine:

    • Click on "Create" and then "Azure virtual machine."

    • In the "Basics" tab, select your Subscription and the Resource group we created ("eastus-rg").

    • Enter a Virtual machine name (a unique name within the resource group e.g., "webAppVM"), supply other information as shown below, and leave the other default information.

    • Set the Authentication type to "SSH public key."

    • Enter a Username (e.g., "azureuser" or any other name of your choice).

    • Upload your SSH public key.

    • Leave other settings as default.

    • Click "Next: Disks."

Step 4: Configure Disks

  1. Choose an OS Disk Type:

    • Select "Standard SSD" for a balance between cost and performance.

    • Click "Next: Networking."

Step 5: Configure Networking

  1. Configure Network Settings:

    • The Virtual Network (VNet) and Subnet are automatically created; you can use these defaults.

    • Ensure Public IP is set to "Enabled" (so you can access the VM).

    • Under NIC network security group (NSG), select "Basic" and allow SSH (22) and HTTP (80).

    • Select "Delete public IP and NIC when VM is deleted." checkbox That way, you will not be billed for an unused public IP address you forgot to delete after deleting the VM.

    • Click "Next: Management."

    • Leave other settings as default.

Step 6: Review and Create

  1. Review Settings:

    • Review the configuration settings for your VM.

    • Scroll down and click on "Create" to deploy the VM.

You will be prompted to download the SSH Keys, Click on "Download private key and create resource."

Step 7: Access the Virtual Machine

  1. Connect to the VM:

    • Once the VM is deployed, click on "Go to resource." or You can access the VM at a later time by searching for "Virtual Machines" in the search bar and then selecting the VM you want to view.

    • navigate to the "Virtual Machines" section.

    • Ensure you VM Status is running and you also need to copy the public IP address to login to the VM using SSH

      In this example, the public IP address is 52.170.74.101, yours will be different.

    • Under the "Overview" tab, click "Connect" and select "connect."

    • Click "Select" under the Native SSH option

    • Follow the instructions to SSH into your VM using the public IP address.

    • Locate you "Download folder", right click and select Git Bash

typy ls -l *.pem

Finally we are login to our VM

From this out put we can see our SSH key file name is webAppVM_key.pem, and our IP address is 52.170.74.101 from the previous image in this example, again yours will be different, so copy yours from the Overview section.

Next, we need to change the permissions on the file

Step 10: Set Up the Web Server

  1. Install Apache (or another web server):

    • Once logged into your VM via SSH, update the package list:

        bashCopy codesudo apt update
      
    • Install Apache:

        bashCopy codesudo apt install apache2 -y
      
    • Ensure Apache is running:

        bashCopy codesudo systemctl status apache2
      
  2. Open Ports for HTTP/HTTPS:

    • Go to the "Networking" tab of your VM in the Azure portal.

    • Click "Add inbound port rule."

    • Add rules for HTTP (80) and HTTPS (443).

Step 11: Test the Web Server

  1. Access the Web Server:

    • Open a web browser and navigate to the VM's public IP address (e.g., http://<your-vm-ip>).

    • You should see the Apache default welcome page.

Step 12: Secure the Web Server

  1. Install SSL (Optional for HTTPS):

    • You can install a free SSL certificate from Let's Encrypt using Certbot.

    • Follow the instructions from Certbot's website to secure your site.

Step 13: Clean Up (Optional)

  1. Remove Resources:

    • If you no longer need the VM, you can delete the resource group ("WebAppResourceGroup") to remove all associated resources.

This process will give you a fully functional web server running on an Azure VM.