If you're running Apache 1.3 (or an httpd based on Apache 1.3, such as OpenBSD's httpd), it's still possible to get MoinMoin working under WSGI. It will take some additional steps. These instructions assume you have root (superuser) privileges on the wiki server, and a dedicated virtual host name that you will use for your wiki (e.g. mywiki.your.domain).

Before we start, you should take note of your wiki directory (something like /var/www/moin/mywiki) and your wiki user (something like www or www-data -- whatever account owns the wiki directory and its content).

  1. Install CherryPy on the wiki server.

  2. Copy moin.wsgi from the wiki/server/ subdirectory of the source tree into your wiki directory and edit it. For moin 1.8:

       1 #!/usr/bin/env python
       2 # -*- coding: iso-8859-1 -*-
       3 """
       4     MoinMoin - mod_wsgi driver script
       5     ...
       6 """
       7 
       8 from MoinMoin.server.server_wsgi import WsgiConfig, moinmoinApp
       9 from cherrypy.wsgiserver import CherryPyWSGIServer, WSGIPathInfoDispatcher
      10 
      11 class Config(WsgiConfig):
      12     pass
      13 
      14 config = Config()
      15 
      16 application = moinmoinApp
      17 
      18 def run_cherrypy(app, address='', port=8080):
      19     from cherrypy import wsgiserver
      20     d = WSGIPathInfoDispatcher({'/': app})
      21     server = CherryPyWSGIServer((address, port), d,
      22                                 server_name='mywiki.your.domain')
      23     try:
      24         server.start()
      25     except KeyboardInterrupt:
      26         server.stop()
      27 
      28 run_cherrypy(application, '0.0.0.0', 8080)
    
    For moin 1.9:
       1 #!/usr/bin/env python
       2 # -*- coding: iso-8859-1 -*-
       3 """
       4     MoinMoin - mod_wsgi driver script
       5     ...
       6 """
       7 
       8 from MoinMoin.web.serving import make_application
       9 from cherrypy.wsgiserver import CherryPyWSGIServer, WSGIPathInfoDispatcher
      10 
      11 # Creating the WSGI application
      12 # use shared=True to have moin serve the builtin static docs
      13 # use shared=False to not have moin serve static docs
      14 # use shared='/my/path/to/htdocs' to serve static docs from that path
      15 application = make_application(shared=False, trusted_proxies=['127.0.0.1'])
      16 
      17 def run_cherrypy(app, address='', port=8080):
      18     from cherrypy import wsgiserver
      19     d = WSGIPathInfoDispatcher({'/': app})
      20     server = CherryPyWSGIServer((address, port), d,
      21                                 server_name='mywiki.your.domain')
      22     try:
      23         server.start()
      24     except KeyboardInterrupt:
      25         server.stop()
      26 
      27 run_cherrypy(application, '0.0.0.0', 8080)
    
    • Change the server_name= part and the port number, if you want. You may use any port number greater than 1023 that's not already being used by something else. (We'll be running this program as an unprivileged user, so we can't use ports under 1024.) Give it execute permissions with a chmod 755 moin.wsgi command.

    • The trusted_proxies list in moin 1.9 lets your RecentChanges page pick up the actual origin of the changes (as reported by Apache), rather than just reporting "localhost" for everything. The analogous list in moin 1.8 is called proxies_trusted and is in MoinMoin/request/__init__.py (requires editing the source code).

  3. Arrange for the moin.wsgi program to be run as your wiki user, inside the wiki directory, according to whatever techniques you use on your system for boot scripts or the like. Start it running now. You should see it listening on port 8080 (or whatever you set in the moin.wsgi file).

  4. Edit your Apache configuration (httpd.conf or whatever filename is correct for your system):

    ...
    Alias /moin_static183/ "/usr/local/share/moin/htdocs/"
    ...
    NameVirtualHost *:80
    ...
    <VirtualHost *:80>
    ServerName mywiki.your.domain
    ServerAdmin your@email.address
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/moin_static.../
    RewriteRule ^/(.*) http://127.0.0.1:8080/$1 [P]
    ProxyRequests Off
    ProxyPassReverse / http://127.0.0.1:8080/
    ErrorLog /var/www/logs/mywiki.your.domain-error.log
    CustomLog /var/www/logs/mywiki.your.domain-access.log combined
    </VirtualHost>
    • Obviously, you should change the htdocs location, the port number, and the logfile locations as necessary.

    • The moin_static183 in the Alias should be changed for each version of MoinMoin. The moin_static... part in the RewriteCond is a regular expression, so it will match every version, and doesn't need adjustment. The purpose of the rewriting code here is to allow the Alias to work for the static content URLs, and rewrite (proxy) everything else to the CherryPy service.

    • Reload or restart your Apache so that it picks up the changes.

That's basically all. Your wiki should be visible at http://mywiki.your.domain/ now. Test everything and make sure it seems correct.

MoinMoin: HowTo/ApacheWithCherryPy (last edited 2009-12-14 18:40:26 by GregWooledge)