Setup a MediaWiki
From GLUG-BOM
You are here : Main Page > Howtos > Setup a MediaWiki
Contributions to the ILUG-Bom wiki are practically nil, so I thought I'd jumpstart it with this. Setting up a MediaWiki is pretty simple. This is not to be treated as the authoritative text on how to install MediaWiki but a record of how I did it. I had to google around quite a bit to figure out how to configure the wiki the way I wanted it. This document is designed to help you setup the basic wiki with minimum customisation and basic security. I strongly advise that you read the comprehensive official documentation (see links at the bottom of the page).
Contents |
What is a wiki?
Quoting from Wikipedia, wiki <wee-kee> <wick-ey> (according to Ward Cunningham) is a type of website that allows users to easily add and edit content and is especially suited for collaborative authoring. The term wiki also sometimes refers to the collaborative software itself (wiki engine) that facilitates the operation of such a website (see wiki software).
The most famous wiki implementation comes in the form of Wikipedia, The Free Encyclopedia.
Preparation
Prerequisites
A linux installation having Apache, MySQL & PHP. I used Fedora Core 4 for my setup, but the below steps should work on any distro. I used the stock versions that came along with Fedora Core 4 (httpd-2.0.54-10, php-5.0.4-10 & mysql-4.1.11-2).
Getting MediaWiki
You can get the latest version from the MediaWiki download page. At the time of writing this document, the version was 1.5.5.
Copying files
Untar the downloaded tarball. A directory called mediawiki-1.5.5 will be created in the current working directory. Create a directory called mediawiki (or any name that suits you) under /opt and copy all the files into /opt/mediawiki. Create a directory called wiki under the document root of your Apache installation and use the lndir command to link /opt/mediawiki to that location. This might sound odd, but it makes a lot of sense when you are trying to run multiple wiki instances on the same server. It makes upgrading to new versions of MediaWiki easier.
[veejay@neo ~]# tar -zxvf mediawiki-1.5.2.tar.gz [root@neo ~]# mkdir /opt/mediawiki [root@neo ~]# cp -rf /home/veejay/mediawiki/* /opt/mediawiki [root@neo ~]# mkdir /var/www/html/wiki [root@neo ~]# lndir /opt/mediawiki /var/www/html/wiki
Change the owner:group of the wikimedia directory to apache:apache. For the purpose of initial configuration, give everybody write access to the config directory under the document root. This is required so that during initial configuration the LocalSettings.php file can be created. The permissions are to be removed later.
[root@neo ~]# chown -R apache:apache /opt/mediawiki/* [root@neo ~]# chmod 777 /var/www/html/wiki/config
And we're done.
Configuring the wiki
Initial Configuration
Open an browser and goto http://localhost/wiki. If you are connecting to the server from a different system, replace localhost with the domain name. Mediawiki detects that it needs to be configured and provides you with the link to the configuration page. If you get an error saying Can't write config file, aborting, you have not setup the permissions correctly.
The wiki will automatically check the environment and inform you if anything is missing.
In the Site Config section of the page fillup all the required information. Brief description of each is as follows...
- Site name : Put in the name of your wiki. Eg. Test Wiki or Foo's Wiki
- Contact e-mail : Email address of the Wiki's contact person Eg. foo@domain.com
- Language : Select the language of your choice from the drop down list. Indian Languages currently supported are Bengali, Gujrati, Hindi, Malayalam, Punjabi, Tamil & Telugu.
- Copyright/license metadata : The option selected here is the default licence for documents published in the wiki. A notice indicating the same is inserted at the bottom of every page displayed. Eg.
Content is available under GNU Free Documentation License 1.2.
- Sysop account name : This section creates the wiki SysOp (the "root" user) of the wiki. The SysOp has administrative rights to the wiki and can perform tasks like page deletions, banning/unbanning users, protecting pages, etc. Enter the desired name, password and confirm password.
- Shared memory caching: Use this option to enable PHP precompiled page caching. This reduces the load on the server by serving pages from the cache if it has already been generated before. This requires Turck MMCache or eAccelerator to be installed on the server.
- E-mail, e-mail notification and authentication setup : This section enables email notification settings.
- E-mail (general): Master switch for email functions.
- User-to-user e-mail : Enables user-to-user email functions.
- E-mail notification : Enables email notifications to users who have setup their watch list.
- E-mail address authentication : Enables email address verification by sending an activation link to the email address specified during registration. Verification is also done when the user changes his/her email address in his profile.
- Database config : This section defines the MySQL database settings for the wiki.
- MySQL server : Enter localhost here. If the MySQL server is on another box, then enter IP Address/Domain name of the server here.
- Database name : Specify the name of the database, Eg. testwikidb
- DB username : Username for the database, Eg. testwikiuser
- DB password : Password for the username.
- again : Confirm password.
- Database table prefix : Specify a prefix to be used before table names in the database. This is useful to diferentiate between tables if you are running multiple wiki instances. Eg. tw_
- Database charset : Self explanatory.
- DB Root Password : Password of the MySQL database root. The password is required to create the database instance. This is blank by default in Fedora Core 4.
Check all entries for errors. If everything is fine, click Install. The install confirmation page takes a few moments to show up. The page lists all that was done in the installation process.
If the installation fails, check the error messages to see what went wrong. Fortunately, this never happened to me.
A file called LocalSettings.php will be generated in the config (/var/www/html/wiki/config) directory. Move this file to the wiki root (/var/www/html/wiki) and delete the config directory.
[root@neo ~]# mv /var/www/html/wiki/config/LocalSettings.php .. [root@neo ~]# rm -rf /var/www/html/wiki/config
Initial configuration is done! Open the browser and fire up the wiki (http://localhost/wiki).
Now comes the customisation bit.
Customisation
All customisation entries go into the LocalSettings.php file in the wiki root (/var/www/html/wiki). Add the entries to the end of the file or make changes wherever necessary.
Logo
Create a folder in the webserver document root and place your logo image there. Set $sgLogo in LocalSettings.php to the path of your logo image. 125x125 pixels is the ideal size for the image
$wgLogo = "/image/logo.png";
Security
Allowing File Uploads
File uploading is disabled by default in MediaWiki. The following steps will show you how to enable it. The images directory in the wiki root (/var/www/html/wiki/images) should be writable by the webserver owner (usually apache). Change the owner:group of the directory to apache:apache and set the permissions to 755.
[root@neo ~]# chown apache:apache /var/www/html/wiki/images [root@neo ~]# chmod 755 /var/www/html/wiki/images
The /etc/php.ini file should have file_upload set to on and you can place size restriction for the file by setting upload_max_filesize to a suitable value.
; Whether to allow HTTP file uploads. file_uploads = On ; Maximum allowed size for uploaded files. upload_max_filesize = 2M
Change $wgEnableUploads in LocalSettings.php to True. Initially I found that whenever I tried to upload an image, I got a The file is corrupt or has an incorrect extension. Please check the file and upload again. error. After a little googling, I learnt that specifying an external mime detector is a good idea.
$wgEnableUploads = true; $wgMimeDetectorCommand= "file -bi"; #use external mime detector
Enabling uploads of files other than images isn't difficult either. Add this line to your site's LocalSettings.php
$wgFileExtensions = array('png','jpg','jpeg','pdf','tgz','tar.gz');
Contents of this array decide what kind of files are allowed to be uploaded.
Disable Editing by Anonymous Users
Add the following lines to the end of LocalSettings.php to disable editing of pages by anonymous users.
# Permission keys given to users in each group. # All users are implicitly in the '*' group including anonymous visitors; # logged-in users are all implicitly in the 'user' group. These will be # combined with the permissions of all groups that a given user is listed # in in the user_groups table. # slot machines games # This replaces wgWhitelistAccount and wgWhitelistEdit of 1.4 or prior # # The following line should be commented, otherwise these settings will # throw away the settings on DefaultSettings.php (you probably don't want this). # With this line commented you will only overwrite the settings you explicitly # define here (that's what you probably want). #$wgGroupPermissions = array(); $wgGroupPermissions['*' ]['read'] = true; $wgGroupPermissions['*' ]['edit'] = false;
Disable user registrations
The ILUG-Bom wiki became the target of vandalism in the initial weeks after being launched. In light of this, I had suggested that new user registrations be disabled. Any individual willing to contribute would have to contact a SysOp for creating their accounts. (See: ILUG-BOM Wiki Editing Guidelines ) Add the below line with the code for "Disable Editing by Anonymous Users".
$wgGroupPermissions['*' ]['createaccount'] = false;
Disable Viewing by Anonymous Users
If you want only registered users to read the wiki, add the following lines to LocalSettings.php. This line defines what pages anonymous users are able to see. For the viewing the rest, log in is required.
# Pages anonymous (not-logged-in) users may see
$wgWhitelistRead = array ("Main Page", "Special:Userlogin", "Wikipedia:Help");
$wgGroupPermissions['*' ]['read'] = false;
Note that the read=false group permission conflicts with the one used to disable editing by anonymous users. In such a case, the line which comes later in the file will be the enforced rule.
Creating a second wiki instance
To create a second wiki on the same webserver, simply create a new directory (say wiki2) in the document root. lndir the /opt/mediawiki to the new directory, assign the appropriate permissions to directories and visit the wiki (http://localhost/wiki2) for configuration. Make sure that the database name, user(?) and table prefix are different for this wiki.
External Links
MediaWiki home
Official Installation Manual
MediaWiki FAQ
Author(s)
Vivek J. Patankar <list307 at gmail dot com>
Anurag <anurag at gnuer dot org>





