1

Hi All i am not able to run a django application in apache2 webserver. I have went through all the document but it still did not work for me.This is my Apache2's httpd.conf file

<Location "/mysite/">
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE mysite.settings
  PythonOption django.root /mysite
  PythonPath "['/home/djangotest/mysite'] + sys.path"
  PythonDebug On
</Location>

My django project location is at /home/djangotest/mysite in which i am running the polls application. Is there something i have to mention in settings.py or urls.py for this to work in apache2 it works fine in the dev server. or is there configuration i have to do in apache2 to work

2
  • 4
    please do not use mod_pythom, use mod_wsgi instead :'( Commented Mar 9, 2011 at 13:05
  • i have switched to mod_wsgi and trying it out Commented Mar 9, 2011 at 18:08

3 Answers 3

2
  1. Download and install http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz

  2. Add to the /etc/httpd/conf.d/ directory


<VirtualHost *:80>
  ServerName --insert--

  ErrorLog /home/djangotest/mysite/error_log
  CustomLog /home/djangotest/mysite/access_log combined

  UseCanonicalName Off

  WSGIScriptAlias /g2 /home/djangotest/mysite/mysite.wsgi
  WSGIDaemonProcess iproj processes=7 threads=1 display-name=%{GROUP}

</VirtualHost>
  1. Add to LoadModules secion in /etc/httpd/conf/httpd.conf

    LoadModule wsgi_module /usr/lib/httpd/modules/mod_wsgi.so

  2. Add to AddHandler section in /etc/httpd/conf/httpd.conf

    AddHandler wsgi-script .wsgi

  3. Make sure your the httpd user can access /home/djangotest/ as well as execute your python scripts

  4. Create a mysite.wsgi file:


import os
import sys

sys.path.append('/home/djangotest/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

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

Or as @Efazati said, read the manual ;)


Hopefuly this solves your final issue:

no module named mysite.urls but there is a file urls.py

Check your settings file for

ROOT_URLCONF = "mysite.urls"

This is the name of your urls file, I am guessing you dont have a module called mysite.urls.py ? It sounds like your property should read:

ROOT_URLCONF = "urls"

Sign up to request clarification or add additional context in comments.

5 Comments

So you're saying download mod_wsgi, then use mod_python??
I tried wt u said but i get an import error no module named mysite.urls but there is a file urls.py
I dont have any reference to mysite.urls ? You are going to have to explain....? It sounds like an issue with your settings file, or your python path.
This is wt i have done in my /etc/apache2/httpd.conf file i have put LoadModule wsgi_module /usr/lib/httpd/modules/mod_wsgi.so AddHandler wsgi-script .wsgi WSGIScriptAlias / /home/djangotest/mysite/apache/django.wsgi and i created an wsgi file in apache folder with the code u have sent is there something i have to add in mysite/setting.py
Thanks for the ROOT_URLCONF suggestion! Just curious why the file gets named urls.py and the default path in settings is mysite.urls.py ?
1

Try to add '/home/djangotest' to PythonPath:

<Location "/mysite/">

  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE mysite.settings
  PythonOption django.root /mysite
  PythonPath "['/home/djangotest', '/home/djangotest/mysite'] + sys.path"

  PythonDebug On
</Location>

You need to add that if you import your project's files with the syntax .. The other guys here are right, though; switch to mod-wsgi if you can. Django's mod_python support will be deprecated very soon. http://docs.djangoproject.com/en/1.2/howto/deployment/modpython/

edit: mod_python support is deprecated in Django 1.3, and will be removed entirely on Django 1.5.

Comments

0

read the manual

http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.