Django running on Linux VM using Windows Azure

At Confoo 2013, we have worked with Make Web Not War and created a HTML5 Word Cloud using HTML5, socket.IO and Node.JS which runs on a Linux VM using Windows Azure. Yes, you have heard it right – LINUX VM on Windows Azure!

As of lately I’ve been working with the Django framework, so I decided to set it up on a Linux VM using Windows Azure. If you are like me using a Windows PC/Laptop, you want to code directly on the Linux VM, and I will show what exactly how.

In this walk-thru, you will learn how to:

  • Create an Ubuntu Linux VM on Windows Azure
  • Using putty for setup Django
  • Coding Django using Notepad++

Creating and setup the Linux VM on Windows Azure

Obviously, you need an Windows Azure account to begin. If you don’t have an account, sign up for a Free Trial here.
First sign in to the Windows Azure Management Portal. On the bottom, click on New in the command bar.
new

Choose Compute > Virtual Machine > Quick Create, and then select Image as Ubuntu Server. Fill in the rest of the information and click “Create A Virtual Machine”.
createvm

Just wait a few minutes, and your VM will be ready.
vm-waiting
done

Once it is ready, click to open the VM management, and go to Endpoints. Click Add Enpoints in the command bar at the bottom, and open the port 80 for your VM.

addport
port

portadded

SSH using Putty

Download putty if you haven’t. Open Putty and connect to your Linux VM using your VM url, and SSH port.

putty

Once you are login, enter the following commands to install Python, Django and Apache server.

sudo apt-get install python-setuptools
sudo easy_install django
sudo apt-get install apache2 libapache2-mod-wsgi

Next, we are going to start a Django Project. Enter the follow commands:

mkdir myweb
cd myweb
django-admin.py startproject myweb

The django-admin.py generates a basic files and directories for your Django web app.

Now open up your apache default config file using vim.
sudo vim /etc/apache2/sites-available/default

Insert these the two lines to the top of your file
WSGIScriptAlias / /home/azureuser/back-end/trainerplus/wsgi.py
WSGIPythonPath /home/azureuser/back-end

Insert these lines inside the element.

<Directory /home/azureuser/back-end/trainerplus>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

updateconf

Save and restart Apache by call this:


sudo apachectl restart

Open up your browser, and go to enter VM domain name, and you should your website is up!

Coding using Notepad++

Assuming you don’t have a Python/Django environment setup on your machine, you can directly code on the Linux Virtual Machine. However if you are not familiar with the Linux editor tools like vim, you can actually use a editor that supports SFTP like Notepad++.

You have to setup the SFTP by opening Plugins > NppFTP > Show NppFTPs Window.

notepad-sftp

Create a profile, and enter the your VM URL, select FTPS, and make sure you enter the SSH port number you are using for your putty.
sftp

Once it connects successfully, you can start coding directly from your machine. Happy coding!

code

By Raymond Tsang

Posted in Technical

Leave a Reply