Django Apache mod python and MySQL install on Ubuntu
From Django In Production
Follow the instructions below to install Django, Apache/mod_python on a fresh install of Ubuntu (tested on Edgy). Make sure you have secured your server for use on the web (disable root ssh, configure iptables, etc...) before attempting these instructions.
Contents |
Install dev tools and dependencies
There are a number of tools that will come in useful later in the install process for building and making some packages.
sudo apt-get install gcc libc6-dev build-essential python-dev python-setuptools
Install Apache and mod_python
Install the prefork MPM of Apache 2 and mod_python module. apache2-utils also includes some other useful utilities such as ab the Apache benchmark tool and rotatelogs.
sudo apt-get install apache2 apache2-mpm-prefork apache2.2-common apache2-utils libapache2-mod-python
If you need SSL support also install:
sudo apt-get install ssl-cert
Install MySQL and MySQL binding
sudo apt-get install mysql-server mysql-client python-mysqldb
MySQL should ask you for a root password during installation, but if not add one now using:
mysqladmin -u root password "newpwd"
Some people also like to remove the anonymous accounts that exist by default in MySQL. Log into mysql:
mysql -u root -p
and remove the accounts:
mysql> DROP USER "";
Finally create a new database user and database for Django to use. In the mysql shell run:
mysql> CREATE DATABASE db_name;
mysql> GRANT ALL ON db_name.* to user_name WITH GRANT OPTION;
mysql> SET PASSWORD FOR user_name = password('psswdhere');
Install Django
aptitude does contain various verisons of Django (latest version is Version 1.0.1 in Jaunty), but often the latest stable version is not yet available via aptitude. For the most flexibility you probably want to download and install your chosen version directly.
sudo wget http://www.djangoproject.com/download/#{django_version}/tarball/ sudo tar xzvf Django-#{django_version}-final.tar.gz sudo python Django-#{django_version}-final/setup.py install sudo rm Django-#{django_version}-final.tar.gz sudo rm -rf Django-#{django_version}-final
Install memcached
Memcached is the recommended mechanism for in-memory caching with Django. Three packages are required, memcached, libmemcache-dev, as well as the cmemcache API.
sudo apt-get install libmemcache-dev memcached wget http://gijsbert.org/downloads/cmemcache/cmemcache-0.95.tar.bz2 tar xjvf cmemcache-0.95.tar.bz2 cd cmemcache-0.95 sudo python setup.py install rm cmemcache-0.95.tar.bz2 rm -rf cmemcache-0.95
If you can't install the cmemcache API you can use the Python based python-memcached which is a little slower but still a recommended approach.
To start the memcached daemon run:
sudo memcached -u www-data -p 11211 -m 32 -d
Configure and start project
The above should give you all the software you need to run Django on Ubuntu. There is a great guide to getting a complete Django project up and running on Ubuntu, in The Django and Ubuntu Intrepid Almanac.

