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.
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.
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
Check the issue and make sure that Apache is working properly before moving to the next step.
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
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 ./configure make sudo make install
Once you have mod_wsgi installed, you can see how to use it to serve applications in the next article.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.