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
URL rewriting is recommended to make some of your URLs look much nicer. This is very installation-specific, but see the Rewrite_rules page for some pointers.

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
 * upload.conf
 * wikimedia.conf
 * foundation.conf
 * en2.conf
 * postrewrites.conf

Next page: Robots.txt >