I am looking for step by step details of how to deploy django websites in apache2 server with one example. I am using ubuntu operating system

Please give some link or give the details.

Hi.
I use apache for Django 1.1.1 deployment under Debian, but Ubuntu must be all the same.
This could be an example:
1-Install an activate python module for apache:
sudo apt-get install libapache2-mod-python
sudo a2enmod python
sudo /etc/init.d/apache2 restart

2-Guess you have your project located at /srv/my_site
cd /srv/
sudo django-admin.py startproject my_site

3-Make a virtualhost for it:
sudo edit /etc/apache2/sites-available/my_site.com
<VirtualHost *:80>
ServerAdmin me@localhost
ServerName mysite.com
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE videoteca.settings
PythonPath " + sys.path"
#You can activate Python debug
#PythonDebug On
order allow,deny
allow from all
</Location>

#We will serve media under /media
Alias /media /srv/my_site/media
<Location "/media">
SetHandler None
Options FollowSymLinks
</Location>

#We will serve the admin media under /adminmedia
Alias /adminmedia /srv/my_site/adminmedia
<Location "/adminmedia">
SetHandler None
Options FollowSymLinks
</Location>

#Contents that python does not handle are handled by apache directly
<LocationMatch "\.(jpg|gif|png|swf|css|js|flv|mp3|xml)$">
SetHandler None
</LocationMatch>

#We do not want for encoding troubles
AddDefaultCharset utf-8
</VirtualHost>

4-Edit settings.py and adjust settings, these are some things you shoul set:
sudo edit /srv/my_site/settings.py

MEDIA_ROOT = '/srv/my_site/media/'
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/adminmedia/'
TEMPLATE_DIRS = (
"/srv/my_site/templates",
)

If you use sqlite database, you must specify the complete path to your database:
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = '/srv/my_site/my_database.db'

5-Make a symbolic link to admin media. In my case it's located at /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/, but it can be at other place on your system:
cd /srv/my_site
sudo ln -s /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/ adminmedia

6-Make apache user the owner of the directory, so it can modify the database file, de media directory so you can make uploads, etc.
sudo chown -R www-data.www-data /srv/my_site

7-Enable your apache virtualhost:
sudo a2ensite my_site.com
sudo /etc/init.d/apache2 reload

8-Set mysite.com on your virtualhost for testing purposes:
sudo edit /etc/hosts

127.0.0.1 localhost mysite.com

Make ping to mysite.com to be sure it responds to your loop interface:
ping mysite.com
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_req=1 ttl=64 time=0.090 ms
64 bytes from localhost (127.0.0.1): icmp_req=2 ttl=64 time=0.047 ms
64 bytes from localhost (127.0.0.1): icmp_req=3 ttl=64 time=0.060 ms
64 bytes from localhost (127.0.0.1): icmp_req=4 ttl=64 time=0.057 ms
^C
--- localhost ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 0.047/0.063/0.090/0.017 ms

9-Open site on your browser:
firefox mysite.com

Hope be helpfull.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.