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

Installing mod_wsgi on Ubuntu 12.04

PostedJuly 18, 2012 132.9k views Apache Django Ubuntu

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

About mod_wsgi

mod_wsgi is a simple and easy to setup tool that serves python web apps from Apache server. It is also one of the recommended ways of getting Django into production. In this article, we will be discussing the installation and set up of mod_wsgi with the Apache server.


This article is the second in a series of 3. The previous article covers installing Django on the server. I recommend looking over the previous article before starting this one.

Since we are focusing on mod_wsgi for installing Apache module so first of all we need an installed Apache server. Use below command for installing required Apache components.

sudo aptitude install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert

Once all of the components of apache have installed, access your droplet IP in the browser and make sure that you see the default Apache page that says ‘It Works’. If you don’t get this page , it may be for one of several reasons

  1. Apache is not installed correctly
  2. There is an existing installation of Apache
  3. Iptables are blocking the port number 80

Check the issue and make sure that Apache is working properly before moving to the next step.

Installing mod_wsgi From Aptitude:

It is very easy to install mod_wsgi with the help of aptitude.

 sudo aptitude install libapache2-mod-wsgi

Restart Apache to get mod_wsgi to work.

 sudo service apache2 restart

How to Install mod_wsgi from Source

Since the code is constantly changing, we can ensure that we install the latest version of mod_wsgi by installing it from the source.

mkdir ~/sources
cd ~/sources
wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz 
tar xvfz mod_wsgi-3.3.tar.gz

Before continuing further, we will grab two different packages from aptitude.

 sudo aptitude install python-dev apache2-prefork-dev

If you are using worker MPM with Apache then replace apache2-prefork-dev with apache2-threaded-dev.

After that process has completed, you can go ahead and configure and install mod_wsgi.

 cd mod_wsgi-3.3
sudo make install

See More

Once you have mod_wsgi installed, you can see how to use it to serve applications in the next article.

By Etel Sverdlov


Creative Commons License