CSUF LogoCSUF Site Navigation

F14 Apache/MySQL/PHP Services & Applications MediaWiki

Department of Electrical and Computer Engineering
Associate Professor Gregory R. Kriehn
F14 MediaWiki

"MediaWiki is a free software wiki package originally written for Wikipedia. It is now used by several other projects of the non-profit Wikimedia Foundation and by many other wikis." I use it for one of my classes, simply because I am trying to introduce new technology that students are familiar with into the classroom. In general, a wiki can be edited by anyone — however, in my case, I only want the wiki to be edited by my students. To circumvent this problem, many Wiki's are setup so that you can only edit a page if you have logged in. Even so, this still does not preclude an unknown person from registering, logging in, and editing the pages. As a result, I setup my Wiki to include security contexts and groups, meaning that if a user does not have the proper permissions to edit the page, the page cannot be edited. Period.

Installation of MediaWiki requires first heading getting Apache, PHP, and MySQL running. I also find it useful to have phpMyAdmin installed as well. See the appropriate pages if you need help. I also strongly recommend reading over the Installation Guide on MediaWiki's web site.

Before we install MediaWiki, we also need to install php-pecl-apc and php-devel, which can be used to increase the performance of PHP scripts by caching them in their compiled state.  Install it using yum:

~> sudo yum install php-pecl-apc php-devel
Press 'y' when prompted to install the program and any dependencies.  Then restart httpd:
~> sudo service httpd restart
You should see the daemon successfully stop and restart:
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
Assuming that you have the appropriate software installed and configured, install MediaWiki and a couple of other packages with yum:
~> sudo yum install mediawiki mediawiki-math LabPlot
MediaWiki is installed into /usr/share/mediawiki, with additional files in /var/www/wiki. Before we can run the installation script, create a softlink into /var/www/html:
~> sudo ln -s /var/www/wiki /var/www/html/mediawiki
Then create a soft link for the skins and extensions, and make a directory for the logo:
~> sudo ln -s /usr/share/mediawiki/skins /var/www/html/mediawiki/.
~> sudo ln -s /usr/share/mediawiki/extensions /var/www/html/mediawiki/.
~> sudo mkdir /var/www/html/logo
Next change the ownership of the installed package:
~> sudo chown -R apache.apache /usr/share/mediawiki
~> sudo chown -R apache.apache /var/www/wiki
In this case, we want Apache to have control over the directory so that we can upload files to the Wiki. Next, open up Firefox and go to:
Click on the set up the wiki link. If everything is setup properly, you should see a green bullet point that says "Environment checked.  You can install MediaWiki". Scroll down to Wiki name and type the Wiki name for your site. My Wiki name is "Professor Kriehn". Verify the contact e-mail address, the language, and click on the appropriate copyright license that you want to use. Choose an Admin username (in this case, I have changed "WikiSysop" to another username), and type in the Password for your Admin user. Since php-pecl-apc should be installed, click on APC under Shared memory caching. After this, click on the appropriate e-mail authentication options.

Under Database config, click on the MySQL button. The Database host is "localhost", and choose and appropriate Database name (in this case, I have changed it to "mediawiki"). Pick an appropriate DB username ("wikiuser" is fine), and choose a DB password. Since we have not created the database ahead of time, click on the User superuser account option, and type in the superuser password. Finally, type "mw_" for the Database table prefix. Then click Install MediaWiki.

After MediaWiki installs, you should see another green bullet point that says "Installation successful!" We now need to move the config/LocalSettings.php file to the parent directory:

~> sudo mv /var/www/html/mediawiki/config/LocalSettings.php /var/www/html/mediawiki/.
While we are at it, we might as well make a backup of the LocalSettings.php file (we are going to be editing it extensively):
~> cd /var/www/html/mediawiki
~> sudo cp LocalSettings.php LocalSettings.php.bak
Finally, correct the write permissions on the config directory:
~> sudo chmod go-w /var/www/html/config
With this done, look again at the last line, indicating that installation was successful. Notice that when the LocalSettings.php file is moved from the config directory, you can click on the "this link" to go to your Wiki. Do so now.

Customizing the Wiki

