Developing and Deploying

Developing Using repoze.zope2

On a UNIX machine that has the capability of compiling Python software (e.g. gcc is installed and working and Python development libraries are installed), follow the instructions at the Quickstart page to get up and running.

Repoze in Development architecture diagram

The important deviations from the standard Zope/Plone install and deployment process are as follows:

  • All Python packages are packaged and deployed as Python eggs and placed into the virtual Python's site-packages (if installed via easy_install) or in the eggs directory (if installed via buildout).
  • Zope is being served up via a WSGI server (currently the reimplemented ZServer wsgihttpserver in zope3).
  • A middleware pipeline is configured to include: error handling, a transaction manager, retry middleware, and virtual hosting middleware "in front" of Zope and Plone (see etc/zope2.ini).
  • ZPublisher is not publishing Zope 2. Instead repoze.zope2 emulates ZPublisher's publishing machinery and publishes Zope. The only ZPublisher code used by repoze.zope2 is the Zope 2 HTTPRequest and HTTPResponse classes.

For more information about differences between developing under repoze.zope2, see the PDF at Developing With repoze.zope2 .

Deployment Using a Paste server plus an Apache VirtualHost Rewrite Proxy

You can deploy repoze.zope2 installed as per the Quickstart page behind an Apache proxy. For instance to serve the Zope root on 'www.example.com':

     <VirtualHost *:80>
       ServerName  www.example.com
       RewriteEngine On                                                        
       RewriteRule ^/(.*) http://127.0.0.1:8080/VirtualHostBase/http/www.example.com:80/VirtualHostRoot/$1 [L,P]
     </VirtualHost> 

Alternately if you have mod_headers compiled in to Apache, you can use headers to perform virtual hosting ala:

     <VirtualHost *:80>
       ServerName www.example.com
       RewriteEngine On
       RewriteRule ^/(.*) http://127.0.0.1:8080/$1 [L,P]
       RequestHeader add X-Vhm-Host http://www.example.com/
     </VirtualHost>

You can also serve up a Zope subfolder behind an Apache proxy. For instance to serve up a plone subfolder on 'www.example.com':

     <VirtualHost *:80>
       ServerName  www.example.com
       RewriteEngine On                                                        
       RewriteRule ^/(.*) http://127.0.0.1:8080/VirtualHostBase/http/www.example.com:80/plone/VirtualHostRoot/$1 [L,P]
     </VirtualHost> 

Alternately if you have mod_headers compiled in to Apache, you can use headers to perform virtual hosting to the plone subfolder ala:

     <VirtualHost *:80>
       ServerName www.example.com
       RewriteEngine On
       RewriteRule ^/(.*) http://127.0.0.1:8080/$1 [L,P]
       RequestHeader add X-Vhm-Host http://www.example.com
       RequestHeader add X-Vhm-Root /plone
     </VirtualHost>

Deployment under Apache + mod_wsgi

It's materially simpler and far better for development to run repoze.zope2 under a Paste server. But for production, it's sometimes advantageous to run it under mod_wsgi, an Apache module for running WSGI applications.

In a mod_wsgi configuration, there will be multiple process which need to use the same ZODB database. We must accommodate this requirement by modifying etc/zope.conf, configuring the Zope instance to use ClientStorage and a ZEO server instead of a FileStorage. There is a section in the default repoze zope.conf commented out that provides an easy way to do that (just uncomment it and comment the filestorage-related ZODB stanza).

Repoze in mod_wsgi architecture diagram

After such changes, the repoze application environment directory may be deployed to an Apache / mod_wsgi 2.X environment with an Apache configuration like this (replace ${sandbox} with the path to your Repoze installation's top-level environment in any below examples):

      WSGIPythonHome ${sandbox}
      WSGIDaemonProcess zope2 threads=1 processes=4 maximum-requests=10000 python-path=${sandbox}/lib/python2.4/site-packages

      <VirtualHost *:80>
        ServerName my.machine.local
        WSGIScriptAlias /site ${sandbox}/bin/zope2.wsgi
        WSGIProcessGroup zope2
        WSGIPassAuthorization On
        SetEnv HTTP_X_VHM_HOST http://my.machine.local/site
      </VirtualHost>

If you don't want to use an Apache virtual host, you can also avoid the use of any VirtualHost directive by using a Location directive:

      WSGIPythonHome ${sandbox}
      WSGIDaemonProcess zope2 threads=1 processes=4 maximum-requests=10000 python-path=${sandbox}/lib/python2.4/site-packages

      <Directory ${sandbox}/bin>
        Order deny,allow
        Allow from all
      </Directory>

      WSGIScriptAlias /site ${sandbox}/bin/zope2.wsgi
      WSGIProcessGroup zope2

      <Location /site>
        WSGIPassAuthorization On
      </Location>

This will make your Zope instance available under the /site directory of your Apache's my.machine.local virtual host. You may change the WSGIScriptAlias to '/ and change the location to /' in order to serve it at the root of this Apache instance instead. The bin/zope2.wsgi file is a generic WSGI application loader which uses Paste to parse the etc/zope2.ini file and configure the application for use under mod_wsgi. A typical zope2.wsgi file might look like so:

      import os
      from paste.deploy import loadapp

      ini = '${sandbox}/etc/zope2.ini'
      application = loadapp('config:%s' % ini)

See the mod_wsgi configuration documentation for more information about alternate and further configuration.