Deploy a website with Azure virtual machines - Creating Virtual machine

June 15, 2023 by Anuraj

Azure IAAS Virtual Machine

This post is about how to deploy an ASP.NET Core web application in Azure Virtual machines. This is part of series where we will be discussing about setting up web server, configuring custom domains, creating and installing SSL certificate in web server and finally configuring CI / CD pipelines to deploy our application to Azure VM from Azure DevOps. In this blog post we will be exploring about creating a Virtual Machine in Azure, how to configure IIS web server and deploy an ASP.NET Core application to the virtual machine.

We will be using Azure CLI to create and configure the server.

  1. First we need to login to Azure account using Azure CLI. We can use the az login command to access out Azure account.
  2. Once logged, we can execute the following command to create a resource group - az group create --name webserver-us --location centralus
  3. Next we can create the Azure virtual machine with the command - az vm create --resource-group webserver-us --name dotnetthoughts --image Win2022AzureEditionCore --public-ip-sku Basic --admin-username azurewebuser. If we execute this command, it will prompt for the admin password. Or we can use --admin-password parameter to accept the admin password. This might take some time.
  4. After the VM is created, we can use the following command to install IIS web server on the virtual machine - az vm run-command invoke --resource-group webserver-us --name dotnetthoughts --command-id RunPowerShellScript --scripts "Install-WindowsFeature -name Web-Server -IncludeManagementTools".
  5. And we need to enable port 80 - for IIS web server. We can do this with the following command - az vm open-port --port 80 --resource-group webserver-us --name dotnetthoughts.
  6. Now we created and configured web server. To browse we can get the IP address with the following command - az vm list-ip-addresses --resource-group webserver-us --name dotnetthoughts --output table
  7. And we can copy the PublicIPAddresses column and paste it on the browser - which will show the IIS default page, like this.

Azure VM IIS default page

In the next post we will be configuring a custom domain for the Azure virtual machine.

Happy Programming.

Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub