Skip to main content

Create an Azure Web App

Hands-On Lab

 

Photo of

Training Architect

Length

01:00:00

Difficulty

Intermediate

Azure Web Apps are a fantastic way to deploy and host web applications, mobile apps, and other APIs without having to worry about infrastructure tasks such as OS patching and maintenance. Azure web apps allow us to deploy code using various languages, such as .NET, PHP, Javascript and others, and are available in Windows and Linux platforms. In this hands-on lab, we will be deploying two web apps using the Azure CLI and Visual Studio. We will also deploy and configure the underlying App Service Plan, which defines the computing environment where our Apps will run. #### Lessons learned - Deploying and configuring an App Service Plan using the Azure Portal - Deploying a simple Web App using the Azure CLI - Deploying a functional Web App that integrates with Blob Storage using Visual Studio Community

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Create an Azure Web App

Welcome to this Azure hands-on lab, where we'll be creating a couple of different Web Apps in Azure, and deploying them in different App Service Plans. One will be a single page web app running on Linux and one will be a more complex image uploading app running on WIndows.

Get logged into the Azure Portal using the credentials on the Linux Academy lab page, and let's have a look at the All resources page. We're only concerned with a couple of these, a storage account and the virtual machine. We won't really touch the rest of the resources during the lab.

Download Visual Studio Solution and Sample Images.

The first thing we've got to do is get Visual Studio installed on our virtual machine, so we'll have to use Remote Desktop and log into the Virtual Machine (VM). From the All resources page in the Azure Portal, let's click on our VM, then the Connect button. This will prompt us to download the Remote Desktop Protocol (RDP) file for connecting to the VM. Once we get that loaded up into our RDP client, there are a couple of options we want to set and unset:

  • We don't want to connect to an admin session (that way we can copy and paste)
  • We want to start the session in something smaller than full-screen. A 1024x768 resolution is probably a safe bet.

These login credentials are going to be different than the Portal ones:

Username: azureuser Password: LA!2018!Lab1

Once we've agreed to all of the security and networking prompts, let's get into a Powershell terminal, as an administrator.

The following script will download the PhotoStor Web App and some sample images that we will use in the second part of the lab. We can copy it and paste it right into Powershell:

Add-Type -AssemblyName System.IO.Compression.FileSystem

$url = "https://github.com/linuxacademy/content-az-300-lab-repos/blob/master/create-an-azure-web-app/LA_PhotoStor.zip?raw=true"
$url2 = "https://github.com/linuxacademy/content-az-300-lab-repos/blob/master/create-an-azure-web-app/images.zip?raw=true"

$zipfile = "C:UsersazureuserDesktopLA_PhotoStor.zip"
$zipfile2 = "C:UsersazureuserDesktopimages.zip"

$folder = "C:UsersazureuserDocumentsVS"
$folder2 = "C:UsersazureuserPictures"

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -UseBasicParsing -OutFile $zipfile $url

[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $folder)

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -UseBasicParsing -OutFile $zipfile2 $url2

[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile2, $folder2)

Remove-Item -Path $zipfile
Remove-Item -Path $zipfile2
#

The tailing hashtag is used so we paste and run the script in full

App #1: Using Linux

Deploy a Linux App Service Plan

In the Azure Portal, in the All resources page, we can see that all of our resources have a five-character suffix. It's probably a good idea to use that same suffix when we're naming the App Service Plan.

Now we can click the Green + icon at the top-left hand of the screen. Search for and click on App Service Plan. Create the App Service Plan with the following settings:

  • Name: Choose a name for your App Service Plan. Use something like ASP-XXXXX-Linux, where XXXXX represents the five character suffix of the lab resources (See the VM name for an example).
  • Subscription: Leave as-is.
  • Resource Group: Use existing, choose lab resource group.
  • Operating System: Linux
  • Location: South Central US
  • Pricing Tier: S1 Standard

We can click Create when it all looks good. If we click on the notification bell icon, we'll see when this process finishes.

Set up Cloud Shell

Before we can deploy the app, we need to set up Cloud Shell. Let's do that by clicking the Cloud Shell button (it looks like this: >_ ) in the top-right hand corner of the screen:

We're going to be using Bash. At the prompt about mounting storage, we're going to use the existing subscription in the dropdown, and click on Show advanced settings. We can leave the Resource group, but we won't be able to use our existing Storage account until we change the Cloud Shell region to South Central US. Once we do that, we can pick Use existing from the Storage account section, and then pick ours in the dropdown. In the File share section, choose Create new and specify cloudshell as a name.

It's safe now to click Create storage. In short order, we'll land at a Linux command prompt.

Deploying the App

Back over in the VM (the Remote Desktop session we left running), we're going to deploy our app with a short script. We'll have to make some edits in Notepad on the VM, but first copy these commands:

