Tutorial

How To Setup uWSGI On Ubuntu 12.10

Published on April 18, 2013
Default avatar

By

How To Setup uWSGI On Ubuntu 12.10

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://<IP address:port>: You can run the following command to reveal your VPS’ IP address

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

When you visit your <IP address:port> page in your browser, you will see the words:

"Hello World From Digital Ocean"

uWSGI installed and a sample application served by it.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
9 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Yeah I also agree, this is pretty bad in terms of tutorials here. How can you expect to have us set up a project and then instead of updating the actual tutorial to reflect you send us to a stack over flow to try and resolve the issue with your actual tutorial instead of just updating it?

sudo uwsgi --http :8080 --wsgi-file app.py --uid demo user demo not found

in the end i got Internal Server Error

nice guide, made by people who not tested it, and expect other people to think about missed parts them self.

plus u using vim and dont explain how to exit from it(normal people dont need to know this, vim sucks)

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
July 31, 2014

@geraldb.popa: Thanks for catching that! Fixed.

| sudo uwsgi --http :port_num; --wsgi-file app.py --uid <username>

The “;” after port_num should not be there.

Thanks

That did it. Had to set up a correct ini file. Thanks!!!

“— no python application found” I followed the instructions, inserting my port number and user id in the red places. I did the pre-tutorial. I triple checked everything, I think. Please advise.

Moisey Uretsky
DigitalOcean Employee
DigitalOcean Employee badge
April 23, 2013

Fixed up =]

there is a typo in the first paragraph. “ngix.”, I’d imagine, should be “nginx”.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel