How to setup a wiki outside of webserver DocumentRoot
This guide is based on Apache and MediaWiki.
Contents
Installation
Check the requirements and follow the Official Installation Guide, and this section in particular.
We assume that the installation is under a directory named w
under /home/www-data/example.com
,
depending on your VirtualHost config you may need a line like the following
in order to access the installation page.
Alias /w "/home/www-data/example.com/w"
NOTE: after the installation remember to set 600 permissions to LocalSettings.php
Clean URLs
In order to have Clean URLs follow the Official Guide. We use the recommended setup.
However, in our case there are some little differences, we do want indeed the
wiki to be accessible via /wiki
, but the installation directory
/w
will be outside our VirtualHost
DocumentRoot
, since the
latter is used by the main site which is a Drupal installation and we don't
want to put MediaWiki files inside the Drupal installation.
In our case the DocumentRoot
for server example.com is /home/www-data/example.com/drupal
, we need to tell explicitly where the wiki installation files are, here's the interesting snippet of the VirtualHost config:
Alias /wiki "/home/www-data/example.com/w/index.php" # Needed because our mediawiki installation is outside of DocumentRoot Alias /w "/home/www-data/example.com/w" <Directory /home/www-data/example.com/w> Options -Indexes +FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory>
Now only paths which have /w
and /wiki
prefixes are
handled by MediaWiki, everything else is left to Drupal.
Notes:
- the MediaWiki installation can be everywhere on the filesystem, provided that its files are readable by the web server.
-
the robots.txt file have still to be in the
DocumentRoot
Customization
- Edit LocalSettings.php to add custom logo (135x135):
$wgLogo = "$wgScriptPath/logo.png";
and a favicon:
$wgFavicon = "$wgScriptPath/favicon.ico";
Obviously these statements must be after the declaration of
$wgScriptPath
-
Optionally you can restrict editing pages to logged users (I won't do that for now here, let's see how much spammers like me first):
$wgGroupPermissions['*']['edit'] = false; $wgShowIPinHeader = false;
Other tips can be found here.
- If you use the default Monobook theme, you can add some custom
CSS code go to this page:
Mediawiki:Monobook.css
as suggested here and append your rules. NOTE: you need to log in with the SysOp user or equivalent. - Create content for the Privacy policy, About and Disclaimers pages, you find the links of the bottom of every page.
- Multilingual support? Described here, we don't do that here, let's keep it simple.
Updating MediaWiki
The full guide can be found here, briefly we need to:
-
Configure the
AdminSetting
script:cd /home/www-data/example.com/w cp AdminSettings.sample AdminSettings.php $EDITOR AdminSettings.php
-
Now that we have set up
$wgDBadminuser
and$wgDBadminpassword
, we can run the upgrade script:cd maintenance/ php update.php --aconf ../AdminSettings.php
Extensions
You can add extensions in the extensions/
dir, some useful ones:
Anti-spam measures
If you want to prevent page editing from well known spammers you can use the method described in the Combating Spam page on the MediaWiki site.
I use a variation of the suggested script because I like sed more in this case:
#!/bin/sh IP_LIST=http://www.stopforumspam.com/downloads/bannedips.zip wget -N $IP_LIST unzip -u bannedips.zip echo "<?php" > bannedips.php echo \$"wgProxyList = array(" >> bannedips.php echo -n "'" >> bannedips.php cat bannedips.csv | sed -e "s/,/',\n'/g" >> bannedips.php echo "');" >> bannedips.php echo "?>" >> bannedips.php rm bannedips.csv rm bannedips.zip*
and I update it daily via cron, here's the crontab entry:
@daily cd /home/www-data/example.com/w && ./update_banned_openproxy_list.sh
You can also use DNSBL filtering adding these lines to LocalSettings.php
:
$wgEnableSorbs = true; $wgSorbsURL = 'zen.spamhaus.org.';