Skip to content
Myr

mod_wsgi.rst

This file

Path

docs/deploying/mod_wsgi.rst

80 lines · 2.6 KiB

Last changed by

Proofreading the documentationChris Edgemonbefore adoptiona7ff9db

History of this file

Take it

Break up deployment docs into separate documents.Armin Ronacherbefore adoptionc64a4e0

lines 1–13why, one step back
1mod_wsgi (Apache)
2=================34If you are using the `Apache`_ webserver you should consider using `mod_wsgi`_.56.. _Apache: http://httpd.apache.org/78Installing `mod_wsgi`9---------------------1011If you don't have `mod_wsgi` installed yet you have to either install it using12a package manager or compile it yourself.13

Proofreading the documentationChris Edgemonbefore adoptiona7ff9db

lines 14–15why, one step back
14The mod_wsgi `installation instructions`_ cover source installations on UNIX
15systems.

Break up deployment docs into separate documents.Armin Ronacherbefore adoptionc64a4e0

lines 16–46why, one step back
16
17If you are using ubuntu / debian you can apt-get it and activate it as follows::1819 # apt-get install libapache2-mod-wsgi2021On FreeBSD install `mod_wsgi` by compiling the `www/mod_wsgi` port or by using22pkg_add::2324 # pkg_add -r mod_wsgi2526If you are using pkgsrc you can install `mod_wsgi` by compiling the27`www/ap2-wsgi` package.2829If you encounter segfaulting child processes after the first apache reload you30can safely ignore them. Just restart the server.3132Creating a `.wsgi` file33-----------------------3435To run your application you need a `yourapplication.wsgi` file. This file36contains the code `mod_wsgi` is executing on startup to get the application37object. The object called `application` in that file is then used as38application.3940For most applications the following file should be sufficient::4142 from yourapplication import app as application4344If you don't have a factory function for application creation but a singleton45instance you can directly import that one as `application`.46

Proofreading the documentationChris Edgemonbefore adoptiona7ff9db

line 47why, one step back
47Store that file somewhere that you will find it again (e.g.:

Break up deployment docs into separate documents.Armin Ronacherbefore adoptionc64a4e0

lines 48–80why, one step back
48`/var/www/yourapplication`) and make sure that `yourapplication` and all
49the libraries that are in use are on the python load path. If you don't50want to install it system wide consider using a `virtual python`_ instance.5152Configuring Apache53------------------5455The last thing you have to do is to create an Apache configuration file for56your application. In this example we are telling `mod_wsgi` to execute the57application under a different user for security reasons:5859.. sourcecode:: apache6061 <VirtualHost *>62 ServerName example.com6364 WSGIDaemonProcess yourapplication user=user1 group=group1 threads=565 WSGIScriptAlias / /var/www/yourapplication/yourapplication.wsgi6667 <Directory /var/www/yourapplication>68 WSGIProcessGroup yourapplication69 WSGIApplicationGroup %{GLOBAL}70 Order deny,allow71 Allow from all72 </Directory>73 </VirtualHost>7475For more information consult the `mod_wsgi wiki`_.7677.. _mod_wsgi: http://code.google.com/p/modwsgi/78.. _installation instructions: http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide79.. _virtual python: http://pypi.python.org/pypi/virtualenv80.. _mod_wsgi wiki: http://code.google.com/p/modwsgi/wiki/