Apache configuration

<- MediaWiki architecture

Apache webserver is the recommended web server for use with MediaWiki. Other servers may work, but who knows.

PHP
You'll want to set up PHP as an Apache module, or likely you won't get anything running. ;)

Be sure to enable mod_php in the directory that contains the MediaWiki scripts, but you should also remember to disable it in the upload directory, so that visitors don't have the ability to execute arbitrary code on your system!

mod_rewrite
(Is this old? mediawiki 1.2.5 does not have a wiki.phtml)

URL rewriting is recommended to make things not look too dreadful. So far this is limited to the paths to view regular pages. For instance, if in LocalSettings.php your $wgScript is '/w/wiki.phtml' and $wgArticlePath is '/wiki/$1':

RewriteEngine On   RewriteRule ^/wiki/(.*)$ /w/wiki.phtml?title=$1 [L] RewriteRule ^/wiki$ /w/wiki.phtml

This will internally change /wiki/Some_Title to /w/wiki.phtml?title=Some_Title, which gives the script the variables it needs.

Note: What this feature does is that it changes the default file to run in a directory from 'index.html' to 'wiki.phtml' and any parameters given on the line are passed to that program instead of using them as files to attempt to view in that directory. When I was reading the sources, it occurred to me that I couldn't figure out how the wiki.phtml file was being executed, when it turns out it's 'snuck' into the server automagically through this procedure.

Without this feature, all URLs would have to insert 'wiki.phtml?title=' when sending them to the browser window for processing.

Note that when you use URL rewriting, you have to change $wgUploadPath and $wgStyleSheetPath in your LocalSettings.php, otherwise they stay pointing at the default wiki directory, which gets rewritten, with obvious painful consequences.

Example of a working configuration:

Apache configuration:

RewriteEngine On   RewriteRule ^/wiki/(.*)$ /mediawiki/wiki.phtml?title=$1 [L] RewriteRule ^/wiki$ /mediawiki/wiki.phtml

Mediawiki configuration (LocalSettings.php): $IP = "/var/www/mediawiki"; $wgScriptPath      = "/mediawiki"; $wgScript          = "$wgScriptPath/wiki.phtml"; $wgRedirectScript  = "$wgScriptPath/redirect.php"; ## If using PHP as a CGI module, use the ugly URLs $wgArticlePath     = "/wiki/$1";  // this path will be mod rewrote $wgStylePath       = $wgScriptPath."/stylesheets"; $wgStyleDirectory  = "$IP/stylesheets"; $wgLogo            = "$wgStylePath/images/wiki.png"; $wgUploadPath      = $wgScriptPath."/images"; $wgUploadDirectory = "$IP/images";

mod_alias
Alternatively to using mod_rewrite, you may use mod_alias with similar effects. In this case it is assumed that mediawiki is not installed under apache's document root, but in some other directory, e.g. /usr/local/lib/mediawiki. Then you can add lines similar to the following example to your apache configuration:

   Alias /mediawiki/ /usr/local/lib/mediawiki/ Alias /wiki/ /usr/local/lib/mediawiki/index.php/ Alias /wiki /usr/local/lib/mediawiki/index.php/  Options MultiViews AllowOverride None Order allow,deny Allow from all   Options MultiViews AllowOverride None Order allow,deny Allow from all # avoid execution of PHP scripts in upload directory AddType text/plain .php AddType text/plain .phps  

As in the mod_rewrite example, wgScriptPath is now "/mediawiki", and wgArticlePath is "/wiki/$1".

Note that this section on mod_alias was not written by an apache/php expert, so you should check whether it's fitting your security demands.

Patches
If you're using URL rewriting and want to be able to use the ampersand (&) in page titles, you'll need to patch Apache to properly escape the character when generating the query string. A patch for Apache 1.3.26 is available as maintenance/apache-ampersand.diff in the MediaWiki source. (No patch is yet available for Apache 2.0.x.)

Change your mod_rewrite config like so:

RewriteEngine On   RewriteMap ampescape int:ampescape RewriteRule ^/wiki/(.*)$ /w/wiki.phtml?title=${ampescape:$1} [L] RewriteRule ^/wiki$ /w/wiki.phtml

This way, /wiki/AT&T correctly becomes /w/wiki.phtml?title=AT%26T instead of /w/wiki.phtml?title=AT&T, which breaks up into "title=AT" and a useless "T".

Robots exclusion file
You probably don't want spiders trying to download every dynamically generated page... see robots.txt

Throttling
See request throttling.

Reference implementation
For reference, here are the apache configuration files used for Wikimedia wikis:


 * httpd.conf
 * nonexistent.conf
 * webshop.conf
 * testwiki.conf
 * redirects.conf
 * main.conf
 * remnant.conf
 * boards.conf
 * wikimedia.conf
 * foundation.conf
 * en2.conf
 * postrewrites.conf

Next page: Robots.txt >