How to operate multiple TWiki sites with a single software installation
by Ian Kluft
See my presentation slides
from the Nov 29, 2007 TWiki Meetup.
It's possible to run more than one TWiki site with a single installation
of the TWiki.Org software.
The configuration file is usually used like a flat text file.
But it's a series of Perl variable assignments.
And it is itself a Perl script.
It is possible to add Perl code to make the TWiki server detect the
domain in which an incoming request was directed, and select
configuration settings based on the incoming request.
How it started
I developed this for the
Stratofox Aerospace Tracking Team
in April 2004 in order to create separate private discussion web sites
for the May 17 "CSXT Space Shot 2004"
(in which CSXT claimed a flight altitude of 72 miles or 380,000',
the first amateur rocket launch to space) and the June 7 Paragon
Space Launch (which launched but experienced an in-flight failure and
did not reach space).
This trick was later used to set up public TWiki sites for
- wiki.sbay.org
(South Bay Community Network, Inc., a California non-profit corporation)
- svwux.org
(SVWUX, the Silicon Valley Wireless Users and eXperimenters)
- linuxpicnic.org
(Linux Picnic, annual celebration of the anniversary of Linus Torvalds' Aug 1991 public release of the Linux Kernel)
and a
public wiki for Stratofox as well.
How to do it
Note: (Nov 30, 2007) It has been pointed out that this solution works
only for CGI-based TWiki environments, not on mod_perl, speedy or fastcgi.
We'll have to keep working on a more general solution.
But for now a solution for any environment is better than we had before.
The changes which I made to the configuration file were not extensive.
This is what it took to make all those TWiki sites listed above work
on one Apache HTTPD server.
This is shown in the format of a simple Unix diff.
54a55,58
> # capture server name so this can be used for multiple TWiki's
> $ENV{SERVER_NAME} =~ /^([A-Z0-9_.-]+)/i;
> $server_name = $1;
> $server_name =~ s/^www\.//;
62c66
< $defaultUrlHost = "http://your.domain.com";
---
> $defaultUrlHost = "http://$server_name";
72c76
< $pubDir = "/home/httpd/twiki/pub";
---
> $pubDir = "/home/httpd/$server_name/twiki/pub";
76c80
< $dataDir = "/home/httpd/twiki/data";
---
> $dataDir = "/home/httpd/$server_name/twiki/data";
219c223
< $displayTimeValues = "gmtime";
---
> $displayTimeValues = "servertime";
329c333
< $wikiHomeUrl = "http://your.domain.com/twiki";
---
> $wikiHomeUrl = "http://$server_name/twiki";
|
How it works
Here's a summary of how it works.
- Capture the SERVER_NAME from the CGI environment provided by the web server
into the $server_name Perl variable.
- Use $server_name to set the $defaultUrlHost, $pubDir, $dataDir and $wikiHomeUrl configuration variables, instead of using static assignments.
- The directories named by these paths must already exist with twiki/data and twiki/pub directories in order for the separate TWiki site to work.
- The twiki/bin and twiki/lib directories and twiki/.htaccess file
can be symbolic links to your single TWiki installation directory
for the server.
- Using symlinks to the code helps you to upgrade TWiki later.