User:Alvaro Ortiz-Troncoso/Draft Create a new mediawiki instance

From Biowikifarm Metawiki
Jump to: navigation, search

As more wikis are needed it would be nice to have a scriptable method to create new wiki instances. This page documents creating a wiki by hand in such a way that it would be feasable to automatize the steps in a script.

See also: Create_a_new_mediawiki_instance (using a template and a database dump).

Create a new wiki directory

Create a new directory in /var/www for the wiki installation.

mkdir /var/www/v-xxx/new_wiki_name
cd /var/www/v-xxx/new_wiki_name

Create the wiki database

Link the maintenance directory from the common wiki installation

ln -s /usr/share/mediawiki26wmf/maintenance maintenance

Run the installer php ./maintenance/install.php with the following options

Database user
Database user password
Path to where the LocalSettings.php shall be stored (without 'LocalSettings.php')
Name of the database to be created
Wiki administrator password
Path to the wiki files, relative to /var/www


  • <name>: The name of the wiki
  • <admin>: The username of the wiki administrator (WikiSysop)
php ./maintenance/install.php --dbuser <dbuser> --dbpass <dbpass> --confpath <confpath> --dbname <dbname> --pass <pass> --scriptpath <scriptpath> <name> <admin>


  • Don't worry if the installation script fails to create the smw_ tables, they can be created by the update script.
  • If the script complains about existing LocalSettings file, then it is probably looking in /usr/share/mediawiki26wmf. Rename the LocalSettings file and rerun to create database tables, then move the Localsettings file back to where it was. The LocalSettings File will not be created. You will have to copy a LocalSettings file from another wiki and adapt it.

Grant user rights

Once the database has been created by the maintenance script, the db wiki user has to get these rights (e.g. using PHPMyAdmin):

-- DROP , INDEX ,CREATE TEMPORARY TABLES seems necessary only for Semantic MediaWiki Wikis or maybe only Semantic Forms

Link to common files and directories

Define the path to the base Mediawiki installation (scope is restricted to this shell, and to this user, so 'sudo su' first if you must)


(Soft-) Link folders and files to the common mediawiki installation:

# Main web entry point for MediaWiki
ln -s $MWPATH/index.php index.php
ln -s $MWPATH/index.php5 index.php5
# Stub file for compatibility with older versions
ln -s $MWPATH/wiki.phtml wiki.phtml

# Entry point for API queries
ln -s $MWPATH/api.php api.php 
ln -s $MWPATH/api.php5 api5.php

# PHP script to be used as 404 handler to create and stream out a
# not yet existing image thumbnail.
ln -s $MWPATH/thumb_handler.php5 thumb_handler.php5
# PHP script to stream out an image thumbnail.
ln -s $MWPATH/thumb.php thumb.php
ln -s $MWPATH/thumb.php5 thumb.php5
# Image authorisation script
ln -s $MWPATH/img_auth.php img_auth.php
ln -s $MWPATH/img_auth.php5 img_auth.php5

# Entry point for the resource loader.
ln -s $MWPATH/load.php load.php
ln -s $MWPATH/load.php5 load.php5

# Entry point for the search API
ln -s $MWPATH/opensearch_desc.php5 opensearch_desc.php5

# Script that redirects to the article passed in the "wpDropdown" parameter.
# This is used by the nostalgia skin for the special pages drop-down
ln -s $MWPATH/redirect.php redirect.php
ln -s $MWPATH/redirect.php5 redirect.php5
ln -s $MWPATH/redirect.phtml redirect.phtml

