Apr 26, 2009

Django with Apache + mod_python on Windows XP

All right, this is just a step by step tutorial for myself.
  1. Get following files, but notice there're some limitations for the combination. For instance, mod_python does not recognize Python26 or later version.
    • apache_2.2.11-win32-x86-no_ssl.msi
    • python-2.5.4.msi
    • Django-1.0.2-final.tar.gz
    • mod_python-3.3.1.win32-py2.5-Apache2.2.exe

  2. Install Apache (C:\Program Files\Apache Software Foundation\Apache2.2), I chose "Install Apache for All Users, on Port 80, as a Service."

  3. Install Python (C:\Python25), I chose "Install for all users."

  4. Update system environment with path "C:\Python25" included.

  5. Install mod_python, it will ask where do you put your Python and Apache.

  6. Add this line into Apache configuration (...\Apache2.2\httpd.conf) to load mod_python:
    LoadModule python_module modules/mod_python.so
  7. Install Django, untar the archive and run command "python setup.py install" from command prompt, it will be installed at "C:\Python25\Lib\site-packages\django."

  8. Create a directory for storing Django projects (D:\django).

  9. Create a Django project (mysite) by running command "C:\Python25\Scripts\django-admin.py startproject mysite." A new directory "D:\django\mysite" will then be created.

  10. Put this directive into Apache configuration file:
    <location "/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonPath "['D:/django'] + sys.path"
    PythonDebug On
    </location>
  11. Open http://127.0.0.1/.
It worked!
Congratulations on your first Django-powered page.

Notes
  • DJANGO_SETTINGS_MODULE xxx.settings, xxx is the project's name created at step 9.
  • If the url you want for your project is something like "http://127.0.0.1/best/*", you need to use
    <location "/best/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonOption django.root /best
    PythonPath "['D:/django'] + sys.path"
    PythonDebug On
    </location>
    at step 10 instead.

No comments:

Post a Comment