User:Dantman/Server Config Notes

From mediawiki.org

Apache[edit]

  • RewriteRules support a useful %{DOCUMENT_ROOT} variable.
  • Alias does not support %{DOCUMENT_ROOT}.
  • Need to double check whether RewriteRule supports %{DOCUMENT_ROOT} when in Apache config instead of .htaccess.

Basic .htaccess base:

RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/path/to/index.php [PT,L,QSA]

Line to redirect the root to the wiki (if it's blank):

RewriteRule ^/?$ %{DOCUMENT_ROOT}/path/to/index.php [PT,L,QSA]

Case needed for root urls:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/w/index.php [PT,L,QSA]

Root config basics:

Alias /wiki /path/to/index.php

Doesn't work with root URLs, you'll need to use rewrite rules in-config.

MediaWiki built-in short URL generator notes[edit]

Thanks to Apache's Alias directive the install path can be different than the actual document root. So sometimes the %{DOCUMENT_ROOT} rules will be invalid. The configuration tool will need to differentiate between these two situations. In theory this can be done by looking at the __DIR__ MediaWiki is installed in that $IP is based on, $_SERVER['DOCUMENT_ROOT'], the directory path in some of the $_SERVER values, and the known relative path of the current file.

Nginx[edit]

  • Don't know how to efficiently reproduce the Apache IE6 fix in Nginx.

Lighttpd[edit]

  • Install steps
    • General packages to install: php5-cli, php-apc, php5-mysql, mysql-server, and lighttpd
    • If using php5-cgi and Lighttpd's built in process handling:
      • Packages: php5-cgi
      • Setup fastcgi support with sudo lighty-enable-mod fastcgi; sudo lighty-enable-mod fastcgi-php;
    • If using php5-fpm:
      • Packages: php5-fpm
      • Setup fastcgi support with sudo lighty-enable-mod fastcgi;
      • -not done yet-
    • Install MediaWiki normally
    • Uncommented the "mod_rewrite", in server.modules
    • Added the rewrite rules.

Short URLs[edit]

When installing /phase3/index.php with short URL /wiki/$1 used this config:

# MediaWiki
url.rewrite-once = (
  "^/wiki/" => "/phase3/index.php"
)

When installing /index.php with short URL /wiki/$1 used this config:

# MediaWiki
url.rewrite-once = (
  "^/wiki/" => "/index.php"
)

When installing /index.php with root URL /$1 used this config:

# MediaWiki
url.rewrite-if-not-file = (
  "^/" => "/index.php"
)

Other config bits[edit]

Error handler (when we build support for this into MediaWiki):

server.error-handler-404 = "/index.php"

404 Image error handler (till we build support for this into MediaWiki):

url.rewrite-if-not-file = (
  "^/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$" => "/thumb.php?f=$1&width=$2",
  "^/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$" => "/thumb.php?f=$1&width=$2&archived=1"
)

IIS[edit]

  • Need a unique name="" for each
  • appendQueryString="true" is necessary for QUERY_STRING to be correct.
  • logRewrittenUrl="false" tells IIS to log the original /wiki/$1 url instead of the index.php url inside logs.

Basic rewrite:

<rule name="[...]" enabled="true" stopProcessing="true">
	<match url="^wiki(/.*)?$" />
	<action type="Rewrite" url="w/index.php" appendQueryString="true" logRewrittenUrl="false" />
</rule>

Rewrite for root urls:

<rule name="[...]" enabled="true" stopProcessing="true">
	<match url="^(.*)$" />
	<action type="Rewrite" url="w/index.php" appendQueryString="true" logRewrittenUrl="false" />
	<conditions>
		<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
		<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
	</conditions>
</rule>

Rule to rewrite root of the domain to the mainpage when a subdirectory is used:

<rule name="[...]" enabled="true" stopProcessing="true">
	<match url="^/*$" />
	<action type="Rewrite" url="w/index.php" appendQueryString="true" logRewrittenUrl="false" />
</rule>

All these rules are part of a config file that looks like:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<system.webServer>
		<!-- ... -->
		<rewrite>
			<rules>
				<!-- <rule>s -->
			</rules>
		</rewrite>
	</system.webServer>
</configuration>

Sending 404 errors to index.php in the future:

<httpErrors>
	<remove statusCode="404" subStatusCode="-1" />
	<error statusCode="404" prefixLanguageFilePath="" path="/w/index.php" responseMode="ExecuteURL" />
</httpErrors>