Django Installation Guide

shrubberystatuesqueData Management

Dec 1, 2012 (4 years and 11 months ago)

281 views

Django Installation Guide


The
following guide help
to install
django

on the UBUNTU platform.


OS Version: Ubuntu
8.10 Server


Step
1
:

Install MySQL and MySQL binding


$

sudo apt
-
get install mysql
-
server mysql
-
client python
-
mysqldb

Step
2
:

MySQL should
ask you for a root password during installation, but if not
add one now using



$sudo

mysqladmin
-
u root password "new

p
ass
w
or
d"

Step
3
:

Remove the anonymous accounts that exist by default in MySQL. Log into
mysql


$

mysql
-
u root
-
p

password:

mysql>
DROP USER "";

Step
4
:

C
reate a new database user and database for Django to use


mysql> CREATE DATABASE db_name;

mysql> CREATE USER ‘username’@’localhost’ IDENTIFIED BY ‘password’;

mysql> GRANT ALL PRIVILEGES ON db_name.* TO ‘username’@’localhost’ WITH
GRANT
OPTION;


Step
5
:

Install Django


$

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


Step 6
:

Deploy the website

using MOD_WSGI

First, c
opy the
developed
project to
DJANGO server under (“/home/user/www/”)

Here, I have copied the “ritcco” project under “/home/user/www”.

Edit ritcco project settings and change the following characters (
marked

as

red

color
)
.

Note: create a “www” directory if not exist,




$ sudo

vi /home/user/www/ritcco/settings.py


#
Django settings for ritcco project.


from os.path import dirname, join

_dir = dirname(__file__)


DEBUG = True

TEMPLATE_DEBUG = DEBUG


ADMINS = (



('
User Name
', '
email address
),

)


MANAGERS = ADMINS


DATABASE_ENGINE = '
mysql
' #
'postgresql_psycopg2', 'postgresql', 'mysql',
'sqlite3' or 'oracle'.

DATABASE_NAME = '
ritcco_db
' # Or path to database file if using sqlite3.

DATABASE_USER = '
ritcco
' # Not used with sqlite3.

DATABASE_PASSWORD = '
ritcco
' # N
ot used with sqlite3.

DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.

DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.


# Local time zone for this installation. Choices can
be found here:

# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name

# although not all choices may be available on all operating systems.

# If running in a Windows environment this must be set to the same as your

# system time zone.

TIME_ZONE = '
Asia/Ri
yadh
'


# Language code for this installation. All choices can be found here:

# http://www.i18nguy.com/unicode/language
-
identifiers.html

LANGUAGE_CODE = 'en
-
us'


SITE_ID = 1


# If you set this to False, Django will make some optimizations so as not

# to
load the internationalization machinery.

USE_I18N = True


# Absolute path to the directory that holds media.

# Example: "/home/media/media.lawrence.com/"

MEDIA_ROOT =
path(“media”)


# URL that handles the media served from MEDIA_ROOT. Make sure to use a

#
trailing slash if there is a path component (optional in other cases).

# Examples: "http://media.lawrence.com", "http://example.com/media/"

MEDIA_URL = '/
site_
media/'


# URL prefix for admin media
--

CSS, JavaScript and images. Make sure to use a

# trailin
g slash.

# Examples: "http://foo.com/media/", "/media/".

ADMIN_MEDIA_PREFIX =
'/media/
'


# Make this unique, and don't share it with anybody.

SECRET_KEY = '+$hv+g7345a!h%4_)wkequgc*m48@&bbhv$==ytfwm3(dniwy7'


# List of callables that know how to import tem
plates from various sources.

TEMPLATE_LOADERS = (


'django.template.loaders.filesystem.load_template_source',


'django.template.loaders.app_directories.load_template_source',

# 'django.template.loaders.eggs.load_template_source',

)


MIDDLEWARE_CL
ASSES = (


'django.middleware.common.CommonMiddleware',


'django.contrib.sessions.middleware.SessionMiddleware',


'django.contrib.auth.middleware.AuthenticationMiddleware',

)


ROOT_URLCONF = 'ritcco.urls'


TEMPLATE_DIRS = (


# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".


# Always use forward slashes, even on Windows.


# Don't forget to use absolute paths, not relative paths.


join(_dir, 'website/templates/'),

)


INSTALLED_APP
S = (


'django.contrib.auth',


'django.contrib.contenttypes',


'django.contrib.sessions',


'django.contrib.sites',


'ritcco.website',


'django.contrib.admin',

)


Step 7
:

Create new apache directory under “/home/user/www/ritcco/”


$
mkdir apache


Step 8
:

Create new django wsgi file by issuing following command,

$
vi djang.wsgi

import os, sys

sys.path.append(
'/home/user/www'
)

os.environ['DJANGO_SETTINGS_MODULE'] = '
ritcco
.settings'


import django.core.handlers.wsgi


application =
django.core.handlers.wsgi.WSGIHandler()

Save and exit

Step 9
:

Create apache virtual host file under “/etc/apache2/sites
-
available/”,

$ s
udo

vi /etc/apache2/sites
-
available/ritcco.com


<VirtualHost 173.10.13.215:80>


ServerName test.rezayat.net



WSGIScriptAlias / "/home/sa/www/ritcco/apache/django.wsgi"


<Directory "/home/sa/www/ritcco/apache">


Allow from all


</Directory>



Alias /site_media/ "/home/sa/www/ritcco/media/"


<Directory "/home/sa/www/ritcco/media/">


Or
der allow,deny


Options Indexes FollowSymLinks


Allow from all


IndexOptions FancyIndexing


</Directory>


</VirtualHost>


Step 1
0
:

Enable ritcco website & restart apache service

$ sudo a2ensite ritcco.com

$ sudo /etc/init.d/apache2

restart


Step 1
1
:

Serve Django admin media files



First, edit /home/user/www/ritcco/settings.py

& modify the following
line


ADMIN_MEDIA_PREFIX=’/media/admin/’




Edit /home/user/www/ritcco/urls.py & make sure that following lines
are uncommented

properly
,

from django.contrib import admin

admin.autodiscover()





C
reate the
site administration


$
sudo python manage.py syncdb

Make sure that you are running this command under /home/user/www/ritcco/

& enter the new password for site administration



Edit
the project

configuration file

and add the following lines,


$ sudo

vi /etc/apache2/sites
-
available/ritcco.com

Alias /media/ "/usr/local/lib/python2.6/dist
-
packages/django/contrib/admin/m

edia/"


<
Directory "/usr/local/lib/python2.6/dist
-
packages/django/contrib/admin/media/">


Order allow,deny


Options Indexes FollowSymLinks


Allow from all


IndexOptions FancyIndexing


</Directory>

Save & exit. Then, restart apache
service by typing below command
,

$ sudo

/etc/init.d
/apache2 restart

To verify

click

http://test.rezayat.net

& for site admin
http://test.rezayat.net/admin