Mediawiki setup

From DiLab
Jump to: navigation, search

Initial setup

Doing apt-get install mediawiki is not enough. Here is what else needs to be done:

sudo apt-get install mediawiki imagemagick mediawiki-math mysql-server

Remove comment'#' and rename the mediawiki link as needed in /etc/apache2/conf.d/mediawiki.conf, e.g. in:

gksudo gedit /etc/apache2/conf.d/mediawiki.conf

... change the appropriateline in /etc/apache2/conf.d/mediawiki.conf as follows

from: # Alias /mediawiki /var/lib/mediawiki
to:   Alias /wiki /var/lib/mediawiki

Restart Apache:

 sudo /etc/init.d/apache2 restart
  • BTW, if you get the annoying "Could not reliably determine the server's fully qualified domain name" message on a fresh apache install, then you can edit /etc/apache/sites-available/default and add the ServerName. Note, your server name should be resolvable. You could add it also in /etc/hosts file and point to localhost IP.
NameVirtualHost *
ServerName myserver

Then visit the website at http://localhost/wiki (or http://localhost/mediawiki) and follow the instructions to create the databases and configure the wiki. You may want to enable SSL or be secure in some other way since you will be entering passwords.

Finally, move the LocalSettings file to a safe place so anonymous can not read it (the mediawiki mysql pass is in there!). Check the path below to match your configuration.

sudo mv /var/lib/mediawiki/config/LocalSettings.php /etc/mediawiki/LocalSettings.php
sudo chmod 600 /etc/mediawiki/LocalSettings.php
sudo rm -Rf /var/lib/mediawiki/config

Now you should be able to access the wiki at

http://localhost/wiki (or http://localhost/mediawiki)

Typical configuration options

In LocalSettings.php (possible locations: /var/lib/mediawiki/, /var/lib/mediawiki/config/, or /etc/mediawiki/)

Change your logo (picture in top-left corner):

$wgLogo = "http://urlpath/to/my/logo/picture.png";

Disable new user creation:

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

Disable editing and creating pages by anonymous users:

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

Disable reading by anonymous users, except for certain pages:

$wgGroupPermissions['*']['read'] = false;
$wgWhitelistRead =  array ( "Main Page", "Special:Userlogin");

Customize the layout.

http://meta.wikimedia.org/wiki/Layout_customization

Creating another wiki on the same webserver

  • create a new directory (say wiki2) in the document root.
  • lndir the /var/lib/mediawiki to the new directory,
cd /var/lib
sudo mkdir wiki2
cd wiki2
sudo lndir /var/lib/mediawiki
  • 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.

Recovering wiki after upgrade

This is what happened: I upgraded Ubuntu to 8.04 and all of a sudden my wiki was unreachable... Investigation showed that there is a new mediawili installed, wiping almost all of the old configuration, including the /var/lib/mediawiki-?? with links.

Luckily I had the Localhost.php with settings in the old /etc/mediawiki-?? directory that was not wiped. After investigating I found that the content of the wiki remained in the mysql database. That gave me a hope, and this is what I did:

  • recreated mysql passwords for the wikiuser and mysql-root. You can reset root password - stop mysql and start the daemon with no-
    • reset mysql root password
 sudo /etc/init.d/mysql stop
 sudo mysqld --skip-grant-tables
 mysql -u root 
 mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
 mysql> FLUSH PRIVILEGES; 
 mysql> exit
 sudo mysqladmin shutdown -u root
 sudo /etc/init.d/mysql start
    • Change mysql wikiuser password
 $ mysql -u root -p
 mysql> use mysql;
 mysql> update user set password=PASSWORD("NEWPASSWORD") where User='wikiuser';
 mysql> flush privileges;
 mysql> quit
  • created a new root directory for the wiki (actually several for several wiki's)
sudo mkdir /var/lib/wiki
  • used lndir to create links in the new directory
cd /var/lib/wiki
lndir <insert your parameters here>
  • added the following fragment to set up mediawiki with apache2: create/add this in /etc/mediawiki/apache.cnf
Alias /wiki /var/lib/wiki

#=== My wiki ===
<Directory /var/lib/wiki/>
       Options +FollowSymLinks
       AllowOverride All
       order allow,deny
       allow from all
</Directory>

# some directories must be protected
<Directory /var/lib/wiki/config>
       Options -FollowSymLinks
       AllowOverride None
</Directory>
<Directory /var/lib/wiki/upload>
       Options -FollowSymLinks
       AllowOverride None
</Directory>
  • made sure /etc/apache2/conf.d has a link to the file above (in /etc/mediawiki/apache.conf)


  • started web pointing to http://example.com/wiki and
  • set all the parameters as before, except using the new mysql passwords as appropriate.
  • compared the newly created Localsettings.php with my old (if present) and copied that into /var/lib/wiki, and set the permissions so that it could not be changed by anyone or read by anyone but the www-data (webserver).


Wiki user (Sysop?) password recovery?

Log in to mysql as root, use your wiki database, and issue the following command using your wiki prefix for the user table name. The following assumes the default option $wgPasswordSalt = true.

UPDATE user SET user_password = MD5(CONCAT(user_id, '-', MD5('yourpassword'))) WHERE user_name = 'yourusername';

More on the subject here.

Other info and links

* wikimedia meta FAQ