MultiWiki

From Traxel Wiki
Revision as of 20:40, 28 September 2023 by RobertBushman (talk | contribs) (Created page with "Category:MediaWiki Category:Website = Multi-Wiki = == Wiki farm: Practical == <pre> $wgLogos = [ '1x' => "http://wiki-static.iterativechaos.com/iterative_chaos_logo_004.png", 'icon' => "http://wiki-static.iterativechaos.com/iterative_chaos_logo_004.png", ]; $wgDBtype = "mysql"; $wgDBserver = "localhost"; $wgDBname = "iterativechaos_wiki"; $wgDBuser = "wiki_wiki"; ## Set $wgCacheDirectory to a writable directory on the web server #$wgCacheDirectory = "$IP/cac...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Multi-Wiki

Wiki farm: Practical

$wgLogos = [
	'1x' => "http://wiki-static.iterativechaos.com/iterative_chaos_logo_004.png",
	'icon' => "http://wiki-static.iterativechaos.com/iterative_chaos_logo_004.png",
];
$wgDBtype = "mysql";
$wgDBserver = "localhost";
$wgDBname = "iterativechaos_wiki";
$wgDBuser = "wiki_wiki";

## Set $wgCacheDirectory to a writable directory on the web server
#$wgCacheDirectory = "$IP/cache";
NO ENTRY FOR: $wgUploadDirectory = "$IP/images/$wgDBname";
NO ENTRY FOR: $wgUploadPath = "/w/images/$wgDBname";
## $IP is Install Path

The following steps are for running multiple wikis on same version of MediaWiki:

  1. Install the first wiki as normal. For details, see Manual:Installation guide.
  2. Enable your web server to share your MediaWiki install with all wikis. For multiple (sub)domains, you can use listen on multiple server names. For multiple subdirectories, you could use rewrite rules, aliases, or symlinks.
  3. Add code to the top of LocalSettings.php, to detect the current wiki. Note that if the argument to --wiki contains a hyphen, the argument will be split on the hyphen and the resulting two values assigned to MW_DB and MW_PREFIX, respectively. For wikis by domain name:
    $wikis = [
        'wiki.iterativechaos.com' => 'wiki',
        'mw.iterativechaos.com' => 'mediawiki',
    ];
    if ( defined( 'MW_DB' ) ) {
        // Automatically set from --wiki option to maintenance scripts
        $wikiID = MW_DB;
    } else {
        // Use MW_DB environment variable or map the domain name
        $wikiID = $_SERVER['MW_DB'] ?? $wikis[ $_SERVER['SERVER_NAME'] ?? '' ] ?? null;
        if ( !$wikiID ) {
            die( 'Unknown wiki.' );
        }
    }
    
    $wgLocalDatabases = $wgConf->wikis = array_values( $wikis );
    $wgDBname = $wikiID;
    $wgDBuser = 'mediawiki';
    
  4. Configure settings that must differ for all wikis. For example:
    $wgCacheDirectory = "/tmp/mediawiki_cache/$wgDBname";
    $wgUploadDirectory = "$IP/images/$wgDBname";
    $wgUploadPath = "/w/images/$wgDBname";
    
  5. Configure per-wiki overrides. This should include at least Template:Phpi and Template:Phpi.
    $wgConf->settings = [
        'wgServer' => [
            'examplewiki' => 'https://example.org',
            'onewiki' => 'https://one.example.org',
        ],
        'wgArticlePath' => [
            'default' => '/wiki',
        ],
        'wgSitename' => [
            'default' => 'Example',
            'onewiki' => 'One',
        ],
        'wgLogo' => [
            'default' => '/images/examplewiki/Example_logo.png',
        ],
        'wgLanguageCode' => [
            'default' => 'en',
            'onewiki' => 'pt',
        ],
    ];
    extract( $wgConf->getAll( $wgDBname  ) );
    
    This could be done from a separate file, e.g.:
    # LocalSettings.php
    $wgConf->settings = require __DIR__ . '/LocalSettings_overrides.php';
    
    # LocalSettings_overrides.php
    return [
        'wgServer' => ..,
        ..,
    ];
    


To create a new wiki, create its database and add its settings first, and then run php maintenance/update.php --wiki=mywiki.

Wiki farm

The following steps are for running multiple wikis on same version of MediaWiki:

  1. Install the first wiki as normal. For details, see Manual:Installation guide.
  2. Enable your web server to share your MediaWiki install with all wikis. For multiple (sub)domains, you can use listen on multiple server names. For multiple subdirectories, you could use rewrite rules, aliases, or symlinks.
  3. Add code to the top of LocalSettings.php, to detect the current wiki. Note that if the argument to --wiki contains a hyphen, the argument will be split on the hyphen and the resulting two values assigned to MW_DB and MW_PREFIX, respectively. For wikis by domain name:
    $wikis = [
        'example.org' => 'examplewiki',
        'one.example.org' => 'onewiki',
    ];
    if ( defined( 'MW_DB' ) ) {
        // Automatically set from --wiki option to maintenance scripts
        $wikiID = MW_DB;
    } else {
        // Use MW_DB environment variable or map the domain name
        $wikiID = $_SERVER['MW_DB'] ?? $wikis[ $_SERVER['SERVER_NAME'] ?? '' ] ?? null;
        if ( !$wikiID ) {
            die( 'Unknown wiki.' );
        }
    }
    
    $wgLocalDatabases = $wgConf->wikis = array_values( $wikis );
    $wgDBname = $wikiID;
    $wgDBuser = 'mediawiki';
    
  4. Configure settings that must differ for all wikis. For example:
    $wgCacheDirectory = "/tmp/mediawiki_cache/$wgDBname";
    $wgUploadDirectory = "$IP/images/$wgDBname";
    $wgUploadPath = "/w/images/$wgDBname";
    
  5. Configure per-wiki overrides. This should include at least Template:Phpi and Template:Phpi.
    $wgConf->settings = [
        'wgServer' => [
            'examplewiki' => 'https://example.org',
            'onewiki' => 'https://one.example.org',
        ],
        'wgArticlePath' => [
            'default' => '/wiki',
        ],
        'wgSitename' => [
            'default' => 'Example',
            'onewiki' => 'One',
        ],
        'wgLogo' => [
            'default' => '/images/examplewiki/Example_logo.png',
        ],
        'wgLanguageCode' => [
            'default' => 'en',
            'onewiki' => 'pt',
        ],
    ];
    extract( $wgConf->getAll( $wgDBname  ) );
    
    This could be done from a separate file, e.g.:
    # LocalSettings.php
    $wgConf->settings = require __DIR__ . '/LocalSettings_overrides.php';
    
    # LocalSettings_overrides.php
    return [
        'wgServer' => ..,
        ..,
    ];
    


To create a new wiki, create its database and add its settings first, and then run php maintenance/update.php --wiki=mywiki.

Separate settings files

This approach is for operating entirely independent wikis, but still sharing the same web server and MediaWiki source code.

  1. Install the first wiki as normal, via the web or CLI installer, which sets up your database and generates a LocalSettings.php file.
  1. After installation, rename the generated LocalSettings.php file to include the wiki ID (e.g. database name), like LocalSettings_mywiki.php.
  1. Repeat step one and two above for each wiki you wish to create.
  1. Create a new LocalSettings.php file that will load the correct one. As with the above wiki farm example, a --wiki argument containing a hyphen will be split on the hyphen into two values assigned to MW_DB and MW_PREFIX, respectively.
<?php
$wikis = [
    'example.org' => 'examplewiki',
    'one.example.org' => 'onewiki',
];
if ( defined( 'MW_DB' ) ) {
    // Automatically set from --wiki option to maintenance scripts
    $wikiID = MW_DB;
} else {
    // Use MW_DB environment variable or map the domain name
    $wikiID = $_SERVER['MW_DB'] ?? $wikis[ $_SERVER['SERVER_NAME'] ?? '' ] ?? null;
}

if ( $wikiID ) {
    require_once "LocalSettings_$wikiID.php";
} else {
    die( 'Unknown wiki.' );
}

// Add any settings that should apply to all wikis below this line
// -------

If your wikis are on the same domain but under different paths (e.g. example.org/wiki1, example.org/wiki2 etc.), you can use something like this:

<?php
$wikis = [
    '/example' => 'examplewiki',
    '/w_example' => 'examplewiki',
    '/one' => 'onewiki',
    '/w_one' => 'onewiki',
];
if ( defined( 'MW_DB' ) ) {
    // Automatically set from --wiki option to maintenance scripts.
    $wikiID = MW_DB;
} else {
    $path = explode( '/', $_SERVER['REQUEST_URI'] ? '', 3 )[1] ?? '';
    $wikiID = $_SERVER['MW_DB'] ?? $wikis[ $path ] ?? null;
}

if ( $wikiID ) {
    require_once "LocalSettings_$wikiID.php";
} else {
    die( 'Unknown wiki.' );
}

Note: If you use Short URL, you need to add both your $wgArticlePath and the $wgScriptPath