Installing Django on Ubuntu 8.04 (Hardy Heron)
July 15, 2008 – 12:01 amGoal: install Django SVN release on Ubuntu 8.04, working with Apache2, mysql, and mod_python.
Step 1: Install apache, mysql, and mod_python
sudo apt-get install apache2 mysql-server libapache2-mod-python python-mysqldb
Step 2: create a new database “mysite” and a new user “django” with password “password” in mysql
$ mysql -u root -p
mysql> CREATE DATABASE mysite CHARACTER SET utf8;
mysql> create user django identified by ‘password’;
mysql> grant all privileges on mysite.* to django;
Step 3: Install django from SVN repo.
cd ~
svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk
ln -s `pwd`/django-trunk/django SITE-PACKAGES-DIR/django
(Note:
SITE-PACKAGES-DIR = python -c “from distutils.sysconfig import get_python_lib; print get_python_lib()”
)
ln -s `pwd`/django-trunk/django/bin/django-admin.py /usr/local/bin
Step 4: Create a new django project.
cd ~
django-admin.py startproject mysite
Step 5: Add the following entry into the /etc/hosts file:
127.0.0.1 mysite # so that we can access the web site by “http://mysite/”
Step 6: Configure apache with named virtual host.
Edit /etc/apache2/apache2.conf. Append a line “NameVirtualHost *” to the end of the file.
Create a new file /etc/apache2/sites-available/mysite with the following contents.
<VirtualHost *>
ServerAlias mysite
DocumentRoot /var/www/mysite/htdocs
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/mysite/htdocs>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory “/var/www/mysite/cgi-bin”>
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>ErrorLog /var/www/mysite/logs/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warnCustomLog /var/www/mysite/logs/access.log combined
ServerSignature OnAlias /doc/ “/usr/share/doc/”
<Directory “/usr/share/doc/”>
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory><Location “/”>
SetHandler python-program
PythonHandler django.core.handlers.modpython
PythonDebug On
PythonPath “['/home/haobin'] + sys.path” # replace ‘home/haobin’ with your django proj path
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
</Location></VirtualHost>
Add ‘mysite’ to the Apache’s enabled sites: /etc/apache2/sites-available$ sudo a2ensite mysite
Reload apache: sudo /etc/init.d/apache2 reload
Point the browser to http://mysite/ and you should see the “Welcome to Django” page.
3 Responses to “Installing Django on Ubuntu 8.04 (Hardy Heron)”
Thanks for the nice summary! Worked great!
Brad
By Brad parks on Oct 10, 2008
Crisp walk through and steps. Quick question, where i all the django admin files will get placed for my project in this configuration?
By Prem on Jan 6, 2009
Prem, do you mean the files for the admin site? If so, they are placed under /Lib/site-packages/django/contrib/admin/
By admin on Jan 11, 2009