P. 1
How to Install Django on Debian Lenny

How to Install Django on Debian Lenny

|Views: 11|Likes:
Published by sammyjr75

More info:

Published by: sammyjr75 on Oct 17, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

02/22/2014

pdf

text

original

How To Install Django On Debian Lenny (Apache2/mod_python

)
Version 1.0 This tutorial explains how to install Django on a Debian Lenny server. Django is a web framework that allows to develop Python web applications quickly with as much automation as possible. I will use it with Apache2 and mod_python in this guide. This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web. This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

1 Install MySQL
Django can use multiple database backends, e.g. PostgreSQL, MySQL, SQLite, etc. If you want to use MySQL, you can install it as follows: aptitude install mysql-server mysql-client You will be asked to create a MySQL root password: New password for the MySQL "root" user: <-- yourrootsqlpassword Repeat password for the MySQL "root" user: <-- yourrootsqlpassword We want MySQL to listen on all interfaces, not just localhost, therefore we edit /etc/mysql/my.cnf and comment out the line bind-address = 127.0.0.1: Vim /etc/mysql/my.cnf
[...] # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. #bind-address = 127.0.0.1 [...]

Then we restart MySQL: /etc/init.d/mysql restart Now check that networking is enabled. Run netstat -tap | grep mysql

djangoproject. we can configure Apache. >. we run: aptitude install python-django python-mysqldb 4 Configure Apache I will use /var/www here as the document root of my virtual host and /etc/apache2/sitesavailable/default as the file containing the configuration of my virtual host..] <Location "/mysite"> .... in /home/mycode): mkdir /home/mycode cd /home/mycode /usr/share/python-support/python-django/django/bin/django-admin. Adjust this to your circumstances.The output should look like this: server1:~# netstat -tap | grep mysql tcp 0 0 *:mysql *:* server1:~# LISTEN 3403/mysqld 2 Install Apache And mod_python If Apache2 and mod_python aren't already installed on your system. Before we configure Apache.g.py startproject mysite This will create the directory /home/mycode/mysite with some Python files in it.</VirtualHost> container: Vim /etc/apache2/sites-available/default [. you can install them as follows: aptitude install apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-python 3 Install Django In order to install Django and the Python MySQL bindings..g. Now with the project mysite created. I open my vhost configuration in /etc/apache2/sites-available/default and place the following lines between the <VirtualHost . called mysite) (see http://www.. we must create a Django project (e.com/documentation/tutorial01/). For security reasons I create that project outside my document root /var/www (e.

path" </Location> [.example.meaning this configuration will be used if you use /mysite in the URL (e.settings PythonDebug On PythonPath "['/home/mycode'] + sys.handlers. http://www.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.path") to the name of your project and the path where it is located. If everything went well.com/mysite).d/apache2 restart Now you can access http://www. Please adjust the other values (SetEnv DJANGO_SETTINGS_MODULE mysite.g. . Restart Apache afterwards: /etc/init.] The path in the first line (<Location "/mysite">) refers to the URL . you should see something like this: This means Django has been successfully installed.djangoproject.core.SetHandler python-program PythonHandler django.settings and PythonPath "['/home/mycode'] + sys..example.com/documentation/ to learn how to develop web applications with Django).com/mysite in a browser. You can change this to your likings. and you can now use it to develop your Python web applications (please refer to http://www..

5 Connect To A MySQL Database From A Django Project If you want to use a MySQL database in your Django project.] DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2'.. mysite) and a database user (e.org/ .org/ Debian: http://www. [.. 'mysql'. GRANT ALL ON mysite. mysiteadmin) for that database: mysql -u root -p CREATE DATABASE mysite. quit. DATABASE_PASSWORD = 'mysiteadmin_password' # Not used with sqlite3.g. e.g. Not used with sqlite3.com/ Python: http://www.* TO 'mysiteadmin'@'localhost' IDENTIFIED BY 'mysiteadmin_password'. DATABASE_PORT = '' # Set to empty string for default. 'postgresql'. Not used with sqlite3. /home/mycode/mysite) and modify the database settings.g. as follows: Vim /home/mycode/mysite/settings. DATABASE_HOST = '' # Set to empty string for localhost. Then open the settings.localdomain' IDENTIFIED BY 'mysiteadmin_password'.py file in the project folder (e.debian..python. you should first create that database (e. DATABASE_USER = 'mysiteadmin' # Not used with sqlite3.* TO 'mysiteadmin'@'localhost.. DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.djangoproject.] 6 Links    Django: http://www. 'sqlite3' or 'oracle'.py [.g. GRANT ALL ON mysite.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->