rgName=$(az group list --query '[].{name:name}' --output tsv)
aspName=$(az appservice plan list --query '[].{name:name}' --output tsv)
az webapp create --resource-group $rgName --plan $aspName --name justanotherwebpp2 --runtime "PHP|7.0"
#

Open up Notepad in the VM, and paste this text in. We need to change --name justanotherwebpp2 to something unique. This name may or may not be unique, but we're going to make sure by changing it to something we know is unique. Let's do webapp1-xxxxx, where xxxxx is that five character suffix we were looking at before. We can copy it all again, then paste it into a Cloud Shell window.

Once everything finishes running, we can close the shell, get into the All resources page, and hit Refresh. We'll see our web app in the list now.

If we click on that web app in the list, we'll land on its overview page. We'll see a URL that we can copy, then paste into a web browser. The standard Azure "Your app service is working" page will show up.

App #2: Using Visual Studio

Up until now, we've only deployed a simple, one-page Web App. Things are going to get a lot more fun. We're going to deploy a fully-functional web application that will allow us to upload images into Azure Blob Storage. Since the backend code was written in ASP.NET, we can't use the App Service Plan that we set up earlier. Instead, we will have to deploy a second plan, one that runs on Windows.

Back in the VM window, let's open up Visual Studio. We can use the credentials provided on the main lab page. Once we're in, we need to pick Open Project / Solution In the Open Project window, we'll need to navigate to where we extracted that image to, way back near the beginning of the lab. It should be a file (as opposed to an identically named directory sitting adjacent to it) called PhotoStor in our Documents/VS/LA_PhotoStor/PhotoStor/ directory. This will take a minute to restore.

Once it's done, check the Error List (in the View menu) to make sure everything completed.

We need to publish this, but before we can do that, we need to create a Web App and a Web App Service Plan

Deploy a Windows Web App and Web App Service Plan

Now we can click the Green + icon at the top-left hand of the screen. Search for and click on App Service Plan. Create the App Service Plan with the following settings:

  • Name: Choose a name for your Web App. Recommendation: Use something like WebApp2-XXXXX, where XXXXX represents the five character suffix of your lab resources (See your VM name for an example).
  • Subscription: Leave as-is.
  • Resource Group: Use existing, choose lab resource group.
  • Operating system: Windows
  • Publish: Code
  • Pricing Tier: S1 Standard
  • App Service Plan: Create a new one with the following settings:

    • Name: Choose a name for your App Service Plan. Use something like **ASP-XXXXX-Windows*, where XXXXX** represents the five character suffix of your lab resources (See your VM name for an example).
    • Subscription: Leave as-is.
    • Resource Group: Use existing, choose lab resource group.
    • Operating system: Windows
    • Location: Central US
    • Pricing Tier: S1 Standard

Note: The location for the Windows App Service Plan isn't South Central US, like with the first one we made. The two must be in different locations.

Click Next: Monitoring > and click No for Enable Application Insights.

Click Review and Create and then, after validation, click Create.

Publish the Web App

Back in our VM (the RDP session we've got running), Visual Studio should still be up. On the right-hand side of the window, We should see a directory tree, with Solution 'PhotoStor' (1 project) at the top of the list. Right click on the next one down (PhotoStor) and then click Publish in the resulting menu.

In the window that pops up, choose Select Existing at the prompt, then click the Publish button. Down in the bottom of this next screen, we can expand the folder in the bottom pane, and we'll see our Web App down there. Select it and click OK. Then we can watch our solution get published.

If we try to test (by going to its URL) we'll get an error, because the publishing process isn't complete yet. Let's wait until Azure fires up a web browser window by itself, then we can go peek.

Attaching Storage

That's great that the Web App is published, but it's not really done yet. This thing is supposed to allow users to upload and display images, but we haven't set up a place to store those images yet. Let's get it done.

Back in All resources, click on the new Windows Web App that we deployed. Scroll a bit down the left-hand menu, and click on Settings, Configuration. We've got to set these three: AccountKey, AccountName, and ImageContainer.

AccountKey

Back on the All resources page, find our Storage account. Click on it, then find Access keys in the left-hand menu, and then copy one of them to the clipboard. Over in our Web App, down in the Application settings section, click Add new setting.

We can paste the key we just copied in the value column. The name should be AzureStorageConfig__AccountKey.

AccountName

Add a new setting, and give it the name AzureStorageConfig__AccountName, and for a Value, stick our storage account's name in there.

ImageContainer

Add one more new setting. Name it AzureStorageConfig__ImageContainer and give it a value of images.

Once we click on Save, we're ready to test. We can either grab the URL from the Overview page when we're looking at our Web App in the Azure resources, or if we've still got our VM open in RDP, we can check over there.

Note that the drag and drop functionality does not work in the Edge browser.

Conclusion

Well, we've done it. We created a fairly simple Web App in Azure, and then made another that was fairly complicated. We got to use both Linux and Visual Studio, and were able to complete all of the tasks successfully. Congratulations!