Server!/Horror! I have a magnet and I don't mind using it!

I need a Wiki (or two, or three) - Quick!

OK so you need a Wiki in your company? - Not much of a problem just grab a copy of some wiki and there you go. Now that is fine for very small companies. You may need to have a Wiki for each project or departement and have some user rights within those Wikis. What are you gonna do? Create a whole new instance all the way thru everytime? I recommend a Wiki-Farm!

Let's have some requirements:

Personally I like Python and so I naturally prefer a Wiki implemented in Python - MoinMoin is such a Wiki. Also since modwsgi came up a setup with some webserver in front of it is not only quite easy but also fast.

It's not that much to set up a nice little Wiki-Farm.

Get a copy of the source code and create a nice directory structure to hold your new Wiki-Farm, I'm on Debian and this is my test box, so I simply installed modwsgi to get a nice setup resembling at least some kind of production layout.

$ # create a nice directory structure
$ sudo cd /srv
$ sudo mkdir -p /srv/moin/code/
$ sudo mkdir -p /srv/moin/wikis/wsgi
$ sudo mkdir -p /srv/moin/wikis/data
$ # grab the source from the mercurial repository
$ sudo hg clone http://hg.moinmo.in/moin/1.8 /srv/moin/code/1.8
$ sudo apt-get install libapache2-mod-wsgi

Ok now we have a nice little setup to get things started, let's configure Apache to get some error messages so that we know Python is actually handling our request...

$ # copy the configuration from upstream to a place that is maintainable
$ # we'll need this later on
$ sudo cp -i /srv/moin/code/1.8/wiki/server/moin.wsgi /srv/moin/wikis/wsgi/moin18.wsgi
$ sudo cp -i /srv/moin/code/1.8/wiki/config/wikifarm/farmconfig.py /srv/moin/wikis/wsgi/
$ sudo vim /etc/apache2/sites-enabled/000-default
We actually only need 3 lines (4 actually but this is just simple Apache stuff) of additional configuration for Apache HTTP Server, I personally like a bit overview so I split the lines up to provide a better human readable format.
alias /moin_static184/ "/srv/moin/code/1.8/wiki/htdocs/"
WSGIScriptAlias /wikis/moin18.wsgi /srv/moin/wikis/wsgi/moin18.wsgi
WSGIDaemonProcess moin18 \
   user=moin18 \
   group=moin18 \
   home=/srv/moin/wikis/18 \
   processes=5 \
   threads=15 \
   maximum-requests=1000 \
   umask=0007 \
   display-name=moin18
WSGIProcessGroup moin18
Let's see what we did wrong:
$ sudo apache2ctl -t
apache2: bad user name moin18
Uh oh! Let's now add the user (and group)
$ sudo adduser --no-create-home --disabled-login --shell /bin/false moin18
Debian will ask a few questions and create a user and group appropriate for our requirements. Another time checking the Apache config tells us everyting is fine.
$ sudo apache2ctl -t
Syntax OK
$ sudo /etc/init.d/apache2 restart
Restarting web server: apache2 ... waiting .
Ok so let's try the configured URL - http://localhost/wikis/moin18.wsgi. Gives us an internal server error and that is a good thing(TM) because we know Apache HTTP is trying to serve something that is configured the wrong way.

So let's fix our WSGI Script. At the top level add the path to the MoinMoin package and then add the path to where your WSGI script is located:

sys.path.insert(0, '/srv/moin/code/1.8/')
sys.path.insert(0, '/srv/moin/wikis/wsgi/')
Calling http://localhost/wikis/moin18.wsgi again should now show you a nice little error message that looks a bit more like python.

Let's edit the aforementiond farmconfig.py file, we don't need to do that much,  actually I changed only 3 settings:

# data_dir = "./data" # comment this out to explicitely set the data dir for a single Wiki
data_underlay_dir = '/srv/moin/code/1.8/wiki/underlay/'
superuser = [u"MartinMarcher", ]
acl_rights_before = u"MartinMarcher:read,write,delete,revert,admin"
We'll configure the underlay dir, and make sure that there is a user that can do everyting (myself in that case). Now there's the wiki variable at the top of the farmconfig.py file, it has a wiki preconfigured "mywiki". Now the interesting part is to create a simple config that uses everything that
import farmconfig
class Config(farmconfig.FarmConfig):
    sitename = u"MyWiki"
    data_dir = '/srv/moin/wikis/data/mywiki/'
    page_front_page = u"FrontPage"
All you need to do is actually tell MoinMoin where it should place the data and what the start page of your Wiki is (the last one is actually a lie but I like the implicit mentioning of the configuration parameter more that having it in the farmconfig.py).

Nearly finished, let's set up the underlay_dir which holds the help pages provided by MoinMoin upstream and also fix the permissions:

$ sudo tar -C /srv/moin/code/1.8/wiki -tf /srv/moin/code/1.8/wiki/underlay.tar
$ sudo chown -R moin18:moin18 /srv/moin/code/1.8/wiki/underlay
Also we need the data_dir set up correctly for our shiny new wiki:
$ sudo cp -a /srv/moin/code/1.8/wiki/data/ /srv/moin/wikis/data/mywiki/
$ sudo chown -R moin18:moin18 /srv/moin/wikis/data/mywiki/
That's about it. You now have a nice Wiki in place you can send as a gift to your customers. Actually that was not quite as short as one might think but the effort pays of with a second wiki.

Wiki-Farms in MoinMoin work by matching the request URI. go to your farmconfig.py (/srv/moin/wikis/wsgi/farmconfig.py) and edit the list variable called wikis. By default it looks like this:

wikis = [
    # Standalone server needs the port e.g. localhost:8000
    # Twisted server can now use the port, too.                         </p>
<p>    # wikiname,     url regular expression (no protocol)
    # ---------------------------------------------------------------
    ("mywiki", r".*"),   # this is ok for a single wiki</p>
<p>    # for multiple wikis, do something like this:
    #("moinmoin",    r"^moinmo.in/.*$"),
    #("moinmaster",  r"^master.moinmo.in/.*$"),
]
Now make it look like this and there's just one more step to do for a second wiki:
wikis = [
    # wikiname,     url regular expression (no protocol)
    # ---------------------------------------------------------------
    ("mywiki", r"^localhost/wikis/moin18.wsgi/mywiki/.*"),
    ("anotherwiki", r"^localhost/wikis/moin18.wsgi/anotherwiki/.*"),
]
Now create a new python module in /srv/moin/wikis/wsgi/ and edit the sitename variable accordingly.
class Config(farmconfig.FarmConfig):
    siteid = u"AnotherWiki"
    sitename = u"AnotherWiki"
    data_dir = '/srv/moin/wikis/data/anotherwiki/'
    page_front_page = u"FrontPage"
All there's left to do is to create another data dir for your shiny new (second) Wiki and apply the correct permissions:
$ sudo cp -a /srv/moin/code/1.8/wiki/data/ /srv/moin/wikis/data/anotherwiki/
$ sudo chown -R moin18:moin18 /srv/moin/wikis/data/anotherwiki/
What we did, in this las step, was:

The URI matching probably needs a bit of explanation it matches everything except the protocoll part (http:// or https://). Construct it this way:

Generated: 2017-11-02 10:20:47 +0100