Installing MediaWiki

From Devpit
(Redirected from Installing Mediawiki)
Jump to: navigation, search

Basic Installation

The easiest way to install is to just untar their source to a subdirectory of your document root, visit the page with a web browser, and let it tell you what to do. Installing it in a subdirectory is usually preferable so you can make nice URLs more easily (see below). The document root itself should be empty, except for the subdirectory (I use /mediawiki) and perhaps a few files normally found in a document root like robots.txt and .htaccess.

It is very helpful to follow these links before you install mediawiki:

Dependencies

  • Install Apache. Apache 1 works fine. I've heard Apache 2 works, but never tried it.
  • Install MySQL. Decide on a database name to dedicate to Mediawiki, but let Mediawiki's installer create it.
  • Install PHP and tell Apache to load mod_php. Enable execution for Mediawiki's directories if necessary. Also install the following PHP modules. This list is for FreeBSD's Ports Collection. If you install from another port collection or directly from PHP's distribution, some of these may be included in the core PHP package.
    • php5-mysql
    • php5-pcre
    • php5-session
    • php5-simplexml
    • php5-spl
    • php5-xml
    • php5-zlib
  • Restart Apache after installing the PHP modules. mod_php will not pick up new modules until you restart Apache!

Tips

  • To make upgrading easier:
    • Save your original LocalSettings.php immediately after installing, and keep your changes diff-friendly. When you upgrade, you must run the installation script again to upgrade your database and config file. This way, after upgrading, you can easily merge in the changes you made to LocalSettings.php.
    • From the mediawiki directory, consider doing this: mv images ../wiki-images; ln -s ../wiki-images images
    • Read http://www.mediawiki.org/wiki/Important_Release_Notes before every upgrade.
  • Never never never install mediawiki directly under the document root. Install it under $DOCROOT/mediawiki or something, then follow the directions below for pretty URLs. Some instructions on pretty URLs say to install directly under the document root. That is error-prone and complex.
  • Read all the sections below. Some have important considerations and good suggestions.

Robots.txt

Adding a robots.txt file is a very good idea. Good contents to start with is:

User-agent: *
Disallow: /mediawiki/
Disallow: /trap/
Disallow: /wiki/Special:Random
Disallow: /wiki/Special%3ARandom
Disallow: /wiki/Special:Search
Disallow: /wiki/Special%3ASearch
Crawl-delay: 1

The goal is to tell robots not to index your entire wiki, since robots will otherwise create a lot of unnecessary traffic. Also, indexing non-article pages is pretty pointless.

Also consider looking at Wikipedia's robots.txt for more ideas.

Making your logo an image in the wiki

Upload your logo as Wiki.png, then set this in Localsettings.php:

$wgLogo = "$wgUploadPath/b/bc/Wiki.png";

Controlling users

Preventing anonymous editing

Add this to LocalSettings.php (requires 1.5.1)

$wgGroupPermissions['*']['edit'] = false;

Preventing anonymous reading

Add this to LocalSettings.php (requires 1.5.1)

$wgGroupPermissions['*']['read'] = false;

Allowing only admins to create accounts

Add this to LocalSettings.php (requires 1.5.1)

$wgGroupPermissions['*']['createaccount'] = false;

Requiring approval of new accounts

This will allow people to create accounts, but the accounts will not let them do anything until you "approve" them by adding them to the "approved" group in the User Rights Management tool (Special:Userrights).

# 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.

# Implicit group for all visitors
$wgGroupPermissions['*']['createaccount'] = true;
$wgGroupPermissions['*']['read'] = true;
$wgGroupPermissions['*']['edit'] = false;
$wgGroupPermissions['*']['createpage'] = false;
$wgGroupPermissions['*']['createtalk'] = false;

# Implicit group for all logged-in accounts
$wgGroupPermissions['user']['move'] = false;
$wgGroupPermissions['user']['read'] = false;
$wgGroupPermissions['user']['edit'] = false;
$wgGroupPermissions['user']['createpage'] = false;
$wgGroupPermissions['user']['createtalk'] = false;
$wgGroupPermissions['user']['upload'] = false;
$wgGroupPermissions['user']['reupload'] = false;
$wgGroupPermissions['user']['reupload-shared'] = false;
$wgGroupPermissions['user']['minoredit'] = false;

# Approved accounts
$wgGroupPermissions['approved']['move'] = true;
$wgGroupPermissions['approved']['read'] = true;
$wgGroupPermissions['approved']['edit'] = true;
$wgGroupPermissions['approved']['createpage'] = true;
$wgGroupPermissions['approved']['createtalk'] = true;
$wgGroupPermissions['approved']['upload'] = true;
$wgGroupPermissions['approved']['reupload'] = true;
$wgGroupPermissions['approved']['reupload-shared'] = true;
$wgGroupPermissions['approved']['minoredit'] = true;

# Sysops
$wgGroupPermissions['sysop']['move'] = true;
$wgGroupPermissions['sysop']['read'] = true;
$wgGroupPermissions['sysop']['edit'] = true;
$wgGroupPermissions['sysop']['createpage'] = true;
$wgGroupPermissions['sysop']['createtalk'] = true;
$wgGroupPermissions['sysop']['upload'] = true;
$wgGroupPermissions['sysop']['reupload'] = true;
$wgGroupPermissions['sysop']['reupload-shared'] = true;
$wgGroupPermissions['sysop']['minoredit'] = true;

How to make nice wiki URLs

There are a few ways to make nice URLs. One way puts documents under a virtual subdirectory, another puts documents directly under your document-root. These two cases assume you installed Mediawiki under /mediawiki in your document-root as described above. The third case assumes you have installed Mediawiki under a 'wiki/' subdirectory in your document-root.

Make URLs look like http://server-name/Main_Page

If you have a dedicated virtual-host for your wiki, and if you will never want to put any other content under that virtual-host, you can make your articles appear to be in the root directory with the instructions below. This is nicer, for example, if you want to set up a virtual-host called "wiki" under another domain name.

  • In the <VirtualHost> section of httpd.conf, add the following:
RewriteEngine on

# Don't rewrite requests for files that really exist or should return 404.
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteCond %{REQUEST_URI} !^/robots.txt
RewriteCond %{REQUEST_URI} !^/mediawiki/

# Rewrite http://wiki/article -- this is the main rule
RewriteRule ^/(.*)$ /mediawiki/index.php/$1 [L,QSA]
  • Edit LocalSettings.php, and change these parameters:
$wgArticlePath = "/$1";

Make URLs look like http://server-name/wiki/Main_Page

Making documents appear in a virtual subdirectory is slightly easier, and is usually preferred so you can put other content on the same host:

  • In the <VirtualHost> section of httpd.conf, add the following:
Alias /wiki /http/devpit.org/mediawiki/index.php
  • Edit LocalSettings.php, and change these parameters:
$wgArticlePath = "/wiki/$1";

Hosts that are restricted to PHP CGI, and .htaccess files (URLS Like: http://server-name/wiki/Main_Page)

Assuming you are installing on a shared host with restrictive access, and you have the wiki installed in a subdirectory 'wiki/' off of your document root.

  • Create a .htaccess file in the 'wiki/' subdirectory including the following:
Options +FollowSymLinks

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wiki/index.php?title=$1 [L,QSA]
  • Edit the LocalSettings.php, and change the following value:
$wgArticlePath = "/wiki/$1"   (Should have been "$wgScript?title=$1")

This will let the main article URLs be nice, however some URLs will still be not so pleasant.

See Also