User:*Surak*/SimpleFarm

This page describes my SimpleFarm experience.

Installation edit

I use a MediaWiki 1.19.1 farm with the SimpleFarm 0.1rc extension that contains three wikis (PROJECT1, PROJECT2, PROJECT3) that share the same productive database. A second implementation contains the same wikis sharing a different test database for testing purpose. I keep all settings in a separate directory parallel to the mediawiki installation directory. Every wiki shall be called using a 'pretty' clean URL.

Installation Directories:

http://www.proddomain.com/wikiroot/mediawiki/
http://www.proddomain.com/wikiroot/settings/

http://www.proddomain.com/testroot                     → http://www.testdomain.com
http://www.proddomain.com/testroot/wikiroot/mediawiki/ → http://www.testdomain.com/wikiroot/mediawiki/
http://www.proddomain.com/testroot/wikiroot/settings/  → http://www.testdomain.com/wikiroot/settings/

Wiki URL:

http://www.proddomain.com/project1/Main_page
http://www.proddomain.com/project2/Main_page
http://www.proddomain.com/project3/Main_page

http://www.testdomain.com/project1/Main_page
http://www.testdomain.com/project2/Main_page
http://www.testdomain.com/project3/Main_page

Settings edit

Due to the redirect from www.proddomain.com/testroot/wikiroot to www.testdomain.com/wikiroot, I can use the same setup files with settings in both domains.

/.htaccess edit

# General Options ==============================================================
  AddType application/x-httpd-php5 .php .php4 .php5
  Options +FollowSymLinks
  Options -Indexes
  mod_gzip_on Yes

# Rewrite Options ==============================================================
  RewriteEngine On
  RewriteBase /

# add trailing backslash to directories only
  RewriteRule ^((?:.*/)?[^\.]*[^/])$  $1/

# MediaWiki Options ============================================================
# redirect w/o adding index.php
  RewriteRule ^(project1|project2|project3)/(.*\.php)     wikiroot/mediawiki/$2 [L,PT]
  RewriteRule  (project1|project2|project3)/(images/.*)   wikiroot/mediawiki/$2 [L,PT]
# RewriteRule ^(project1|project2|project3)/(includes/.*) wikiroot/mediawiki/$2 [L,PT]
# RewriteRule ^(project1|project2|project3)/(skins/.*)    wikiroot/mediawiki/$2 [L,PT]
# cleanup URL = redirect virtual wiki path to physical wiki path
  RewriteRule ^(project1|project2|project3)/(.*)$         wikiroot/mediawiki/index.php?title=$2 [L,PT,QSA]
# no clean URL
# RewriteRule ^(project1|project2|project3)/(.*)$         wikiroot/mediawiki/$2 [L,PT]

/wikiroot/mediawiki/LocalSettings.php edit

<?php
# Protect against web entry
if ( !defined( 'MEDIAWIKI' ) ) {
	exit;
}

# Shared settings for the wiki farm
  require_once dirname(dirname( __FILE__ )) . '/settings/farm-settings.php';

/wikiroot/settings/farm-settings.php edit

<?php
# All settings in this settings file apply to the whole farm.  Since we
# maintain the two farms PROD and TEST, some of the settings are switched
# between them.

# Protect against web entry
if ( !defined( 'MEDIAWIKI' ) ) {
  exit;
}

# ------------------------------------------------------------------------------
# Private Settings
# ------------------------------------------------------------------------------
# The following settings includes all used $wp* variables

  require_once dirname( __FILE__ ) . '/farm-settings-wpDefines.php';

# ------------------------------------------------------------------------------
# Farm Settings
# ------------------------------------------------------------------------------

  require_once( $IP . '/extensions/SimpleFarm/SimpleFarm.php' );
  $egSimpleFarmMembers = array(
      array(
            'name'                => 'Project1',          # $wgSitename
            'scriptpath'          => '/project1',         # $wgScriptPath
            'db'                  => 'project1',          # virtual database
            'addresses'           => array( $wpDomainNamePROD, 
                                            $wpDomainNameTEST ),
            'maintain'            => false,
      ),
      array(
            'name'                => 'Project2',          # $wgSitename
            'scriptpath'          => '/project2',         # $wgScriptPath
            'db'                  => 'project2',          # virtual database
            'addresses'           => array( $wpDomainNamePROD, 
                                            $wpDomainNameTEST ),
            'maintain'            => false,
      ),
      array(
            'name'                => 'Project3',          # $wgSitename
            'scriptpath'          => '/project3',         # $wgScriptPath
            'db'                  => 'project3',          # virtual database
            'addresses'           => array( $wpDomainNamePROD, 
                                            $wpDomainNameTEST ),
            'maintain'            => false,
      ),
  );
  SimpleFarm::init();
  $wpCurrentWiki = SimpleFarm::getActiveMember();

