Difference between revisions of "Wiki Family"
Jump to navigation
Jump to search
Line 223: | Line 223: | ||
</source> | </source> | ||
− | = worksite.php = | + | === worksite.php === |
<source lang='php'> | <source lang='php'> | ||
<?php | <?php | ||
Line 274: | Line 274: | ||
?> | ?> | ||
</source> | </source> | ||
+ | |||
= runjobs = | = runjobs = | ||
<source lang='bash'> | <source lang='bash'> |
Revision as of 08:43, 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
/etc/apache2/sites-available/wiki1.conf
#
# 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>
/etc/apache2/wiki1.conf
Some of the settings here are optional like making font-awesome available. Just comment out things you might not need.
# Apache2 configuration wiki1 for wiki1.doe.com
# created 2015-11-28 09:13:10 by createsite script
DocumentRoot /var/www/mediawiki/wiki1.doe.com
include doe_aliases.conf
# make the font-awesome directory available unconditionally
Alias /font-awesome "/var/www/font-awesome"
# the following aliases need to be access restricted later with
# a directory setting
Alias "/images/wiki1" "/var/www/mediawiki/sites/wiki1.doe.com/images"
Alias "/images" "/var/www/mediawiki/sites/wiki1.doe.com/images"
Alias "/videos" "/var/www/mediawiki/sites/wiki1.doe.com/videos"
# this is important for security - the .htaccess files need to be activated
# for the images and videos directories so that access is controlled
<Directory /var/www/mediawiki/sites/wiki1.doe.com>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
#LogLevel debug
# the log files to use
ErrorLog ${APACHE_LOG_DIR}/wiki1_error.log
CustomLog ${APACHE_LOG_DIR}/wiki1.log combined
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