# Directoriess requiered by Mediawiki
ln -s $MWPATH/bin bin
ln -s $MWPATH/docs docs
ln -s $MWPATH/extensions extensions
ln -s $MWPATH/includes includes
ln -s $MWPATH/languages languages
ln -s $MWPATH/maintenance maintenance
ln -s $MWPATH/resources resources
ln -s $MWPATH/serialized serialized
ln -s $MWPATH/skins skins
# Additional softlinks: 
ln -s $MWPATH/autoload.php autoload.php
ln -s $MWPATH/Gemfile Gemfile
ln -s $MWPATH/Gemfile.lock Gemfile.lock
ln -s $MWPATH/Gruntfile.js Gruntfile.js
ln -s $MWPATH/package.json package.json
# Link to the vendor directory 
ln -s $MWPATH/vendor vendor
# Required for composer
ln -s $MWPATH/composer.json composer.json
ln -s $MWPATH/composer.lock composer.lock

Create local directories

Make sure the right directotry is used

cd /var/www/<new_wiki>

Create the cache directory and make it writable for the web server

mkdir cache
chown www-data:www-data cache

If media are stored locally, create the media directory and make it writable for the web server

mkdir media
chown www-data:www-data media

Edit local configuration file

Biowikifarm uses a shared configuration which is in stored in MediaWikiCommonSettings.php directly in the www-root. To create configuration for an individual wiki on biowikifarm, you need to edit the file LocalSettings.php in the wiki's directory. For a a minmalistic configuration, set these variables in LocalSettings.php:

Name that appears on the wiki pages, e.g. "My Wiki"
URL base path to folder containing the wiki; relative to /var/www. Defaults for all runtime URL paths are based off of this, e.g. "mywiki"
Virtual path. This directory MUST be different from the one used in $wgScriptPath, e.g. "/mywiki/$1"
Name of the database where this wiki stores its contents, e.g. "mywiki"
Language to use for the interface, e.g. "en"
A 64-character random string, e.g. the output of "openssl rand -hex 32"
# Protect against web entry
if ( !defined( 'MEDIAWIKI' ) ) {

$IP = dirname( __FILE__ );

$wgSitename = "";
$wgScriptPath = ""; 
$wgArticlePath = "";  
$wgUsePathInfo = true;
$wgDBname = "";
$wgLanguageCode = "";
$wgSecretKey = "";

$wgDefaultSkin = 'vector';


There are of course many more available settings.

Update database tables

You'll need to run the update script, to ensure that tables required in LocalSettings are available:

cd /var/www/v-XXX/wiki_name;   sudo -u www-data php ./maintenance/update.php  --quick --conf ./LocalSettings.php

Edit Web server settings

There are two files where you can place your server configuration.

No own domain name

If your server has no own domain name, you can place the configuration in

Own domain name

If you have your own domain name, then please make a new configuration in
and link it from
Assuming you wiki is called "<wikiname>" and is located at
# === Wiki: path=mywiki, ShortURL=mywiki ===
 location /<wikiname> {
   try_files $uri @do_<wikiname>_wikipage;
 location @do_<wikiname>_wikipage {
   rewrite "^/<wikiname>$" /<wikiname>/ redirect;
   rewrite "^/<wikiname>/([^?]*)(?:\?(.*))?$" /<wikiname>/index.php?title=$1&$args last;
 location /<wikiname>/media {
   location ~ ^/<wikiname>/media/thumb/(archive/)?[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ {
     try_files $uri @thumb_<wikiname>;
 location @thumb_<wikiname> {
   rewrite ^/<wikiname>/media/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /<wikipath>/thumb.php?f=$1&wi$
   rewrite ^/<wikiname>/media/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /<wikipath>/thumb.php$
   include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME  $document_root/<wikipath>/thumb.php; fastcgi$

Test the configuration

nginx -t

Then restart nginx

/usr/sbin/apache2ctl -k graceful && sudo service nginx restart && sudo service php5-fpm restart

Testing the installation

You should now be able to see your wiki at: http://servername/wikiname/index.php?title=Main_Page


If it doesn't work, you can enable logging:

In LocalSettings.php, add:

$wgDebugLogFile = "$IP/debug.log";

In the wiki's directory, do

touch debug.log
chown www-data:www-data debug.log

To see log output, do

tail -n300 -f debug.log

Please remember to disable logging once you have solved the problem.