Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to get a django application up and running on my cpanel system. I've installed mod_wsgi, and am following the guide here: http://www.nerdydork.com/setting-up-django-on-a-whm-cpanel-vps-liquidweb.html

However, I'm now confused as I don't know what to do next. The application has .py files, and I am able to run it via this: python manage.py runserver 211.144.131.148:8000

However, that's via command line and binds to port 8000. I want to use Apache instead.

The question is, that tutorial doesn't go further into how to get apache to recognize .py files and run the application as I want it. What do I do next?

share|improve this question
add comment

1 Answer

If you're using mod_wsgi, you don't want Apache to recognize your .py files. Confusing, no? Here, let me explain...

The WSGI module provides an interconnect of sorts between Apache and your Python processes. It's a standardized gateway interface (Web Server Gateway Interface), so to speak.

Here's the official Django documentation on configuring Django 1.1 with Apache & mod_wsgi.

Generally, you'll just need:

WSGIScriptAlias / /path/to/mysite/apache/django.wsgi

And then you'll need to define a WSGI application, which serves as front to your Django application:

import os
import sys

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

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

*Note that I took these examples from that document linked above.

This now wires up Apache to a WSGI app and then ties your application into that WSGI app. The WSGIScriptAlias line simply tells apache to send all requests at '/' or lower to your WSGI application, which will manage the URL routing.

I usually do deployments like this using FastCGI & the Python flup module, which is a little more complex, but worth checking out if you've the time.

share|improve this answer
    
It is a lot more confusing than that. You can have mod_wsgi recognise .py files in arbitrary directories, but .wsgi is recommended because quite often .py is mapped as a CGI script. There are other reasons to avoid .py extension besides that as well however. Anyway, for different ways to configure mod_wsgi see 'code.google.com/p/modwsgi/wiki/QuickConfigurationGuide';. –  Graham Dumpleton Mar 17 '10 at 23:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.