Django on Solaris 10 with the GlassFish Web Stack

This post will show how to get running with Django on Solaris 10 with the Sun GlassFish Web Stack.

Install Web Stack

First, get the GlassFish Web Stack from here.   Depending on how you want to install the Web Stack, choose either the Image Packaging System (IPS) or the native package format.  For more details on the installation, see Sriram's Blog.  This post assumes the native version, but can easily be modified for the IPS delivery.

Build mod_wsgi

/usr/sfw/bin/wget http://modwsgi.googlecode.com/files/mod_wsgi-2.5.tar.gz 
/usr/sfw/bin/gtar xfz mod_wsgi-2.5.tar.gz
cd mod_wsgi-2.5 
./configure --with-apxs=/opt/webstack/apache2/2.2/bin/apxs --with-python=/opt/webstack/python/bin/python

Before you run make, be sure that /usr/ccs/bin and the C compiler, in this case Sun Studio Express, /opt/SSX0903/bin, are in your path. We also need to explicitly set the rpath.

LD_RUN_PATH=/opt/webstack/python/lib make
make install

This will put the mod_wsgi.so library in /opt/webstack/apache2/2.2/libexec/mod_wsgi.so.

Setup Django

/usr/sfw/bin/wget  http://www.djangoproject.com/download/1.1/tarball/
/usr/sfw/bin/gtar xfz Django-1.1.tar.gz
cd Django-1.1
/opt/webstack/python/bin/python setup.py install

Now, let's create a sample project.

cd /export/home/overstre
/opt/webstack/python/bin/python /opt/webstack/python/lib/python2.6/site-packages/django/bin/django-admin.py startproject mysite

We now need to tell Django that we will be using WSGI.

cd mysite; mkdir apache
cat > django.wsgi << EOF
import os, sys
sys.path.append('/export/home/overstre')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi

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

Be sure to update the path and the site name for your specific instance.

Setup Apache

This section shows a simple setup for Apache. Look at the mod_wsgi Configuration Guide for other details including delegation to daemon process.

Next, we need to load the mod_wsgi module into Apache.

echo "LoadModule wsgi_module libexec/mod_wsgi.so" >> /etc/opt/webstack/apache2/2.2/conf.d/modules-32.load 

And now we need to setup a simple wsgi.conf file so Apache knows about the Django project we created in the previous section.

cat > /etc/opt/webstack/apache2/2.2/conf.d/wsgi.conf << EOF
WSGIScriptAlias /mysite /export/home/overstre/mysite/apache/django.wsgi

<Directory /export/home/overstre/mysite/apache>
Order allow,deny
Allow from all
</Directory>
EOF

Again, be sure to update the paths for your setup.

The final step is to restart Apache.

svcadm restart sun-apache22

Let's make sure there were no problems.

svcs sun-apache22

It should show

STATE          STIME    FMRI
online         14:57:40 svc:/network/http:sun-apache22

If there was a problem, check the Apache log.

tail /var/opt/webstack/apache2/2.2/logs/error_log

Finally, let's see what it looks like in the browser.

Screencast

There's also a screencast showing these steps at http://mediacast.sun.com/users/overstre/media/django/details

Having trouble viewing the video?  Try using Firefox 3.5 which has native support for Theora.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Brian Overstreet

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today