Search
Translations of this page:

Installing mod_wsgi

This refers to installing mod_wsgi 2.1 for the pre-installed apache2 in /opt/local.

1. Get the mod_wsgi source and place it in your build directory (eg. ~/usr/src):

$ svn export http://modwsgi.googlecode.com/svn/tags/mod_wsgi-2.1 mod_wsgi-2.1

2. Run configure in the mod_wsgi source:

$ ./configure --with-apxs=/opt/local/sbin/apxs --with-python=/opt/local/bin/python

3. Change the Makefile to look for libraries in /opt/local/lib. Update the following line in the generated Makefile:

LDFLAGS = -L/opt/local/lib/python2.4/config

to:

LDFLAGS = -L/opt/local/lib/python2.4/config -L/opt/local/lib

4. Build and install the binaries:

$ make
...
$ sudo make install

5. Load the module in the apache configuration. Add this line to /opt/local/etc/httpd/includes/dso.conf:

LoadModule wsgi_module    lib/httpd/mod_wsgi.so

6. Restart apache:

sudo svcadm restart apache

7. Sanity test - let's create a simple wsgi handler. Write the following python program (/var/www/htdocs/test.py):

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello world, I am a wsgi app!'
    response_headers = [('Content-Type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]

Configure our virtual host to let test.py handle our requests:

<VirtualHost *:80>
    ServerName mywebsite.com
    DocumentRoot /var/www/htdocs
 
    WSGIScriptAlias /test /var/www/htdocs/test.py
 
    <Directory /var/www/htdocs>
        Order allow,deny
        Allow from all
        Options +ExecCGI
    </Directory>
</VirtualHost>

This configures apache to send all requests to /test to our wsgi application (test.py). Restart apache again and test the URL (http://mywebsite.com/test).

 
mod_wsgi.txt · Last modified: 2008/07/06 22:10 by rounder
 
Recent changes RSS feed Creative Commons License Driven by DokuWiki