We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How To Setup uWSGI On Ubuntu 12.10

PostedApril 18, 2013 21.6k views Python

Status: Deprecated

This article is deprecated and no longer maintained.

Reason

Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates.

See Instead

This article may still be useful as a reference, but may not follow best practices or work on this or other Ubuntu releases. We strongly recommend using a recent article written for the version of Ubuntu you are using.

If you are currently operating a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

About uWSGI

uWSGI provides an implementation of the WSGI specification and is both a protocol and an application server. For more, please refer to the uWSGI docs here. Although in this tutorial we will setup a standalone uWSGI server, it is generally kept behind nginx.

Prerequisites

As a prerequisite, we are assuming that you have gone through the article on how to set up your droplet or VPS. If not, you can find the article here. This tutorial requires you to have a VPS up and running and have you log into it.

  ssh -p 25000 demo@12.34.56.789

Remember to replace '2500' with the number of port you used in the previous article. Replace 'demo' with your username and '12.34.56.789' with your droplet IP.

The VPS needs to be equipped with Python; since you have installed Ubuntu 12.04, you might already have Python 2.7.3 installed.

Step 1: Install Pip and Python Essentials on a VPS

We will download the Python development headers as we will be deploying a small application written in Python.

sudo apt-get install build-essential python-dev
sudo apt-get install python-pip

Step 2: Install dependent packages

Next, install the required packages.

sudo apt-get install libxml2-dev
sudo apt-get install libxslt1-dev 

Step 3: Install Pip

We will install uwsgi from pip and not using aptitude, as Aptitude seems to install an older version of uwsgi.

sudo pip install uwsgi

Step 4: Create a small Application

We will create a small application and render a text. Create the following folder and then a python file inside it.

mkdir ~/projects
vim ~/projects/app.py

Copy the following contents in this file:

def application(env, start_response):
        start_response('200 OK', [('Content-Type','text/html')])
        return "Hello World From Digital Ocean"

Step 5: Launch the Application via uWSGI

Assuming that you have created a 'demo' user using 'adduser' as mentioned in the Pre-requisites sections, you can run the following to start serving the application at a port of your choice:

sudo uwsgi --http :port_num --wsgi-file app.py  --uid <username>
sudo uwsgi --http :9090 --wsgi-file app.py  --uid demo

Step 6: Confirmation: Access the Application

You can confirm that uWSGI has been installed and running by directing your browser to your http://: You can run the following command to reveal your VPS' IP address

ifconfig eth0 | grep inet | awk '{ print 2 }'

When you visit your page in your browser, you will see the words:

"Hello World From Digital Ocean"

uWSGI installed and a sample application served by it.

10 Comments

Creative Commons License