Sunday, March 2, 2008

How to install MediaWiki

To create a MediaWiki site accessible at follow the instructions below
>>>http://www.mediawiki.org/wiki/Download_from_SVN#Download

Download the MediaWiki software from the>>
http://www.mediawiki.org/wiki/Download_from_SVN#Download

2>>Decide what the URL to your wiki will be. For this example we'll use a generic name that you should alter to your liking.

e.g. http://www.cs.nyu.edu/~USERNAME/PROJECT_NAME/wiki/

Create all the necessary directories in your ~/public_html folder that correspond to the path to your wiki, except for the last directory in the URL

e.g. mkdir -p ~/public_html/PROJECT_NAME

Then upload the MediaWiki software to the new folder created. For example, I uploaded mediawiki-1.8.2.tar.gz to

~/public_html/PROJECT_NAME/

3>Change to the directory into which you uploaded the mediawiki software. Run the following two commands (with the filename of the software you uploaded):

gunzip mediawiki-1.8.2.tar.gz

tar -xpf mediawiki-1.8.2.tar

This will create a directory called mediawiki-1.8.2 (depending on the version) containing all the MediaWiki files. Since this directory will be part of the URL, rename it to the last folder in your wiki URL. In our case we renamed it wiki (e.g. mv mediawiki-1.8.2 wiki ). At this point all the MediaWiki software is located at

~/public_html/PROJECT_NAME/wiki


4>Now that your wiki software’s in the right place, you need to create a MySQL database. For this, see our instructions on

--------------------------------
To create a MySQL database and access it from the CIMS network, follow the instructions below (mostly borrowed from Michael Schidlowsky):

1. Login to access.cims.nyu.edu

ssh access.cims.nyu.edu

2. Decide on a data directory for you MySQL database. This should NOT be in your public_html directory. I recommend creating a directory in your home folder just for this purpose, something like

~/data/mysql

3. Connect to one of the courses machines (courses1, courses2, or courses3). This is where you should run the mysql process (mysql will not run on the access machines). Since the courses machine are not publicly accessible, you will have to ssh to them from the access machines. From the UNIX prompt, just execute:

ssh courses1

4. Now issue the following command to create your database:

/usr/local/pkg/mysql/bin/mysql_install_db \ --datadir=/PATH/TO/DATA_DIR

An example might be:

/usr/local/pkg/mysql/bin/mysqld_install_db \ --datadir=/home/YOUR_USERNAME/data/mysql

5. Pick a port number between 10000 and 65535 for your MySQL server and make sure you remember it. For this example we'll use 25000. Start the MySQL database using this command (don't forget to use the ampersand so that the process runs in the background), also make sure that someone isn't already using this port

/usr/local/pkg/mysql/bin/mysqld_safe --port25000 \ --datadir=/home/YOUR_USERNAME/data/mysql &

You can check if your process is running by issuing this command:

ps -ef | grep YOUR_USERNAME

You can check if other MySQL processes are using this port by issuing this command:

ps -ef | grep port

6. Come up with a root password for the MySQL database and use the following command to set it (we'll use the password foobar):

/usr/local/pkg/mysql/bin/mysqladmin --port=25000 -u root password 'foobar'

7. You can now access your MySQL database from any CIMS computer using the database hostname (machine:port) courses1:25000, specifying your user name and password. Run the following command to start up the MySQL command line interface:

/usr/local/pkg/mysql/bin/mysql --hostname=courses1.cims.nyu.edu --port=25000 -u root -p

----------------------------------

5># Run the following command to start up the mysql command line interface:

/usr/local/pkg/mysql/bin/mysql --host=HOSTNAME \ --port=PORTNUMBER -u root -p

Replace HOSTNAME with the name of the computer where you are running your mysql server, and replace the PORTNUMBER with the port you are using. Then enter the root password when prompted.

Now think of a password for the wikidb user and issue the following four commands (we’ll use 'wikidb_password' for the password):

create database wikidb;

Grant all privileges on wikidb.* to 'wikidb_user'@'%' identified by 'wikidb_password';

flush privileges;

\q

Once you have extracted the wiki and created a database, the only thing left is some configuration. Luckily, MediaWiki has a nice and simple web-based installation form.

---------------------------------------
---------------------------------------
Configure MediaWiki
>

1. Visit your wiki’s homepage using a web browser. Mine could be found at http://www.cs.nyu.edu/~USERNAME/PROJECT_NAME/wiki

Now fill out the form. Pay careful attention to these fields:
* Database type: MySQL
* Database host: HOSTNAME:PORT
* Database name: wikidb
* Database username: wikidb_user
* Database password: wikidb_password
* Database table prefix: wiki_

Replace the host information with the hostname and port used in creating your database. Next replace the wikidb_password with the password you specified. Do NOT modify the superuser information or password. We want MediaWiki to use the account we created and not log in as root.
2. Once you successfully submit the form, MediaWiki will create a file in the config folder called LocalSettings.php. Copy this file to the main wiki directory. For our example this is

~/public_html/PROJECT_NAME/wiki

Securing your server

By using ACLs (Access Control Lists) you can restrict access to files and folders to specific users. Most importantly, you'll want to create an ACL for the LocalSettings.php file, since it contains a copy of the wiki database username and password. Issue the following three commands to secure this file so that only you and wwwcims can read it:

* chmod 700 LocalSettings.php
* setfacl -s u::rwx,g::---,m:rwx,o:--- LocalSettings.php
* setfacl -m user:wwwcims:r-x LocalSettings.php

Also, you'll want the images directory (the directory where file uploads are stored) to be readable and writable by yourself and by wwwcims, so execute the following four commands:

* chmod 700 images
* setfacl -s "u::rwx,g::---,m:rwx,o:---,\ d:u::rwx,d:g::---,d:m:rwx,d:o:---" images
* setfacl -m u:wwwcims:rwx images
* setfacl -m d:u:wwwcims:rwx images

MediaWiki Customizations

You now have a running MediaWiki instance. There are certain default settings that probably aren't optimal for a course wiki. Here are the changes I made with links to instructions:

* * Change the default Logo
* * Prevent new user registrations
* * Disable anonymous edits
* * Disable anonymous reads
* * Enable media uploads
* * Enable user emails
* * Set Browser bookmark icon (favicon)

Now that you've made it impossible for anonymous users to read pages on the wiki, you've also made it impossible for anyone to login or see the front page of your website. Find the $wgWhitelistRead variable in your LocalSettings.php file and make sure it lists all the pages that anonymous users should be able to see. At the very least, it should include these:

* $wgWhitelistRead = array( "Main_Page", "Special:Userlogin",
* "-", "MediaWiki:Monobook.css", "Special:Booksources",
* "Help:Contents", "Special:Confirmemail",
* "Special:Userlogout" );

You will also need to modify a file to make it possible for the email confirmation and booksources links to work properly. Find the end of the userCanRead() function in includes/Title.php and replace this

* }
* return false;
* }

with this code block:

* $names=split("/", $name);
* if(strcmp($names[0],"Special:Confirmemail")==0 &&
* count($names)==2 &&
* preg_match('/[a-f0-9]{32}/', $names[1])) {
* return true; #Confirmemail link
* }
* if(strcmp($names[0],"Special:Booksources")==0 &&
* count($names)==2) {
* return true; #Booksources link
* }
* }
* return false;
* }

Last but not least, you'll probably want to have an account for yourself that is not the WikiSysop. For your username the MediaWiki standard is to use your full name (e.g., "Some User") rather than a typical system username like someuser. (You should know that no matter what name you choose, MediaWiki will capitalize the first letter of every word, turning someuser to Someuser.)

No comments: