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
- Apache is not installed correctly
- There is an existing installation of Apache
- 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 ./configure make sudo make install