Howto for mod_wsgi

Introduction

This tutorial shows you how to easily publish your PyAMF applications with the Apache 2 webserver and mod_wsgi. mod_wsgi is an Apache module which can host any Python application which supports the Python WSGI interface.

We're going to assume you already installed the Apache webserver running on 192.168.1.100. Flash applications will be able to access your PyAMF remoting gateway on http://192.168.1.100/flashservices/gateway.

This was tested with Python 2.4.3, Apache 2.0.55 and mod_wsgi 1.3 on Ubuntu 6.06.1 LTS.

Create your PyAMF application

Create a folder for your application:

mkdir /var/www/myApp

Create a startup file for your application in /var/www/myApp/startup.py:

import sys
sys.path.append('/usr/src/pyamf/')
sys.path.append('/var/www/myApp/')

from pyamf.remoting.gateway.wsgi import WSGIGateway

def echo(data):
   return data

application = WSGIGateway({'echo': echo})


Setup Apache vhost

Create a new vhost or modify an existing one:

<VirtualHost 192.168.1.100:80>

        ServerName example.server.com
        DocumentRoot /var/www/myApp

        CustomLog /var/log/apache2/myApp-access.log combined
        ErrorLog /var/log/apache2/myApp-error.log

        LogLevel warn
        ServerSignature Off

        # PyAMF gateway
        WSGIScriptAlias /flashservices/gateway /var/www/myApp/startup.py

</VirtualHost>


Restart Apache

That's it! Your Flash/AMF clients will now be able to access your PyAMF application through http://192.168.1.100/flashservices/gateway.

References