Toggle navigation

[UNKNOWN NODE title_reference] (Apache)

If you are using the Apache webserver you should consider using mod_wsgi.

Installing [UNKNOWN NODE title_reference]

If you don’t have [UNKNOWN NODE title_reference] installed yet you have to either install it using a package manager or compile it yourself.

The mod_wsgi installation instructions cover installation instructions for source installations on UNIX systems.

If you are using ubuntu / debian you can apt-get it and activate it as follows:

# apt-get install libapache2-mod-wsgi

On FreeBSD install [UNKNOWN NODE title_reference] by compiling the [UNKNOWN NODE title_reference] port or by using pkg_add:

# pkg_add -r mod_wsgi

If you are using pkgsrc you can install [UNKNOWN NODE title_reference] by compiling the [UNKNOWN NODE title_reference] package.

If you encounter segfaulting child processes after the first apache reload you can safely ignore them. Just restart the server.

Creating a [UNKNOWN NODE title_reference] file

To run your application you need a [UNKNOWN NODE title_reference] file. This file contains the code [UNKNOWN NODE title_reference] is executing on startup to get the application object. The object called [UNKNOWN NODE title_reference] in that file is then used as application.

For most applications the following file should be sufficient:

from yourapplication import make_app
application = make_app()

If you don’t have a factory function for application creation but a singleton instance you can directly import that one as [UNKNOWN NODE title_reference].

Store that file somewhere where you will find it again (eg: [UNKNOWN NODE title_reference]) and make sure that [UNKNOWN NODE title_reference] and all the libraries that are in use are on the python load path. If you don’t want to install it system wide consider using a virtual python instance.

Configuring Apache

The last thing you have to do is to create an Apache configuration file for your application. In this example we are telling [UNKNOWN NODE title_reference] to execute the application under a different user for security reasons:

<VirtualHost *>
    ServerName example.com

    WSGIDaemonProcess yourapplication user=user1 group=group1 processes=2 threads=5
    WSGIScriptAlias / /var/www/yourapplication/yourapplication.wsgi

    <Directory /var/www/yourapplication>
        WSGIProcessGroup yourapplication
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

For more information consult the mod_wsgi wiki.