Create a Wikifarm
On Wikifarms
What is a Wikifarm?
Wikifarm and the verb Wikifarming refer to the setup and operation of multiple wikis on a single server. This could be because on a single website you want to run multiple wikis (e.g. http://www.saruman.biz/linuxwiki and http://www.saruman.biz/bsdwiki). Or it could be because you're running multiple websites on a single server (each behind its own IP, or all on the same IP number using virtual hosts), and more than one of these websites needs to have its own wiki.
Types of Wikifarms
There are multiple ways to set up a wikifarm; what is the most suitable way for you depends on how you want to use the farm. We can roughly distinguish the following type of farms:
- Multiple wikis, each running their own code and their own database. This is simple to set up when you install the Wiki code base from source - funny enough, under Debian it's not easy. Also, it's not a recommendable solution from the perspective of maintenance: each wiki must be updated separately when e.g. a security patch is issued for the wiki software.
- Multiple wikis, running on a shared code base, but each with their own database. This is a good solution for multiple wikis for multiple websites.
- Multiple wikis, running on a shared code base, and on a shared database. This could be a good solution for multiple wikis for a single website, because a user can register on one wiki, and automatically have the same account in the other database as well.
The standard Debian MediaWiki structure
Recreating (moving over) your first MediaWiki instance
We'll assume you've followed the other tips in this wiki. Most notably, you've taken all steps described in the article on "how to Place MediaWiki inside a Virtual Host". The steps are simple
Move the Wiki configuration within /etc
Your Wiki config file will be /etc/mediawiki/LocalSettings.php, and the settings for Apache2 will be in /etc/mediawiki/apache.conf. We'll create a subdirectory under /etc/mediawiki that hosts the configuration of your Wiki. Suppose we name the subdirectory after the Wiki we're handling, in this example the SaruWiki. Furthermore, suppose that you also have an AdminSettings.php file. If you don't: no worries! Just skip the steps involved with that file!
cd /etc/mediawiki mkdir SaruWiki mv LocalSettings.php SaruWiki mv AdminSettings.php SaruWiki mv apache.conf Saruwiki
Note: make sure that after moving the files, the owner and permissions are the same. Moving a file while you are root has the effect of changing ownership to root. LocalSettings.php must be owned by user:group www-data:www-data in order for Apache2 to be able to read the file. The AdminSettings.php file, if it exists, must be owned by root:root and NOT be readable by world (permissions 600) because it should contain the MySQL "root" username and password, with which maintenance scripts can perform their tasks if you instruct them to (while you are root, of course). To keep the Wiki running, we're going to need to tell Apache2 where the two files went to. In this case:
- change the path to apache.conf in the Include statement in the site declaration (e.g. in /etc/apache2/sites-available/000-saruman.biz, change the Include line to
Include /etc/mediawiki/SaruWiki/apache.conf
- change the symlink in /var/lib/mediawiki that points to LocalSettings.php; and if you have one, change the AdminSettings.php symlink as well:
cd /var/lib/mediawiki unlink LocalSettings.php ln -s /etc/mediawiki/SaruWiki/LocalSettings.php unlink AdminSettings.php ln -s /etc/mediawiki/SaruWiki/AdminSettings.php
If you now restart Apache2, your Wiki will still work - but the two primary configuration files have moved over to a dedicated spot.
Move the Wiki website
As you can see from the MediaWiki directory structure, the code that is actually served in the webserver is in two separate trees: by default the webserver thinks the full tree is in /var/lib/mediawiki, but a large part of what you find in that spot is actually symlinked to files and directories in /usr/share/mediawiki. Actually, the tree /usr/share/mediawiki can be thought of as a source code library, and /var/lib/mediawiki as the instance that we're actually serving. Since an instance needs both source code and some files of its own, we find that /var/lib/mediawiki contains both links to that source code, as well as actual files and directories.
So what we now need to do, is to tell the webserver that the full tree can be served from elsewhere, and in that spot "elsewhere" create symlinks to the right spots. Let's begin with the latter.
Let's assume we wish to move our default Wiki instance to /data/wikifarm/SaruWiki. Other instances could then run under /data/wikifarm/<instancename>. We now first create the links to the /usr/share/mediawiki files as we see them in the /var/lib/mediawiki instance:
cd /data/wikifarm/SaruWiki for i in /usr/share/mediawiki/*.php; do > ln -s $i > done unlink AdminSettings.php unlink LocalSettings.php ln -s /usr/share/mediawiki/*.phtml ln -s /usr/share/mediawiki/install-utils.inc ln -s /usr/share/mediawiki/includes ln -s /usr/share/mediawiki/languages ln -s /usr/share/mediawiki/maintenance ln -s /usr/share/mediawiki/skins
Next, we create the directories that contain the instance-specific files, i.e. the files that belong to this one member of the Wiki farm. This includes the images directory, where users of this wiki instance can upload their images.
mkdir images chown www-data:www-data images mkdir config chown www-data:www-data config cp -P /var/lib/mediawiki/config/* .