Loading, please wait...

A to Z Full Forms and Acronyms

How to Create a VM to host your web application

Jul 25, 2020 Azure, VM, Host, Web, Application, 4317 Views
In This Article, we'll discuss How to Create a VM to host your web application

Create a VM to host your web application

Like most application frameworks, you can run your MEAN stack application in many different environments. You can run your application on a physical computer in your server room, on a virtual machine, or in containers.

Here you'll run your application on a VM running on Azure. MEAN supports many different operating systems. For learning purposes, here you'll use Ubuntu Linux.

Create an Ubuntu Linux VM

Normally, you create a resource group before you create other resources on Azure. A resource group is a container that holds the resources that are related for an Azure solution. For this exercise, the Azure sandbox provides a resource group for you. However, when you are working in your own Azure subscription, you would use the following command to create a resource group in a location near you.

Azure CLI
az group create \
  --name <resource-group-name> \
  --location <resource-group-location>
  1. From Cloud Shell, run the az vm create the command to create an Ubuntu VM.

    Azure CLI
    az vm create \
      --resource-group [sandbox resource group name] \
      --name MeanStack \
      --image Canonical:UbuntuServer:16.04-LTS:latest \
      --admin-username azureuser \
      --generate-ssh-keys
    

    The command takes about two minutes to complete. When the command finishes, you'll see output similar to this.

    JSON
    {
      "fqdns": "",
      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/MeanStack",
      "location": "eastus",
      "macAddress": "00-0D-3A-1E-1B-3B",
      "powerState": "VM running",
      "privateIpAddress": "10.0.0.5",
      "publicIpAddress": "104.211.9.245",
      "resourceGroup": "[sandbox resource group name]",
      "zones": ""
    }
    

    The VM's name is "MeanStack". You'll use this name in future commands to identify the VM you want to work with

  2. Open port 80 on the VM to allow incoming HTTP traffic to the web application you'll later create.

    Azure CLI
    az vm open-port \
      --port 80 \
      --resource-group [sandbox resource group name] \
      --name MeanStack
    
  3. Create an SSH connection to your VM.

    Although the output from the az vm create the command displays your VM's public IP address, you may find it useful to store the address in a Bash variable.

    Start by running az vm show. This command saves the IP address in a Bash variable named ipaddress.

    Azure CLI
    ipaddress=$(az vm show \
      --name MeanStack \
      --resource-group [sandbox resource group name] \
      --show-details \
      --query [publicIps] \
      --output tsv)

    Connect to your VM like this.

         Bash

    ssh azureuser@$ipaddress

       When prompted, answer "yes" to save the VM's identity locally so future connections are trusted.

       You'll use the SSH connection to configure software on the virtual machine in the next parts

A to Z Full Forms and Acronyms