# ------------------------------------------------------------------------------
# Domain and Database Settings
# ------------------------------------------------------------------------------

  $wpWikiDomainPath               = dirname( dirname( dirname( __FILE__ ) ) );
  switch( substr( $wpWikiDomainPath, strrpos( $wpWikiDomainPath, '/' ) + 1 ) ) {
    case '/':
      $wpWikiDomain               = 'PROD';
      break;
    case 'testroot':
      $wpWikiDomain               = 'TEST';
      break;
    default:
      $wpWikiDomain               = 'UNKNOWN';
  }

  switch ( $wpWikiDomain ) {
    case 'PROD':
    # DB settings
      $wgDBserver                 = $wpPRODDBServer;
      $wgDBname                   = $wpPRODDBname;
      $wgDBadminuser              = $wpPRODDBadminuser;
      $wgDBadminpassword          = $wpPRODDBadminpassword;
      $wgDBuser                   = $wpPRODDBuser;
      $wgDBpassword               = $wpPRODDBpassword;
      $egSimpleFarmMainMemberDB   = $wgDBserver;
      break;
    case 'TEST':
    # DB settings
      $wgDBserver                 = $wpTESTDBserver;
      $wgDBname                   = $wpTESTDBname;
      $wgDBadminuser              = $wpTESTDBadminuser;
      $wgDBadminpassword          = $wpTESTDBadminpassword;
      $wgDBuser                   = $wpTESTDBuser;
      $wgDBpassword               = $wpTESTDBpassword;
      $egSimpleFarmMainMemberDB   = $wgDBserver;
      break;
    default:
      die ( 1 ); # e.g., the backup copy
  }

# ------------------------------------------------------------------------------
# Shared Settings
# ------------------------------------------------------------------------------

  $wgLocalInterwiki               = $wpCurrentWiki->getCfgOption( 'db' );
  $wgArticlePath                  = '/' . $wgLocalInterwiki . '/$1';
  $wgUsePathInfo                  = true;
  $wgScriptExtension              = '.php';
  $wgStylePath                    = $wgScriptPath . '/skins';
  $wgLanguageCode                 = 'de';
  $wgSkipSkins                    = array( 'chick',
                                           'cologneblue',
                                           'myskin',
                                           'nostalgia',
                                           'simple',
                                           'standard' );
  $wgDefaultSkin                  = 'modern';

  $wgEnableEmail                  = true;
  $wgEnableUserEmail              = true;
  $wgEmergencyContact             = 'webmaster@' . $wpDomainName;
  $wgPasswordSender               = 'webmaster@' . $wpDomainName;
  $wgPasswordSenderName           = 'Wiki Administrator';
  $wgEnotifUserTalk               = true;
  $wgEnotifWatchlist              = true;
  $wgEmailAuthentication          = true;

  $wgDBtype                       = 'mysql';
  $wgDBTableOptions               = 'ENGINE=InnoDB, DEFAULT CHARSET=binary';
  $wgDBmysql5                     = false;

# $wgCacheDirectory               = '$IP/cache';
# $wgDisableOutputCompression     = true;
  $wgMainCacheType                = CACHE_NONE;
  $wgMemCachedServers             = array();
  $wgEnableUploads                = true;
# $wgHashedUploadDirectory        = false;
  $wgResourceLoaderMaxQueryLength = -1;

  $wgShellLocale                  = 'en_US.utf8';
  $wgDiff                         = '/bin/diff';
  $wgDiff3                        = '';
  $wgUseImageMagick               = true;
  $wgImageMagickConvertCommand    = '/usr/bin/convert';
  $wgUseTeX                       = false;

  $wgUseInstantCommons            = true;
  $wgEnableCreativeCommonsRdf     = true;
  $wgRightsPage = ''; # Set to the title of a wiki page that describes your license/copyright
  $wgRightsUrl  = 'http://creativecommons.org/licenses/by-nc-sa/3.0/';
  $wgRightsText = 'Creative Commons „Namensnennung, nicht kommerziell, Weitergabe unter gleichen Bedingungen“';
  $wgRightsIcon = '{$wgStylePath}/common/images/cc-by-nc-sa.png';
  $wgRightsCode = ''; # Not yet used

# ------------------------------------------------------------------------------
# Shared Extensions & User Rights
# ------------------------------------------------------------------------------

  require_once dirname( __FILE__ ) . '/farm-settings-extensions.php';
  require_once dirname( __FILE__ ) . '/farm-settings-semantic.php';
  require_once dirname( __FILE__ ) . '/farm-settings-privileges.php';

# ------------------------------------------------------------------------------
# Wiki-specific Settings
# ------------------------------------------------------------------------------

  switch( $wpCurrentWiki->getCfgOption( 'db' ) ) {
    case 'project1':
    # put any project-specific settings here; you can overwrite the shared settings here for this wiki
    # $wgDBprefix
    # $wgSecretKey
    # $wgUpgradeKey
      $wgEmergencyContact         = 'project1@' . $wpDomainName;
      $wgPasswordSender           = 'project1@' . $wpDomainName;
      break;
    case 'project2':
    # put any project-specific settings here; you can overwrite the shared settings here for this wiki
    # $wgDBprefix
    # $wgSecretKey
    # $wgUpgradeKey
      break;
    case 'project3':
    # put any project-specific settings here; you can overwrite the shared settings here for this wiki
    # $wgDBprefix
    # $wgSecretKey
    # $wgUpgradeKey
      break;
    default:
      echo "WP: No valid wiki defined in 'farm-settings.php'!";
      die( 1 );
  }

# ------------------------------------------------------------------------------
# End of Settings
# ------------------------------------------------------------------------------
# Unset all $wp* variables

  require_once dirname( __FILE__ ) . '/farm-settings-wpUndefines.php';

# Ensure that cached pages are cleared, when you modify this settings file
  $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
# No closing tag for disallowing malware to include commands AFTER the closure.