Next, open up the LocalSettings.php file in a text editor. We are going to customize things like the logo up in the top left corner of the Wiki, create a re-direct for the Wiki so that it no longer displays "index.php" in the web address, along with a number of other changes. If you want to understand what each of the configuration options does, go to:


and read about the different Configuration settings.

The first thing we will configure is allow for users to upload files to the Wiki. Perform a search for $wgEnableUploads. Change the setting from "false" to "true" so that the line reads:

$wgEnableUploads       = true;
Scroll down a few lines, to the $wgImageMagickConvertCommand option. Under it, add the following lines:
$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'tif', 'tiff', 'txt', 'doc', 'pdf', 'xls');
$wgMimeDetectorCommand = "file -bi";
The first line restricts what kinds of files are allowed to be uploaded to the Wiki, and the second line performs MIME detection so that the Wiki knows how to handle various file types. If you want to allow other extensions, add them in the $wgFileExtenstions setting.

Scroll down a few lines and uncomment the $wgHashedUploadDirectory option to upload figures under safe mode:

$wgHashedUploadDirectory = false;
Scroll down a few lines and change the $wgUseTeX option:
$wgUseTex = true;
Next, scroll down to the very bottom of the LocalSettings.php file. Add the following:
# User Defined Settings
The first setting that we are going to define is the location of the logo in the upper left corner of the screen. Add the following lines:
# Set default skin directory and logo path
$wgStylePath        = "$wgScriptPath/skins";
$wgStyleDirectory   = "$IP/skins";
$wgLogo             = "$wgScriptPath/logo/[figure].[ext]";
Notice that the Wiki is going to look for the logo in /var/www/html/mediawiki/logo/. Copy the figure that you want to use there.
~> sudo cp <image location> /var/www/html/mediawiki/logo/.
Let's also fix the timezone:
#Set Default Timezone
$wgLocaltimezone = "America/Los_Angeles";

#Calculate the timezone offset with UTC
$oldtz = getenv("TZ");
$wgLocalTZoffset = date("Z") / 60 + date("I") * 60;
Assuming that you do not live in the Pacific Time Zone, you can check for the proper value of $wgLocaltimezone at the Time Zone Descriptions link.

To restrict new user creation and anonymous editing, add:

# Restrict new user creation
$wgGroupPermissions['*']['createaccount'] = false;

# Restrict anonymous editing
$wgGroupPermissions['*']['edit'] = false;
Next, we are going to create a redirect from mediawiki to wiki, so that we can use short URLs and remove "index.php" from the web address. The first step in this process involves using the $wgArticlePath option. Add the following lines:
# Redirect path
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;
Save and exit. This forces MediaWiki to look in the /var/www/html/wiki directory for the article files, even though it does not exist. But this can be done by merely creating an alias from the nonexistent /wiki directory to the /mediawiki directory, which can be done through .htaccess.

Open the /var/www/html/.htaccess file. Add the following:

# Mediawiki Rewrite Rules
# Rewrite /mediawiki to /wiki
RewriteRule ^wiki/(.*)$ /mediawiki/index.php?title=$1 [PT,L,QSA]
RewriteRule ^wiki/*$ /mediawiki/index.php [L,QSA]
# Rewrite /mediawiki to /
# RewriteRule ^/*$ /mediawiki/index.php [L,QSA]
Only uncomment the last line if you want to redirect your base web page to the Wiki. Save and exit. We have now created a redirect that points back to the mediawiki directory, including the index.php file. If you go to http://[host].[domain].[name]/mediawiki/, instead of seeing the following address:
you will now see
Much nicer.

Integrating phpBB's User Table with MediaWiki

If you are going to use phpBB for a forum board, there is a nice little extension that integrates phpBB's user table with MediaWiki, and subsequently disallows the creation of new accounts in MediaWiki as well. A user then must use his phpBB username and password to login to edit the wiki. I find it to be extremely useful.

The instructions can be found at:


Upgrading MediaWiki

To upgrade MediaWiki, install the new version of MediaWiki. The installation script should automatically preserve tables in the database, and make changes to the tables wherever necessary.

Make the appropriate changes to the LocalSettings.php file. The upgrade should now be complete.