This HowTo describes how to run MapFish Server under Apache using mod_wsgi.
In the last section of How ToUse Map Fish Server was shown how to launch a MapFish project under the web server embedded in paster. This HowTo describes how to use Apache instead of paster.
Installing mod_wsgi
Make sure you have apache2-prefork-dev installed and follow these instructions for compiling, installing mod_wsgi, and possibly configuring a virtual host.
In addition to the Apache config provided on this page, you need to add WSGIDaemonProcess directive specifying that only one process should be used (wsgi.multiprocess=False). Something like the following should be ok:
<Directory "/path/to/your/wsgi/dir">
WSGIProcessGroup myapp
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias /wsgi /path/to/your/wsgi/dir/myapp.wsgi
WSGIDaemonProcess myapp threads=25
Now create a file named wsgi.load in the Apache modules directory (/etc/apache2/mods-available) with this content:
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
You can now enable wsgi into Apache (a2enmod wsgi) and restart Apache.
Creating a startup script
You now need to write the myapp.wsgi script. This script is the entry point to your MapFish application.
import site
import os, sys
site.addsitedir('/path/to/vpython/lib/pythonX.Y/site-packages')
sys.path.append('/path/to/your/mapfish/project')
os.environ['PYTHON_EGG_CACHE'] = '/var/www/python-eggs'
# configure the logging system
from paste.script.util.logging_config import fileConfig
fileConfig('/path/to/your/mapfish/project/development.ini')
from paste.deploy import loadapp
application = loadapp('config:/path/to/your/mapfish/project/development.ini')
Obviously, you need to adapt the above script to your setup.
Note: site.addsitedir() adds the libraries from the python virtual environment (virtualenv). See this blog entry for details.
