Getting Started with Microsoft Azure Web App

Aryan Garg Last Updated : 31 Jul, 2022
6 min read

This article was published as a part of the Data Science Blogathon.

Introduction

In today’s era, Cloud Computing has become a basic need for every startup or business. Now, developers can quickly develop their applications in the cloud and present them to the end users. Below are some benefits of cloud computing:

1. Hardware Security: It takes backup of all your data in several networks. So your data remains safe in case of hardware failure or power loss.

2. Scalability: Developers can scale up or down the application’s resources based on the fluctuating workloads.

3. Convenience: It enables remote user access, i.e., multiple people can remotely access the server and work on it. It saves time and resources for the companies.

4. Payment Mode: You can access various types of hardware like Virtual Machines, Kubernetes Engine, and Databases. Also, you can customize these services according to your requirements. You have to pay only for your services and how long you have taken.

Below are some more benefits of cloud computing:

Source – https://www.cuelogic.com/blog/advantages-of-cloud-computing

Now, let us talk about a famous cloud computing service Microsoft Azure. It is a public cloud computing platform that provides various services like Compute Engine, Storage, Networking, etc.

This tutorial talks about creating a Web App at Azure, and then we deploy web applications on it. I will show you how can deploy a Django Web Application on this Web App.

We will start everything from the very basics. You can also read this article even if you don’t have any prior knowledge of the Azure Platform.

Prerequisites

1. You must have an active paid account on Azure, as most are paid services. If you are a college or university student, you can check my article on creating a free student account on Azure without a Credit or Debit card.

2. Basic knowledge of developing web applications.

3. GitHub link for the code used in this tutorial: link

Let’s get started, 😉

Creating Web App

1. Open the Azure Portal

2. Navigate to App Services.

Microsoft Azure web app

3. Click on +Create.

web app

4. Fill up the below configurations according to your requirement:

  • Create a resource group or use a previous one if you have any.
  • Enter the name of your app (This also be the domain name to access your app).
  • We will deploy the app through the code, so please select code. You can also set a Docker Container if you have any Docker Image or even deploy some static web pages.
  • We want to deploy a Django Application, so we require a Python runtime stack, so select Python 3.9
  • Choose a Linux Operating System.
  • Finally, select the region of your server.
microsoft azure web app

5. Select the CPU and RAM Configurations

Select the configurations of your CPU and RAM according to your budget and requirements. We have chosen a free tier plan that provides one Gb of memory.

CPU and RAM configuration

6. Finally, click on Create Button. After creating the app, we will set up the Deployment and Networking part.

web app

 

7. Access the web app using your domain name

microsoft azure

When you hit your domain name, a sample static page is displayed, as no deployed app is currently on it.

Sample Web Application

Below is the code for the sample Django Application we will use to deploy in this tutorial. You can use your application also if you have any.

Fork this repo into your GitHub account.

sample web app

It is a simple web-based application made in Django REST Framework and performs basic CRUD Operations.

Setting Environment Variables

Our azure web app is now created, and in this section, we will set up the application’s environment variables.

Environment Variables are the variables used to set the configurations of your program and affect how it runs. These variables are written outside of your main program. For ex-, We can store the Secret API Key or some variables that can connect your app with some other 3rd party services.

1. Navigate to Configuration

 

web app configuration

2. Click on +New application setting

web app

Enter the key and value of the environment variables that you want to use in your app.

But for the sample code, we will store the Django Secret Key and DEBUG status as Envy Variables. Debug status is used to check whether our application is in development mode or production mode.

SECRET_KEY=django-insecure-=wez=%szc194fukmp&l@ql$tyq(pb#)yh58k(e*#$831%kudli
DEBUG=True
web application settings

Deploying the Application

This section will discuss the deployment of our application using GitHub.

Note:
a) requirements.txt” must be present in your directory, which contains information on all the libraries and dependencies used in your application. Otherwise, you will get an error during deployment.
b) You must add the domain name in the ALLOWED_HOSTS of your Settings.py file on Django. Or you can select the ALLOWED_HOSTS as “*” to allow all the incoming host names.

$ ALLOWED_HOSTS = ['*']

1. Navigate to Deployment Center

deployment centre

2. Go to Settings, and in Source, select GitHub

deployment centre

3. Authorize your GitHub account and select the Repository and Branch you want to deploy.

You can also check the Workflow Configurations, which contains all the step-by-step commands Azure runs to deploy your applications.

Finally, click on Save.

deployment center | web app

4. You can also check the logs of your application. If any errors occur during the deployment will show here.

deployment center | web app

5. After the successful deployment, access your webpage through your domain name.

Sample Deployed Application – https://aryanapp.azurewebsites.net

api documentation

Congrats ✌, we have deployed our application successfully.

Conclusion

We successfully created a Web App at Microsoft Azure and deployed a sample Django application on it. Other than Django, NodeJS or Microsoft NET Framework applications can also be hosted on this web app. You have to change the runtime stack accordingly while creating your web app. Like we have chosen Python 3.9 for Django.

Currently, Microsoft Azure has provided you with a .NET domain name. But you can also change that domain to a custom .com or .in domain name and get a valid SSL certificate. Scaling up or down your application according to the traffic is also present. There are various more services which you can explore on your own.

Key takeaways of this article:
1. Firstly, we have discussed Cloud Computing and its benefits.
2. Then, we set up a Web App at Microsoft Azure.
3. We have created the Environment Variables used in the sample application.
4. Finally, we have deployed the Django application on a live server.

It is all for today. I hope you have enjoyed the article. You can also connect with me on LinkedIn.

Do check my other articles also.

The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.

I am currently pursuing my Bachelor of Technology (B.Tech.) in Electrical Engineering and Engineering from the Indian Institute of Technology Jodhpur(IITJ). I am very enthusiastic about Machine learning, and Software Development. Feel free to connect with me on Linkedin.

Responses From Readers

Clear

Congratulations, You Did It!
Well Done on Completing Your Learning Journey. Stay curious and keep exploring!

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details