Azure is a cloud computing platform offered by Microsoft that provides a wide range of services and features for building, deploying and apps and services in the cloud.

If your application needs to interact with Azure's AI and ML services then it makes sense to deploy your Django app to their infrastructure.

In this article you will see how to deploy your Django application on Azure VM.

If you are looking for tutorial for another cloud provider checkout out one of these:

Table of contents

Requirements

  1. An application to deploy
  2. Appliku Account
  3. Azure Account

Django Application

Your Django app should be pushed into a GitHub, GitLab or any other repository.

Make sure that:

  • There is a requirements.txt file in the root of the repository with all dependencies
  • The Procfile in the root of the repository with commands needed to run your app Check this example
  • Application respects environment variables, e.g. DATABASE_URL for database credentials

We have a full Django with Docker and Postgres Tutorial if you want to learn more.

Also you can check our SpeedPy.com SaaS boilerplate

Appliku Account

If you don't already have an Appliku Account create it by going here: https://app.appliku.com/

Click on "Add a server"

Pick a Custom Server:

Select this key, we will need it at server creation step.

Azure account

If you don't already have an Azure account you should sign up here.

When you created your account, log in and you will see a welcome screen. Click on "Go to Azure portal"

Click on "Deploy a Virtual Machine"

Click "Create" under "Create a Linux virtual machine"

You will see the page "Create a virtual machine" with a lengthy form fll of options.

First, create a new "Resource group" by clicking "Create new"

Write a name for it and click OK

Scroll down, and in the section "Instance details" give server a name and select a region for your server.

For the "Image" option chose Ubuntu 20.04 LTS

Scroll down and find "Size". Click on "see all sizes" and pick the one that suites your needs. For the purpose of this tutorial we will pick the one market "Free services" and click "Select"

For authentication type choose "SSH public key".

You can leave "azureuser" for the "Username", you can't specify "root" here.

Add a public key given to you in the Appliku dashboard earlier.

For the "Public inbound ports" select Allow selected ports and in the dropdown select HTTP(80), HTTPS(443) and SSH (22)

Then click "Review + create"

You are presented with the overview of a server to be created. Click "Create" at the bottom of the screen.

Azure VM creation will begin. Wait for it to finish.

When the server is created – click on Go to resource.

You will see the overview of the server. We need the IP address of the Azure VM.

It is on the right, hover over the IP address to see the copy icon. Click on it to copy.

Go back to the Appliku Dashboard and paste IP address and type "azureuser" for the username and click "Check credentials and add server"

You will see that server is added and soon will start setting up.

Watch for "Setup Status" changes. Wait for it to become "Finished". It will take a few minutes as Appliku is installing and configuring all the packages. If "Setup Status" will become "Error" check the tab "Setup Logs" for errors.

When server setup is complete and server is ready to deploy your apps you will see server resources gauges come to live.

Time to deploy our Django app!

Adding an application

Click on the "Applications" menu link

You will get to the Git Provider selection.

Creating application from GitHub

Select the "Setup Credentials" for GitHub.

You need to get a personal token from GitHub.

Go to this link to create a token: https://github.com/settings/tokens

Click on Generate new token -> Generate new token(Classic) Fill in the note, select expiration date, check the "repo" checkbox and "user:email"

And click "Generate token".

Copy the token from the next page.

Go back to Appliku dashboard and paste the GitHub Token, and click Test Credentials and Save

Status must change to "Active".

Click on the logo in top left corner to get back to your team and go to Applications again and create an app, select GitHub.

Fill the form with the app name, select the repository with your application, branch and select the server, click on "Create Application".

You will see your app has been created, but not yet deployed.

Creating application from GitLab

Alternatively if you use GitLab you should add credentials for GitLab and create an app from GitLab.

Go to Applications menu link, Click "Add Application" and Setup credentials for GitLab.

You need to create a Personal Access Token here: https://gitlab.com/-/profile/personal_access_tokens

Give the key a name, set or clear expiration date, select "api" checkbox and click "Create Personal Access token"

Copy the token and paste it in Appliku dashboard.

After you click "Test Credentials and Save" the Status should turn green and say "Active".

Click on the logo to go back to your team, go to Applications, Add Application and select GitLab

Give your application a name, pick repository and the branch, select the server and click "Create Application"

Setup the app

Databases

If your application needs a database, which Django apps need most of the time, you can click on the "Manage" in databases block and "Create Database"

Select a database type you need and your server to deploy the DB to, click "Create database"

Your database will start deploying, wait for the deployment status to become "deployed".

Go back to your app

You can see your database is in the list.

Environment variables and build settings

Click on the "Settings" link next to the application name.

Go to the "Environment Variables" tab

You can see that the DATABASE_URL is already added automatically from the database you created.

If you have a .env file you can use "Import from .env" button to paste variables.

Or click on "Add" button and add variables one by one.

Usually for Django app we need to add DJANGO_ALLOWED_HOSTS and DJANGO_SECRET_KEY.

Appliku provides a default host name for your application which is YOUR_APP_NAME+ '.applikuapp.com'

After you finished adding your variables click on "Save and Deploy"

You will see that the deployment started.

Go back to the application overview.

The "Deploy Now" button is grey because deployment is in progress and in the "Latest deployment" Block you can see the currently running deployment.

Click on "Deployment #1"

You can see the deployment log. Scroll down to see the most recent output.

After it finishes and reports the "exit_code: 0", which is success go back to your application overview

Click on "View Application"

It will open your application in a new window!