- server dns: web01.dev.local
- django code location: /usr/local/lib
- django project: hello
apt-get -y install apache2 libapache2-mod-wsgi \
python-django
Once you ensure apache is up and running. Let create a simple django application:
cd /usr/local/lib django-admin startproject helloCreate a /usr/local/lib/django-hello.wsgi file:
import sys import os import os.path sys.path.append(os.path.dirname(__file__)) os.environ['DJANGO_SETTINGS_MODULE'] = 'hello.settings' from django.core.handlers.wsgi import WSGIHandler application = WSGIHandler()Add apache site configuration that will serve the django wsgi site. Add the following to /etc/apache2/sites-available/django-hello:
<VirtualHost *:80>
ServerName web01.dev.local
DocumentRoot /var/www/
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice,
# warn, error, crit, alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias / /usr/local/lib/django-hello.wsgi
WSGIProcessGroup hello-site
WSGIDaemonProcess hello-site processes=2 threads=16 maximum-requests=1000 display-name=apache-hello-wsgi
</VirtualHost>
Now we are going disable default apache site and enable django-hello site:
a2dissite default a2ensite django-hello /etc/init.d/apache2 restartOnce you navigate to http://web01.dev.local/ you should be able to see the default django welcome screen.
If you experience performance issue with content rendering, overhead of framework internal time, have a willing to fine control content caching consider take a look at the following post.

Thanks for posting these directions. worked like a charm!
ReplyDeletePLEASE UPGRADE THESE INSTRUCTIONS FOR DJANGO 1.4 !
ReplyDeleteBloody hell, why did thos f* decide to change the dir tree and location of the settings file?
hey dude: the code is perfect for 1.4 except the django-hello.wsgi
Deletesuppose i created django-admin.py startproject hello
so now my django.wsgi contains:
this is my code:
import os
import sys
path = '/srv/www/hello'
if path not in sys.path:
sys.path.insert(0,'/srv/www/hello')
os.environ['DJANGO_SETTINGS_MODULE'] = 'hello.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()