Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

Farm Setup By Example

Summary: An alternative introduction to creating a WikiFarm
Version: 0.04
Prerequisites: PmWiki 2.x
Status: Developing Gradually
Maintainer: Hagan Fox
Categories: WikiFarms

This page explains how to install multiple wikis using a single copy of PmWiki.

Specifically, it explains how to install PmWiki (if it's a fresh installation), add a farm-wide configuration file, add a new wiki, and then another new wiki, then customize the wikis using bundled scripts, recipes from the Cookbook, and skins.

Introduction

Because PmWiki is such a flexible piece of software, there are many different ways to set up a WikiFarm. This example starts either from scratch or with an existing stand-alone installation, and ends up with two (or two additional) freshly configured wikis, ready for authors to add content.

Here is how some terms are used in the context of this page.

  • A wiki is a wiki site that has its own URL, stored wiki pages, and local configuration file (local/config.php).
  • A WikiFarm is PmWiki configured to run multiple wikis. The term is related to the computing phrase "server farm".
  • A home wiki is a wiki in a farm that's in PmWiki's directory. If you start with a stand-alone installation and add a wiki, the original wiki becomes a home wiki.
  • Farm-wide refers to something that affects all wikis in a farm.
  • Local refers to something that affects an individual wiki.
  • A URL is a web address that you can reach with your web browser.
  • A filesystem location is location on the server's filesystem.

A wiki may or may not be running in the directory where the PmWiki software is installed. (In this example one won't be if you're starting from scratch.) Aside from the pub/ folder, PmWiki's installation location doesn't even need to be accessible via a URL.

Install PmWiki

(If you already have a stand-alone wiki you can skip to "Add a farm-wide configuration file (farmconfig.php)".)

Start by installing a fresh copy of PmWiki. It's not necessary to set up a wiki.d/ directory because the home wiki will be disabled. Our two wikis will be outside the PmWiki installation directory. (They can be in any web-accessible directory).

For the example, this will be the installation directory:

/home/someuser/public_html/pmwiki/

The URL for the home wiki would be:

http://www.example.com/~someuser/pmwiki/pmwiki.php

Here's the filesystem location of the home wiki's local/config.php file:

http://www.example.com/~someuser/pmwiki/local/config.php

Here are its contents, just a line to disable the home wiki:

<?php header('HTTP/1.0 403 Forbidden'); exit;

Or, if you want to return an error page, use something like this:

<?php
# Disable the home wiki for this farm.
header('HTTP/1.0 403 Forbidden');
exit('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD><TITLE>403 Forbidden</TITLE></HEAD>
<BODY><H1>403 Forbidden</H1>
<P>You do not have permission to access the requested file.
</BODY></HTML>');

You may also want to create an index file with the same contents. Place it in this filesystem location:

http://www.example.com/~someuser/pmwiki/index.php

Now what we have is essentially a locked-down stand-alone PmWiki installation.

Add a farm-wide configuration file (farmconfig.php)

Wikis in a farm can be configured farm-wide (globally, in farmconfig.php) and individually (locally, in config.php). Local configuration overrides global (see PmWiki.WikiCascades).

The farm-wide configuration file is placed in the local/ directory of the PmWiki installation:

/home/someuser/public_html/pmwiki/local/farmconfig.php

At minimum, farmconfig.php must specify $FarmPubDirUrl, the URL of the farm's pub/ directory. Here's a minimal farmconfig.php:

<?php if (!defined('PmWiki')) exit();
$FarmPubDirUrl = 'http://www.example.com/~someuser/pmwiki/pub';
Note: There's no way for PmWiki to automatically determine the URL location of the farm's pub/ directory, so it needs to be explicitly configured in 'farmconfig.php'.

Add a wiki

You can add a wiki in four simple steps.

  1. Create a directory somewhere in the web space.
  2. Add a wrapper script that points to pmwiki.php.
  3. Add a local configuration file.
  4. Let the PmWiki engine create a wiki.d/ directory for page storage.

For our example the directory will be wiki-one/ and the wrapper script will be an index file (index.php) in that directory:

/home/someuser/public_html/wiki-one/index.php

This script only needs one line:

<?php include('/home/someuser/public_html/pmwiki/pmwiki.php');

You could also use a relative path, rather than an absolute path:

<?php include('../pmwiki/pmwiki.php');

The URL will be either of these:

http://www.example.com/~someuser/wiki-one/
http://www.example.com/~someuser/wiki-one/index.php

The local configuration file will be in the wiki's local/ subdirectory, so its path will be:

/home/someuser/public_html/pmwiki/wiki-one/local/config.php

Here is an example local/config.php file:

<?php if (!defined('PmWiki')) exit();
## Title of this wiki
$WikiTitle = 'Wiki One';

## Produce a unique cookie prefix for this site.
$CookiePrefix = substr($tmp = md5(__FILE__), 0, 5).'_';

## Set an administrative password.  (String from ?action=crypt)
$DefaultPasswords['admin']='yourcryptedpassword';

## Enable graphical user interface buttons on edit pages.
$EnableGUIButtons = 1;

## Enable RSS and Atom web feeds.
if ($action == 'rss' || $action == 'atom') {
  include_once("$FarmD/scripts/feeds.php"); }

Now we have this directory structure:

wiki-one/
|-- index.php
`-- local/
    `-- config.php

After we visit this wiki's URL and prepare writable a wiki.d/ it will look like this:

wiki-one/
|-- index.php
|-- local/
|   `-- config.php
`-- wiki.d/

Add another wiki

The second new wiki will be installed in the same manner. The same wrapper script will be here this time:

/home/someuser/public_html/wiki-two/index.php

The URL will be either of these:

http://www.example.com/~someuser/wiki-two/
http://www.example.com/~someuser/wiki-two/index.php

The local configuration file goes in local/ subdirectory:

/home/someuser/public_html/pmwiki/wiki-two/local/config.php

Here are the contents of local/config.php for Wiki Two. (Only the wiki title and password are different.):

<?php if (!defined('PmWiki')) exit();
## Title of this wiki
$WikiTitle = 'Wiki Two';

## Produce a unique cookie prefix for this site.
$CookiePrefix = substr($tmp = md5(__FILE__), 0, 5).'_';

## Set an administrative password.  (String from ?action=crypt)
$DefaultPasswords['admin']='yourcryptedpassword';

## Enable graphical user interface buttons on edit pages.
$EnableGUIButtons = 1;

## Enable RSS and Atom web feeds.
if ($action == 'rss' || $action == 'atom') {
  include_once("$FarmD/scripts/feeds.php"); }

After we visit this wiki's URL and prepare a writable wiki.d/ directory to hold its wiki pages, Wiki Two's directory structure will look like this:

wiki-two/
|-- index.php
|-- local/
|   `-- config.php
`-- wiki.d/

Bundled scripts (the scripts/ directory)

If a wiki isn't a home wiki installed in the same directory as the PmWiki software you will need to make a small change to how you include a bundled script in local/config.php.

Instead of this:

include_once("scripts/somescript.php");

you will use this (with "double" quotes not 'single' quotes):

include_once("$FarmD/scripts/somescript.php");

Recipes (the cookbook/ directory)

Since each wiki in a farm is very similar to a stand-alone wiki, you can install recipes in the wiki's cookbook/ directory (you will need to create one) in the same manner as you would for a stand-alone wiki.

Better yet, you install a recipe in the main cookbook/ directory (the one included with the distribution) and make it available to all of the wikis in the farm. All you need to do is make a slight change to the line that includes the recipe's script.

Instead of this:

include_once("cookbook/somerecipe.php");

you will use this (with "double" quotes not 'single' quotes):

include_once("$FarmD/cookbook/somerecipe.php");

Skins (the pub/skins/ directory)

Skins can be installed farm-wide, locally, or both. Just as with configuration variables, the local version overrides the farm-wide version if both exist.

Skins you want to be globally available for any wiki in the farm should be installed in the farm's pub/skins/ directory, which you need to create if it's not there. An individual wiki can have its own pub/skins/ directory too, and skins can be placed there. PmWiki will look first in the wiki's pub/skins/ directory, and then in the farm's pub/skins/ directory.

Notes

Another way to establish a WikiFarm from scratch:

  1. Unpack the PmWiki software somewhere outside the web document tree.
  2. Move the pub/ directory to somewhere in the web space.
  3. Add a local/farmconfig.php and set $FarmPubDirUrl to the URL of the pub/ directory.
  4. Create wikis using the four steps.

It may be less confusing to create empty pub/css/ and pub/skins/ directories right from the start when a new wiki is added to the farm.

Release Notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

Comments

  • 15-Jun-2008 DaveG: Excellent tutorial. Since the context of the article is 'security' then you might want to add a section describing the permissions on the main directories and files.

See Also

  • WikiFarmAlternative provides methods for sharing PmWiki amongst co-located sites and safeguards the wiki.d directory.

Contributors

Edit - History - Print - Recent Changes - Search
Page last modified on June 15, 2008, at 09:27 AM