Windows – Linux – Mac OSX Guides

Django on Debian Lenny (mod_python + apache2 + mysql)

This is a short note on how to build a Django development environment in a Debian Lenny server.

1. Update and upgrade apt-get

apt-get update && apt-get upgrade

2. Grab all the packages needed

apt-get install apache2 mysql-server libapache2-mod-python  python-mysqldb  python-imaging  python-django  subversion php5  mysql-client php5-mysql

3. Check out Django

cd /usr/lib/python2.5/site-packages
svn co http://code.djangoproject.com/svn/django/trunk/django django
ln -s /usr/lib/python2.5/site-packages/django/bin/django-admin.py /usr/local/bin
cd /var/www
django-admin.py startproject sample_project

4. Change the /etc/apache2/httpd.conf

<Location "/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE sample_project.settings
    PythonOption django.root /sample_project
    PythonDebug On
    PythonPath "[‘/var/www’] + sys.path"
</Location>

Alias /admin_media/ /usr/lib/python2.5/site-packages/django/contrib/admin/media/
<Location "/admin_media/">
    SetHandler None
</Location>

5. Restart the apache server

/etc/init.d/apache2 restart

6. Change mysql  password root

mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD(‘new-password’) WHERE user=’root’;
mysql> FLUSH PRIVILEGES;

6. Create database & user

CREATE DATABASE db_name;
GRANT ALL ON db_name.* to user_name WITH GRANT OPTION;
SET PASSWORD FOR user_name = password(‘password_here’);

7. Modify the database connection in sample_project.settings

8. Now you can follow the Django tutorial

9. Test django on apache http://localhost/

Tagged with:     , , , , , , ,

Related Articles

Loading Facebook Comments ...

Post your comments

Your email address will not be published. Required fields are marked *