Difference between revisions of "Wiki Family"
Jump to navigation
Jump to search
Line 9: | Line 9: | ||
# wiki2.doe.com | # wiki2.doe.com | ||
# wiki3.doe.com | # wiki3.doe.com | ||
− | To your DNS entries and make sure your http server configuration is setup accordingly | + | To your DNS entries and make sure your http server configuration is setup accordingly. |
+ | Virtual hosts can also be configured per IP address or per port. So a different setup is feasible but not as straight-forward. | ||
=== Example Apache config === | === Example Apache config === | ||
<source lang='apache'> | <source lang='apache'> | ||
Line 28: | Line 29: | ||
</VirtualHost> | </VirtualHost> | ||
</source> | </source> | ||
+ | |||
== Directory Layout == | == Directory Layout == | ||
<graphviz> | <graphviz> |
Revision as of 08:38, 25 November 2020
Principle
https://www.mediawiki.org/wiki/Manual:Wiki_family
Example Setup
Virtual Host based selection
The principle of this Wikifarm setup is to use a virtual host based selection of the target Wiki in the Wikifamily. Therefore each Wiki needs it's own virtual host. The simples way to achieve this is by having separate site names per wiki. So if your domain is doe.com and you want three wikis you would add
- wiki1.doe.com
- wiki2.doe.com
- wiki3.doe.com
To your DNS entries and make sure your http server configuration is setup accordingly. Virtual hosts can also be configured per IP address or per port. So a different setup is feasible but not as straight-forward.
Example Apache config
#
# Apache site wiki1
# Virtualhost wiki1.doe.com
# created 2015-11-28 08:25:54 by createsite script
<VirtualHost *:80>
ServerAdmin webmaster@doe.com
ServerName wiki1.doe.com
Redirect permanent / https://wiki1.doe.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@doe.com
ServerName wiki1.doe.com
include ssl.conf
include wiki1.conf
</VirtualHost>
Directory Layout
Localsettings.php (code)
<?php
/**
* MediaWiki wikifamily handling code
*
* Taken from Drupal code to tap multisite configuration.
*/
// returns true if $needle is a substring of $haystack
function contains($needle, $haystack)
{
return strpos($haystack, $needle) !== false;
}
/**
* Find the appropriate configuration directory for the current request
*/
function findConfiguration($confdir,$domain,$debug) {
$host=$_SERVER['SERVER_NAME'];
$host=str_replace(".q.",".",$host);
if ($debug) {
print ("find Configuration for ".$host." in ".$confdir." for domain ".$domain."<br>");
}
if ($host) return $host; else return NULL;
}
/**
* optionally add the given settings
*/
function optionalRequireSettings($settings) {
if (file_exists($settings)) {
require_once($settings);
}
}
# switch on for debuging
$debug=false;
# the main configuration directory in which all wiki farm member sites are configured
$confdir = '/var/www/mediawiki/sites';
# The Prefix to use for local/specialized configuration files
$prefix="BITPlan";
# find the configuration for the current request
$domain="bitplan.com";
$conf=findConfiguration($confdir,$domain,$debug);
#$conf=NULL;
# if we found a configuration then use it
if ($conf) {
# make sure all farm members use the same .smw.json file
# https://www.semantic-mediawiki.org/wiki/Help:$smwgConfigFileDir
global $smwgConfigFileDir;
global $wgWikiFarmSite;
$wgWikiFarmSite=str_replace(".".$domain,"",$conf);
# uncomment for better debugging
if ($debug) {
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
$wgShowExceptionDetails=true;
}
$smwgConfigFileDir = $confdir;
#
# first use the specific LocalSettings for the site
$lsettings="$confdir/$conf/LocalSettings.php";
if ($debug) {
print ("Localsettings from ".$lsettings);
}
require_once( $lsettings );
# then use the global settings for the farm
# if there are further specific settings for the site use them
$gsettings=array("$confdir/{$prefix}Settings.php","$confdir/$conf/{$prefix}Settings.php");
foreach ($gsettings as $gsetting) {
if (file_exists($gsetting)) {
require_once($gsetting);
}
}
} else {
$IP = '.';
require_once( './includes/DefaultSettings.php' ); # used for printing the version
require_once( './includes/NoLocalSettings.php' );
die("wikifarm could not find configuration for $wgServer");
}
?>
worksite.php
<?php
// see https://www.mediawiki.org/wiki/Manual:Wiki_family#Updating_wikifarm_from_the_commandline
// show an error and die
function error($msg) {
die($msg);
}
// check command line arguments
if (count($argv)<3) {
error("usage: worksite [sitename] [update|runJobs|debug|updateNameSpaceCache]");
}
//$argv gets commandline arguments
$siteid= $argv[1]; // siteid e.g. test
$work = $argv[2]; // work to do e.g. update
// set domain name
#$site = $siteid. '.bitplan.com';
$site = $siteid;
$_SERVER['SERVER_NAME'] = $site;
$_SERVER['HTTP_HOST'] = $site;
$_MWCONFIGFILE="/var/www/mediawiki/sites/$site/FullLocalSettings.php";
define( 'MW_CONFIG_FILE', $_MWCONFIGFILE);
echo '--------------------------------------
Running '.$work.'.php for ' . $site . '
--------------------------------------
';
switch ($work) {
case "debug":
echo "$work in progess ...";
echo "MWCONFIGFILE: ".$_MWCONFIGFILE;
#include($_MWCONFIGFILE);
global $cargoavailable;
echo "Cargo:".$cargoavailable;
break;
case "updateEntityCountMap":
include("extensions/SemanticMediaWiki/maintenance/updateEntityCountMap.php");
break;
case "updateNameSpaceCache":
#$language=
#$namespaces=$language->getNamespaces();
#foreach ($namespace ...)
break;
default:
include("maintenance/$work.php");
}
?>
runjobs
#!/bin/bash
# WF 2015-06-08
# run jobs for all sites
jobs=$(pgrep -fla runjobs | wc -l)
if [ $jobs -gt 3 ]
then
echo "$jobs runjobs already running ..."
exit 1
fi
cd /srv/www/mediawiki/code
host=$(hostname)
cat $host.sites | egrep -v "^#" | while read siteid site
do
#./update $siteid
#echo $siteid
#echo $site
/usr/bin/php /srv/www/mediawiki/code/worksite.php $site runJobs \
--conf /srv/www/mediawiki/sites/$site/FullLocalSettings.php >> /var/log/mediawiki/runJobs_$siteid.log 2>&1
done