3 '''tldr''': For GNU/Linux (with a bit of Debian bias), a more concise, holistic and automated install than the official Mediawiki docs. Do some initial configuration then download this page and run it, or execute it as you read.
5 ''' Goals / Why use this guide? '''
7 * Good recommendations. Official docs mostly avoid recommendations among a myriad of possibilities
8 * Closely references & supplements official documentation
9 * Automatic security updates
10 * Explicit automation support wherever practical
11 * Used to setup this site (style is optional)
12 * Support for multiple gnu/linux distros
13 * Holistic scope (backups, server setup), but sections are independent
14 * Code blocks are [https://en.wikipedia.org/wiki/Idempotent idempotent]
15 * Edits to this page are tested on this site and reviewed by the main author.
19 * Self hosting, single GNU/Linux system with root Bash shell
24 Very minor adjustments needed for other distros. Help expand this list.
25 * Mediawiki 1.28, updated as new versions are released
26 * Debian 8 + backports
28 * Debian testing (last tested Aug 7, 2016)
30 Pre 5/2016 revisions ran Mediawiki 1.23, tested on Fedora 20 and Ubuntu 14.04.
34 '''Getting a Server & a Domain'''
36 The most common route and the one taken by this site is buying a domain name from a site like namecheap, and a cheap vps from companies like linode or digital ocean. They have good getting started guides which mostly apply beyond their own sites.
40 For debian jessie with backports:
42 apt-get install --install-suggests jessie-backports certbot
44 For other distros, follow instructions at [https://certbot.eff.org/ certbot.eff.org].
48 Setting up email can be an involved process, and this guide assumes that a some program (usually postfix or exim) is implementing a functional sendmail interface. Mediawiki uses email with to send password reminders or notifications, and this guide includes cronjobs for updating mediawiki and doing backups which will send mail in the case of an error. Email is also the recommended way to get notifications of package updates which require manual steps such as restarting of services.
50 If you are not setting up your server to send mail with a program that uses the default sendmail interface, see these pages when you are configuring mediawiki: [[mediawikiwiki:Manual:$wgEnableEmail|Manual:$wgEnableEmail]], [https://www.mediawiki.org/wiki/Configuration_settings#Email_settings Manual:Email_settings], [[mediawikiwiki:Manual:$wgSMTP|Manual:$wgSMTP]]
52 == Setup Guide Configuration ==
55 # Save the code in this section to a file (~/mw_vars is suggested)
56 # Source it at the beginning of scripts containing later commands
57 # Source it from your .bashrc file while you are setting up Mediawiki
59 '''Requires customization:'''
60 <source lang="bash" type="example">
61 # Replace REPLACE_ME as appropriate
63 export mwdescription="REPLACE_ME" # eg. Opinionated Free Software Wiki
65 # username/pass of the first wiki admin user
66 export wikiuser="REPLACE_ME"
67 export wikipass=REPLACE_ME
69 # root password for the mysql database
70 export dbpass=REPLACE_ME
72 export mwdomain=REPLACE_ME # domain name. for this site, it's ofswiki.org
74 # customize these questions. Try not to have the answer be a word in the question.
76 if ! grep -Fx '$localSettingsQuestyQuestions = array (' $mwc; then
78 $localSettingsQuestyQuestions = array (
79 "What is the name of the wiki software this site (and wikipedia) uses?" => "Mediawiki",
80 "REPLACE_ME with a question" => "REPLACE_ME with an answer"
86 # The rest of this section will work fine with no changes.
88 # git branch for mediawiki + extensions. See intro for supported versions.
89 # branch names: https://git.wikimedia.org/branches/mediawiki%2Fcore.git
90 export mw_branch=REL1_28
92 # As set by gui installer when choosing cc by sa.
93 export mw_RightsUrl='https://creativecommons.org/licenses/by-sa/4.0/'
94 export mw_RightsText='Creative Commons Attribution-ShareAlike'
95 export mw_RightsIcon='$wgScriptPath/resources/assets/licenses/cc-by-sa.png'
97 # Alphanumeric site name for pywikibot.
98 # Here we use the domain minus the dots, which should work fine without changing.
99 export mwfamily=${mwdomain//./}
100 # install path for mediawiki. This should work fine.
101 export mw=/var/www/$mwdomain/html/w
104 # wiki sender address / wiki & wiki server contact email.
105 # see email section for more info on email
106 export mw_email="admin@$mwdomain"
109 mwc="$mw/LocalSettings.php"
112 == Download this page and run it ==
114 This is an option to do automated setup. Optional code blocks are skipped (they have a bold warning just before them and a tag on the source block). The only important things left after running this are running the automated backup setup code on another machine.
116 ''' Requires manual step: inspect output file: /tmp/mw-setup, then run it'''
117 <source lang="bash" type="example">
118 start=' *<source lang="bash"> *'
120 ruby <<'EOF' | sed -rn "/^$start$/,/^$end$/{s/^$start|$end$/# \0/;p} > /tmp/mw-setup"
122 puts JSON.parse(`curl 'https://ofswiki.org/w/api.php?\
123 action=query&titles=Mediawiki_Setup_Guide&prop=revisions&rvprop=content&\
124 format=json'`.chomp)['query']['pages'].values[0]['revisions'][0]['*']
126 chmod +x /tmp/mw-setup
129 == Required Bash Functions ==
131 Here we define some small useful bash functions. This should be part of the same ~/mw_vars file if you are running the code step by step.
134 # identify if this is a debian based distro
135 isdeb() { command -v apt &>/dev/null; }
136 # tee unique. append each stdin line if it does not exist in the file
140 for line in "${MAPFILE[@]}"; do
141 grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line"
145 # get and reset an extension/skin repository, and enable it
148 local original_pwd="$PWD"
150 local re='[^/]*/[^/]*$' # last 2 parts of path
151 [[ $url =~ $re ]] ||:
152 target=$mw/${BASH_REMATCH[0]}
153 if [[ ! -e $target/.git ]]; then
154 git clone $url $target
156 if ! cd $target; then
157 echo "mw-ext error: failed cd $target";
161 git checkout -qf origin/$mw_branch || git checkout -qf origin/master
169 mw-clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/$ext
170 if [[ -e $mw/extensions/$ext/extension.json ]]; then
171 # new style extension
173 wfLoadExtension( '$ext' );
177 require_once( "\$IP/extensions/$ext/$ext.php" );
181 # --quick is quicker than default flags,
182 # but still add a sleep to make sure everything works right
183 sudo -u $apache_user php $mw/maintenance/update.php -q --quick; sleep 1
187 mw-clone https://gerrit.wikimedia.org/r/p/mediawiki/skins/$skin
188 sed -i --follow-symlinks '/^wfLoadSkin/d' $mwc
189 sed -i --follow-symlinks '/^\$wgDefaultSkin/d' $mwc
191 \$wgDefaultSkin = "${skin,,*}";
192 wfLoadSkin( '$skin' );
194 sudo -u $apache_user php $mw/maintenance/update.php -q --quick; sleep 1
197 if command -v apt &>/dev/null; then
205 == Install Mediawiki Dependencies ==
207 The best way to get core dependencies is to install the mediawiki package itself. Nothing about it will get in the way of using a version from upstream.
209 [[mediawikiwiki:Main Page|Mediawiki Main Page]]: the beginning of the official docs.
211 [[mediawikiwiki:Manual:Installation_requirements|Manual:Installation_requirements]]: Overview of installation requirements.
213 Note, this guide needs a little adjustment before it will work with php7.0: make sure settings are still valid, update ini path.
218 # From here on out, exit if a command fails.
219 # This will prevent us from not noticing an important failure.
220 # We recommend setting this for the entire installation session.
221 # If you are running commands interactively, it might be best to
222 # put it in your ~/.bashrc temporarily.
224 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
229 # https://www.mediawiki.org/wiki/Manual:Running_MediaWiki_on_Ubuntu
231 DEBIAN_FRONTEND=noninteractive apt-get install -y imagemagick curl
232 if apt-get install -s mediawiki &>/dev/null; then
233 # mediawiki is packaged in jessie backports.
234 DEBIAN_FRONTEND=noninteractive apt-get -y install php5-apcu mediawiki
236 # https://www.mediawiki.org/wiki/Manual:Installation_requirements
237 if apt-get install -s php7.0 &>/dev/null; then
238 # note, 7.0 is untested by the editor here, since it's not
239 # available in debian 8. it's listed as supported
240 # in the mediawiki page.
241 # noninteractive to avoid mysql password prompt.
242 DEBIAN_FRONTEND=noninteractive apt-get install -y apache2 \
243 default-mysql-server \
244 php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-xml \
245 php7.0-apcu php7.0-mbstring
247 # note: mbstring is recommended, but it's not available for php5 in
249 DEBIAN_FRONTEND=noninteractive apt-get install -y apache2 \
250 default-mysql-server \
251 php5 php5-mysql libapache2-mod-php5 php5-apcu
254 service apache2 restart
257 # fedora deps are missing a database, so some is translated from debian packages
258 yum -y install mediawiki ImageMagick php-mysqlnd php-pecl-apcu mariadb-server
260 systemctl restart mariadb.service
261 systemctl enable mariadb.service
262 systemctl enable httpd.service
263 systemctl restart httpd.service
267 # slightly different depending on if we already set the root pass
268 if echo exit|mysql -u root -p"$dbpass"; then
269 # answer interactive prompts:
270 # mysql root pass, change pass? no, remove anon users? (default, yes)
271 # disallow remote root (default, yes), reload? (default, yes)
272 echo -e "$dbpass\nn\n\n\n\n" | mysql_secure_installation
274 # I had 1 less newline at the start when doing ubuntu 14.04,
275 # compared to debian 8, so can't say this is especially portable.
276 # It won't hurt if it fails.
277 echo -e "\n\n$dbpass\n$dbpass\n\n\n\n\n" | mysql_secure_installation
282 '''Skippable notes'''
285 php[5]-mysqlnd is a faster mysql driver package, but the default in debian php-mysql, appparently because some non-mediawiki packages are not compatible with it. If you run into this issue, simply use the php-mysql package.
288 Additional packages rational
289 * ImageMagick is [https://www.mediawiki.org/wiki/Manual:Image_administration#Image_thumbnailing recommended].
290 * Gui install and [[mediawikiwiki:Manual:Cache]] recomend the apc package.
291 * Clamav for virus scanning of uploads is mentioned in the mediawiki manual. However, wikipedia doesn't seem to do it, so it doesn't seem like it's worth bothering. It also makes uploading a set of images take twice as long on broadband.
293 == Install Mediawiki ==
296 Here, we [[mediawikiwiki:Download_from_Git]], or reset our installation if it is already there, and create the wiki database. [[mediawikiwiki:Manual:Installing_MediaWiki]]
301 # this will just fail if it already exists which is fine
302 if [[ ! -e .git ]]; then
303 git clone https://gerrit.wikimedia.org/r/p/mediawiki/core.git .
305 # to see available branches: https://www.mediawiki.org/wiki/Version_lifecycle
308 git checkout -f origin/$mw_branch
310 # apply librejs patch
311 curl "https://iankelling.org/git/?p=mediawiki-librejs-patch;a=blob_plain;f=mediawiki-1.28-librejs.patch;hb=HEAD" | patch -r - -N -p1
312 # Get the php libraries wmf uses. Based on:
313 # https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries
314 if [[ ! -e vendor/.git ]]; then
315 git clone https://gerrit.wikimedia.org/r/p/mediawiki/vendor.git
318 git checkout -f origin/$mw_branch
321 # Drop any previous database which may have been installed while testing.
322 # If upgrading, we should have a db backup which will get restored.
323 # https://www.mediawiki.org/wiki/Manual:Upgrading
324 mysql -u root -p$dbpass <<'EOF' ||:
325 drop database my_wiki;
328 php $mw/maintenance/install.php --pass $wikipass --scriptpath /w \
329 --dbuser root --dbpass $dbpass "$mwdescription" "$wikiuser"
331 # lock down the wiki to only the initial owner until anti-spam measures are put in place
332 # limit edits to registered users
333 $wgGroupPermissions['*']['edit'] = false;
334 # don't allow any account creation
335 $wgGroupPermissions['*']['createaccount'] = false;
340 Note: When testing, you may need to clear the apc cache to see changes take effect in the browser. Simplest solution is
341 just restart apache. http://stackoverflow.com/questions/911158/how-to-clear-apc-cache-entries
343 ''' Skippable Notes'''
345 If we wanted to reset our installation, but leave the extension repositories alone, alter the command above to be <code>git clean -fxd</code>
347 '''Rational for choosing git sources'''
349 Upstream vs distro packages. Upstream is responsive, and it's distributed within a single directory, so packaging does not integrate with the distro's filesystem. The only potential value would be less bugs by using stable versions, but we choose not to make that tradeoff.
351 Why use git over zip file releases? Mediawiki supports git usage through release branches which get post-release fixes. This means we can auto-update, get more granular fixes, easier to manage updates, and rollbacks.
353 == Configure Apache ==
355 Note, non-debian based installs: modify instructions below to use /etc/httpd/conf.d/$mwdomain.conf, and don't run a2ensite.
357 I use scripts I maintains separately to setup Let's Encrypt certificates and apache config: (url pending).
359 If you are doing a test setup on your local machine, you can make your domain resolve to your local test installation, then remove it later when you are done. Note, you will need non-local site to get Let's Encrypt certificates, and then transfer them locally, or disable ssl from the apache config (neither is covered here) and replace all instances of https in these instructions with http. Another option is to get a cheap 2 dollar domain for your test site.
361 '''Not for production:'''
362 <source lang="bash" type="example">
363 teeu /etc/hosts<<<"127.0.0.1 $mwdomain"
366 To not use my scripts, and still use Let's Encrypt: follow this doc page: https://letsencrypt.org/getting-started/. It's a little long winded, so I would boil it down to this:
368 '''Optional & requires additional steps:'''
369 <source lang="bash" type="example">
370 git clone https://github.com/certbot/certbot
372 ./certbot-auto apache
373 cd /etc/apache/sites-available
374 mv 000-default-le-ssl.conf $mwdomain.conf
375 rm ../sites-enabled/000-default-le-ssl.conf
376 # edit $mwdomain.conf, so documentroot is /var/www/$mwdomain/html
377 # and ServerName is $mwdomain
378 a2ensite $mwdomain.conf
380 Then, copy the input to apache-site below and insert it into the apache config.
382 Here, we use some scripts automate setting up the Let 's Encrypt cert and
388 git_site=https://iankelling.org/git
392 git clone $git_site/basic-https-conf
393 basic-https-conf/web-conf -r ${mw%/*} - apache2 $mwdomain <<EOF
394 ServerAdmin $mw_email
396 # make the site's root url go to our main page
397 RewriteRule ^/?wiki(/.*)?\$ %{DOCUMENT_ROOT}/w/index.php [L]
398 # use short urls https://www.mediawiki.org/wiki/Manual:Short_URL
399 RewriteRule ^/*\$ %{DOCUMENT_ROOT}/w/index.php [L]
401 find -L $(readlink -f $mw) -name .htaccess \
402 | while read line; do
403 echo -e "<Directory ${line%/.htaccess}>\n $(< $line)\n</Directory>";
409 Now mediawiki should load in your browser at $mwdomain .
411 Allow proper search bots and internet archiver bots, via [[Mediawiki:Robots.txt]],
412 and install the default skin.
415 dd of=$mw/../robots.txt <<'EOF'
418 User-agent: ia_archiver
424 '''Skippable Notes'''
426 This section assumes we are redirecting www to a url without www.
428 [http://httpd.apache.org/docs/current/howto/htaccess.html Apache recommends] moving .htaccess rules into it's config for performance. So we look for .htaccess files from mediawiki and copy their contents into this config. In modern apache versions, we would have to explicitly set options like AllowOverride to allow .htaccess files to take effect.
430 == Mediawiki Settings ==
432 Overall reference: [[mediawikiwiki:Manual:Configuration_settings]].
434 Settings which the gui setup prompts for but aren't set by the automated install script.
437 \$wgServer = "https://$mwdomain";
438 \$wgDBserver = "localhost";
439 \$wgRightsUrl = "$mw_RightsUrl";
440 \$wgRightsText = "$mw_RightsText";
441 \$wgRightsIcon = "$mw_RightsIcon";
444 Settings asked by the gui setup which are different than the install script defaults. They different because the defaults are the most compatible and unobtrusive.
447 \$wgPasswordSender = "$mw_email";
448 \$wgEmergencyContact = "$mw_email";
449 \$wgEnotifUserTalk = true; # UPO
450 \$wgEnotifWatchlist = true; # UPO
451 \$wgMainCacheType = CACHE_ACCEL;
452 \$wgEnableUploads = true;
453 \$wgUseInstantCommons = true;
461 # from https://www.mediawiki.org/wiki/Manual:Short_URL
462 $wgArticlePath = "/wiki/$1";
464 # https://www.mediawiki.org/wiki/Manual:Combating_spam
465 # check that url if our precautions don't work
466 # not using nofollow is good practice, as long as we avoid spam.
467 $wgNoFollowLinks = false;
468 # Allow user customization.
469 $wgAllowUserCss = true;
470 # use imagemagick over GD
471 $wgUseImageMagick = true;
472 # manual says this is not production ready, I think that is mostly
473 # because they are using MobileFrontend extension instead, which gives
474 # an even cleaner more minimal view, I plan to try setting it up
475 # sometime but this seems like a very nice improvement for now.
476 $wgVectorResponsive = true;
480 # https://www.mediawiki.org/wiki/Manual:Configuring_file_uploads
481 # Increase from default of 2M to 100M.
482 # This will at least allow high res pics etc.
483 php_ini=$(php -r 'echo(php_ini_loaded_file());')
484 sed -i --follow-symlinks 's/^\(upload_max_filesize\|post_max_size\)\b.*/\1 = 100M/' $php_ini
486 service apache2 restart
488 systemctl restart httpd.service
491 # if you were to install as a normal user, you would need this for images
492 # sudo usermod -aG $apache_user $USER
494 # this doesn't propogate right away
495 chgrp -R $apache_user $mw/images
496 chmod -R g+w $mw/images
499 Style settings. Omit to use a different style.
503 #$wgFooterIcons = null;
505 # Make the toolbox go into the drop down.
507 if ! git remote show ian-kelling &>/dev/null; then
508 git remote add ian-kelling https://iankelling.org/git/forks/Vector
510 git fetch ian-kelling
511 git checkout ian-kelling/${mw_branch}-toolbox-in-dropdown
514 == Install and Configure Mediawiki Extensions ==
516 When installing extensions on a wiki with important content, backup first as a precaution.
518 ''' Extensions with no configuration needed '''
524 | [[mediawikiwiki:Extension:Cite|Extension:Cite]]
525 | Have references in footnotes*
527 | [[mediawikiwiki:Extension:CiteThisPage|Extension:CiteThisPage]]
528 | Ability to generate citations to pages in a variety of styles*
530 | [[mediawikiwiki:CheckUser|Extension:CheckUser]]
531 | Get ip addresses from inside mediawiki so you can ban users''
533 | [[mediawikiwiki:Extension:CSS|Extension:CSS]]
534 | Allows CSS stylesheets to be included in specific articles
536 | [[mediawikiwiki:Extension:Echo|Extension:Echo]]
537 | Notification subsystem for usage by other extensions
539 | [[mediawikiwiki:Extension:Gadgets|Extension:Gadgets]]
540 | UI extension system for users*
542 | [[mediawikiwiki:Extension:ImageMap|Extension:ImageMap]]
543 | Links for a region of an image*
545 | [[mediawikiwiki:Extension:Interwiki|Extension:Interwiki]]
546 | Tool for nice links to other wikis*
548 | [[mediawikiwiki:Extension:News|Extension:News]]
549 | Embed or rss recent changes
551 | [[mediawikiwiki:Extension:Nuke|Extension:Nuke]]
552 | Mass delete of pages, in the case of spam*
554 | [[mediawikiwiki:Extension:ParserFunctions|Extension:ParserFunctions]]
555 | Useful for templates*
557 | [[mediawikiwiki:Extension:Poem|Extension:Poem]]
558 | Useful for formatting things various ways*
560 | [[mediawikiwiki:Extension:Renameuser|Extension:Renameuser]]
561 | Allows bureaucrats to rename user accounts*
563 | [[mediawikiwiki:Extension:SyntaxHighlight_GeSHi|Extension:SyntaxHighlight_GeSHi]]
564 | Source code highlighting*
566 | [[mediawikiwiki:Extension:Variables|Extension:Variables]]
567 | Define per-page variables
570 <nowiki>*</nowiki> = Comes with the MediaWiki default download.
573 mw-ext Cite CiteThisPage CheckUser CSS Echo Gadgets ImageMap Interwiki News \
574 Nuke ParserFunctions Poem Renameuser SyntaxHighlight_GeSHi Variables
578 ''' [[mediawikiwiki:Extension:AntiSpoof|Extension:AntiSpoof]]: Disallow usernames with unicode trickery to look like existing names'''
582 # recommended setup script to account for existing users
583 sudo -u $apache_user php $mw/extensions/AntiSpoof/maintenance/batchAntiSpoof.php
587 '''[[mediawikiwiki:Extension:Wikidiff2|Extension:Wikidiff2]]: Faster and international character supported page diffs'''
589 I used packaged version since this is a c++ and probably not very tied to the Mediawiki version. This isn't packaged in fedora, haven't gotten around to testing and adding the code to compile it for fedora.
592 apt-get -y install php-wikidiff2
594 $wgExternalDiffEngine = 'wikidiff2';
596 dir=$(dirname $(php -r 'echo(php_ini_loaded_file());'))/../apache2/conf.d
597 ln -sf ../../mods-available/wikidiff2.ini $dir
598 service apache2 restart
603 ''' [[mediawikiwiki:Extension:Math|Extension:Math]] Display equations'''
607 # php5-curl according to Math readme
610 if ! apt-get -s install $curl_pkg &>/dev/null; then
613 apt-get -y install latex-cjk-all texlive-latex-extra texlive-latex-base \
614 ghostscript imagemagick ocaml $curl_pkg make
616 # todo, php5-curl equivalent on fedora
617 yum -y install texlive-cjk ghostscript ImageMagick texlive ocaml
619 service apache2 restart
621 cd $mw/extensions/Math/math; make # makes texvc
622 cd $mw/extensions/Math/texvccheck; make
625 # Enable MathJax as rendering option
626 $wgUseMathJax = true;
627 # Enable LaTeXML as rendering option
628 $wgMathValidModes[] = 'latexml';
629 # Set LaTeXML as default rendering option, because it is nicest
630 $wgDefaultUserOptions['math'] = 'latexml';
634 '''Skippable notes'''
636 There is no current list of package depencies so I took dependencies from mediawiki-math package in Debian 7. Fedora didn't have a mediawik math package, so I just translated from debian. Ocaml is for math png rendering, as backup option to the nicer looking LatexML and MathJax. Debian has texvc package, but it didn't work right for me, plus it required additional configuration in mediawiki settings.
639 ''' [[mediawikiwiki:Extension:SpamBlacklist|Extension:SpamBlacklist]]: Import/create IP blacklists, mainly for spam'''
641 Comes with MediaWiki.
645 if ! grep -F '$wgSpamBlacklistFiles = array(' $mwc &>/dev/null; then
647 $wgEnableDnsBlacklist = true;
648 $wgDnsBlacklistUrls = array( 'xbl.spamhaus.org', 'dnsbl.tornevall.org' );
650 ini_set( 'pcre.backtrack_limit', '10M' );
651 $wgSpamBlacklistFiles = array(
652 "[[m:Spam blacklist]]",
653 "http://en.wikipedia.org/wiki/MediaWiki:Spam-blacklist"
659 ''' [[mediawikiwiki:Extension:TitleBlacklist|Extension:TitleBlacklist]]: Anti-spam '''
661 Comes with Mediawiki.
664 mw-ext TitleBlacklist
665 if ! grep -F '$wgTitleBlacklistSources = array(' $mwc &>/dev/null; then
667 $wgTitleBlacklistSources = array(
670 'src' => 'MediaWiki:Titleblacklist',
674 'src' => 'http://meta.wikimedia.org/w/index.php?title=Title_blacklist&action=raw',
681 ''' [[mediawikiwiki:Extension:WikiEditor|Extension:WikiEditor]]: Editing box extras and a fast preview tab '''
683 Comes with MediaWiki.
688 # Enable Wikieditor by default
689 $wgDefaultUserOptions['usebetatoolbar'] = 1;
690 $wgDefaultUserOptions['usebetatoolbar-cgd'] = 1;
692 # Display the Preview and Changes tabs
693 $wgDefaultUserOptions['wikieditor-preview'] = 1;
697 ''' [[mediawikiwiki:CategoryTree|Extension:CategoryTree]]: Enables making nice outlines of pages in a category'''
701 # Mediawiki setting dependency for CategoryTree
706 ''' [[mediawikiwiki:Extension:AbuseFilter|Extension:AbuseFilter]]: Complex abilities to stop abuse '''
708 Used by big wiki sites. As a smaller site, we won't use it much, but it's good to have. It's page suggests a few defaults:
712 $wgGroupPermissions['sysop']['abusefilter-modify'] = true;
713 $wgGroupPermissions['*']['abusefilter-log-detail'] = true;
714 $wgGroupPermissions['*']['abusefilter-view'] = true;
715 $wgGroupPermissions['*']['abusefilter-log'] = true;
716 $wgGroupPermissions['sysop']['abusefilter-private'] = true;
717 $wgGroupPermissions['sysop']['abusefilter-modify-restricted'] = true;
718 $wgGroupPermissions['sysop']['abusefilter-revert'] = true;
722 '''[[mediawikiwiki:Extension:ConfirmEdit|Extension:ConfirmEdit]]: Custom Captcha.'''
724 Uses captchaArray defined in mw_vars. Comes with MediaWiki.
730 wfLoadExtension( 'ConfirmEdit/QuestyCaptcha' );
731 $wgCaptchaClass = 'QuestyCaptcha';
732 # only captcha on registration
733 $wgGroupPermissions['user' ]['skipcaptcha'] = true;
734 $wgGroupPermissions['autoconfirmed']['skipcaptcha'] = true;
736 if ! grep -Fx 'foreach ( $localSettingsQuestyQuestions as $key => $value ) {' $mwc; then
738 foreach ( $localSettingsQuestyQuestions as $key => $value ) {
739 $wgCaptchaQuestions[] = array( 'question' => $key, 'answer' => $value );
745 Enable account creation that we initially disabled.
747 sed -i --follow-symlinks "/\\\$wgGroupPermissions\\['\\*'\\]\\['createaccount'\\] = false;/d" $mwc
750 == Additional Configuration with Pywikibot ==
752 There are quite a few [[mediawikiwiki:Help:Namespaces|special pages]] which act like variables to configure special wiki content and style. A big part of this wiki's style is configured in this section. We use Pywikibot to automate editing those pages.
755 '''Pywikibot Install'''
757 [[mediawikiwiki:Manual:Pywikibot/Installation|Manual:Pywikibot/Installation]]
761 if [[ ! -e ~/pywikibot/.git ]]; then
762 git clone --recursive \
763 https://gerrit.wikimedia.org/r/pywikibot/core.git ~/pywikibot
772 '''Pywikibot Configuration'''
774 Relevent docs: [[mediawikiwiki:Manual:Pywikibot/Use_on_non-WMF_wikis|Manual:Pywikibot/Use_on_non-WMF_wikis]], [[mediawikiwiki:Manual:Pywikibot/Quick_Start_Guide|Manual:Pywikibot/Quick_Start_Guide]]
779 dd of=user-config.py <<EOF
781 usernames["$mwfamily"]['en'] = u'$wikiuser'
783 console_encoding = 'utf-8'
784 password_file = "secretsfile"
787 dd of=secretsfile <<EOF
788 ("$wikiuser", "$wikipass")
791 # it won't overrwrite an existing file. Remove if if one exists
792 rm -f pywikibot/families/${mwfamily}_family.py
794 apt-get install -y python-requests
796 yum -y install python-requests
799 python generate_family_file.py https://$mwdomain/wiki/Main_Page "$mwfamily"
801 # Note, this needed only for ssl site
802 tee -a pywikibot/families/${mwfamily}_family.py<<'EOF'
803 def protocol(self, code):
809 '''Pywikibot Script'''
811 This will take a full minute or so because the bot waits a few seconds between edits. Useful doc: [[mediawikiwiki:Pywikipediabot/Create_your_own_script]].
816 dd of=scripts/${mwfamily}_setup.py<<EOF
820 site = pywikibot.Site()
822 page = pywikibot.Page(site, p)
824 #force is for some anti-bot thing, not necessary in my testing, but might as well include it
825 page.save(force=True)
827 # Small/medium noncommercial wiki should be fine with no privacy policy
828 # based on https://www.mediawiki.org/wiki/Manual:Footer
829 x("MediaWiki:Privacy")
831 # licenses for uploads. Modified from the mediawiki's wiki
832 x("MediaWiki:Licenses", u"""* Same as this wiki's text (preferred)
833 ** CC BY-SA or GFDL| Creative Commons Attribution ShareAlike or GNU Free Documentation License
835 ** Unknown_copyright|I don't know exactly
836 ** PD|PD: public domain
837 ** CC BY|Creative Commons Attribution
838 ** CC BY-SA|Creative Commons Attribution ShareAlike
839 ** GFDL|GFDL: GNU Free Documentation License
840 ** GPL|GPL: GNU General Public License
841 ** LGPL|LGPL: GNU Lesser General Public License""")
842 x("MediaWiki:Copyright", '$mw_license')
843 x("MediaWiki:Mainpage-description", "$mwdescription")
847 # The rest of the settings are for the site style
849 # Remove various clutter
850 x("MediaWiki:Lastmodifiedat")
851 x("MediaWiki:Disclaimers")
852 x("MediaWiki:Viewcount")
853 x("MediaWiki:Aboutsite")
854 # remove these lines from sidebar
855 # ** recentchanges-url|recentchanges
856 # ** randompage-url|randompage
858 x("MediaWiki:Sidebar", """* navigation
859 ** mainpage|mainpage-description
865 # helpfull doc: https://www.mediawiki.org/wiki/Manual:Interface/Sidebar
866 x("mediawiki:Common.css", """/* adjust sidebar to just be home link and up top */
867 /* adjust sidebar to just be home link and up top */
868 /* panel width increased to fit full wiki name. */
869 /* selectors other than final id are for increasing priority of rule */
870 div#mw-panel { top: 10px; padding-top: 0em; width: 20em }
871 div#footer, #mw-head-base, div#content { margin-left: 1em; }
872 #left-navigation { margin-left: 1em; }
875 /* logo, and toolbar hidden */
876 #p-logo, div#mw-navigation div#mw-panel #p-tb {
880 div#mw-content-text {
886 # this can spam a warning, so uniq it
887 python pwb.py ${mwfamily}_setup |& uniq
891 ''' Skippable Notes '''
893 The docs suggest manually entering the pass with python pwb.py login.py, then it should stay logged in. That didn't work for me, and anyways, we automation, so we use secrets file method.
895 Family name, and all its duplicattions documented as supposed to be $wgSitename, but it works fine using any name.
897 == Automatic Backups ==
899 Here we will have a daily cronjob where a backup host sshs to the mediawiki host, makes a backup then copies it back. Copy ~/mw_vars to the backup host at /root/mw_vars. Setup passwordless ssh from the backup host to the mediawiki host. Then run this code on the backup host. This will make a versioned backup of the wiki to ~/backup.
901 <source lang="bash" type="backup">
902 backup_script=/etc/cron.daily/mediawiki_backup
903 sudo dd of=$backup_script <<'EOFOUTER'
905 # if we get an error, keep going but return it at the end
907 trap 'last_error=$?' ERR
909 # No strict because the host is likely not named the same as
911 ssh="ssh -oStrictHostKeyChecking=no"
912 logfile=/var/log/${mwdomain}_backup.log
914 echo "#### starting backup at $(date) ####"
915 $ssh root@$mwdomain <<ENDSSH
918 \$wgReadOnly = 'Dumping Database, Access will be restored shortly';
920 mkdir -p ~/wiki_backups
921 mysqldump -p$dbpass --default-character-set=binary my_wiki > ~/wiki_backups/wiki_db_backup
922 sed -i '\$ d' $mwc # delete read only setting
924 # add no strict option to the defaults
926 rdiff() { rdiff-backup --remote-schema "$ssh -C %s rdiff-backup --server" "$@"; }
928 rdiff root@$mwdomain::/root/wiki_backups ~/backup/${mwdomain}_wiki_db_backup
929 rdiff root@$mwdomain::$mw ~/backup/${mwdomain}_wiki_file_backup
931 echo "=== ending backup at $(date) ===="
933 if [[ $last_error != 0 ]]; then
934 echo "backup for $mwdomain failed. See $logfile"
939 sudo chmod +x $backup_script
942 '''Optional & requires additional steps'''
944 If you are like most people and don't use the old-school mail spool, setup the backup system to send mail externally so you are notified if it fails. For examples of how to do this, [http://unix.stackexchange.com/questions/36982/can-i-set-up-system-mail-to-use-an-external-smtp-server stackoverflow], [https://iankelling.org/git/?p=ian-specific/distro-setup;a=blob;f=mail-setup;hb=HEAD script I use].
946 == Restoring Backups ==
948 '''Whenever you implement a backup system, you should test that restoring the backup works.'''
950 You ''should'' be able to restore your wiki to a new machine by repeating all install steps, then restoring the database and the images directory. I've done this many times. However, we backup the entire Mediawiki directory in case you forget to record a step or some corner case happens. Since most people don't record the steps they took to setup Mediawiki, this is also the officially recommended method. In the code below we restore only the database and images folder from the full backup. You can try this after setting up a wiki from scratch. If it doesn't work, you know your fresh setup is not replicating your backed up wiki correctly. In that case, you can fall back to doing a full restore by copying the full directory instead of just the images. See [[mediawikiwiki:Manual:Restoring a wiki from backup]] if you run into any problems.
952 To test a backup restore:
953 # Do a backup of your wiki with some content in it, as described in the previous section
954 # Move your mediawiki install directory, or setup Mediawiki on a new machine
955 # Re-execute the mediawiki install steps
956 # Change REPLACE_ME in the code below (as in the backup section so you get the right variables),
957 # Execute the code on the backup machine.
960 <source lang="bash" type="example">
963 restore="rdiff-backup --force -r now"
964 $restore ~/backup/${mwdomain}_wiki_file_backup /tmp/wiki_file_restore
965 $restore ~/backup/${mwdomain}_wiki_db_backup /tmp/wiki_db_restore
966 o=-oStrictHostKeyChecking=no
967 scp $o -r /tmp/wiki_file_restore/images/* root@$mwdomain:$mw/images
968 scp $o -r /tmp/wiki_db_restore root@$mwdomain:/tmp
969 ssh $o root@$mwdomain <<EOF
971 chmod -R g+w $mw/images
972 chgrp -R www-data $mw/images
973 mysql -u root -p$dbpass my_wiki < /tmp/wiki_db_restore/wiki_db_backup
974 php $mw/maintenance/update.php
978 Then browse to your wiki and see if everything appears to work.
982 Subscribe to get release and security announcements [https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce MediaWiki-announce].
984 For updates, we simply git pull all the repos, then run the maintenance script. This should be done after a backup. We recommend automatic updates to get security fixes and since not much is changing on the release branch. In this example, we update at 5 am daily (1 hour after the automatic backup example).
986 Major version upgrades should be done manually, and it is recommended to use a new installation directory and the same procedure as for backup & restore. Official reference: [[mediawikiwiki:Manual:Upgrading|Manual:Upgrading]]
988 Minor updates script:
990 s=/etc/cron.daily/mediawiki_update
997 [[ -d $dir ]] || return 1
999 branch=$(git describe --all)
1000 branch=${branch#remotes/}
1002 new_head=$(git rev-parse $branch)
1003 log=$(git log HEAD..$new_head)
1004 if [[ ! $log ]]; then
1009 git checkout -qf $new_head
1013 for dir in extensions/* skins/* vendor; do
1017 curl "https://iankelling.org/git/?p=mediawiki-librejs-patch;a=blob_plain;f=mediawiki-1.28-librejs.patch;hb=HEAD" | patch -r - -N -p1
1019 php $mw/maintenance/update.php -q --quick
1024 == Upgrading Major Versions ==
1026 Reference documentation is at [[mediawikiwiki:Manual:Upgrading]]
1030 # Read the "Upgrade notices for MediaWiki administrators" on the upgrade version and any skipped versions at [[mediawikiwiki:Version_lifecycle]].
1031 # Setup a blank test wiki with the new version.
1032 # Backup the old database, restore it to the new wiki, run php maintenance/update.php.
1033 # If everything looks good, repeat and replace the old wiki with the new one.
1037 There is a balance between effective anti-spam measures and blocking/annoying contributors. Mediawiki documentation on how to combat spam, is not very good, but it has improved over time: [https://www.mediawiki.org/wiki/Manual:Combating_spam manual: Combating Spam]. It's possible for a spammer to quickly make thousands of edits, and there is no good documentation on purging lots of spam, so you should have a good strategy up front. My current strategy is 3 fold, and is limited to small/medium wiki's:
1039 * Find new spam quickly, revert it & ban the user.
1040 ** Watch, and get notified of changes on all primary content pages: Special:Preferences, Bottom of the page, set an email address, then turn on "Email me also for minor edits of pages and files."
1041 ** Use a rss/atom feed reader, and subscribe to recent changes across the wiki. Newer browsers have an rss feed subscribe button, you can click after going to Special:RecentChanges. If that is not available, you can construct the proper url based on [https://meta.wikimedia.org/wiki/Help:Recent_changes#Web_feed these instructions].
1042 * Require registration to edit, and a custom captcha question on registration.
1043 * Install all non-user inhibiting anti-spam extensions / settings that take a reasonable amount of time to figure out.
1045 == Choosing Extensions ==
1047 Mediawiki.org has pages for ~5200 extensions. Mediawiki maintains ~700 extensions [http://git.wikimedia.org/tree/mediawiki%2Fextensions.git in it's git repo]. Wikipedia uses [https://en.wikipedia.org/wiki/Special:Version over 100 extensions]. Major distributors package [[mediawikiwiki:Comparison_of_extensions_in_distributions| ~36 extensions]]. We looked closely at the distributor's and briefly at the Mediawiki repo extensions. We haven't found any other useful list or recommendations.
1049 Here are brief descriptions of extensions that are part of distributions and why they were rejected for this wiki.
1051 {| class="wikitable"
1053 | '''Footnote''' || deprecated in newer versions
1055 | '''InputBox''' || Add html forms to pages. Can't imagine using it. Would install if I did.
1057 | '''LocalisationUpdate'''|| update localization only. I'm fine updating all of mediawiki, there aren't many updates.
1059 | '''NewestPages''' || A page creation history that doesn't expire like recent-changes. Meh
1061 | '''NewUserNotif''' || Send me a notification when a user registers. Seems like an excessive notification.
1063 | '''Openid''' || Poor UI. 2 pages & 2 links <login> <login with openid> which is confusing & ugly.
1065 | '''Pdfhandler''' || Gallery of pages from a pdf file. Can't imagine using it. Would install if I did.
1067 | '''RSSReader''' || Embed an rss feed. Can't imagine using it. Would install if I did.
1069 | '''Semantic''' || Seems like a lot of trouble around analyzing kinds of data which my wiki will not have.
1071 | '''Validator''' || dependency of of semantic
1077 ''' Web Analytics Software '''
1079 I do not recommend using google analytics: it's proprietary software and gives private information of your website visitors to google for them to make money. Piwik has the best features and I recommend it, but I use goaccess because it is simpler to manage and good enough.
1081 ''' Mediawiki Documentation Quality '''
1083 Overall the documentation is good, but like wikipedia, it depends.
1085 The closer a topic is to core functionality and commonly used features, the better the documentation is likely to be. Wikimedia Foundation (WMF) has a competing priority of being a good upstream to mediawiki users and being good for their own sites. That, plus the multitude of unconnected extension developers, and official documentation is sometimes neglected in favor of bug reports, readme files, comments, code, and unpublished knowledge. User's documentation edits vary in quality, and often aren't reviewed by anyone. If you run into an issue, try viewing/diffing the most recent version of a page by the last few editors.
1087 One issue is that mediawiki.org needs a lot of organizing, deleting, and verifying of material, and that is relatively unpopular, tedious, and sometimes difficult work. The discussion pages of mediawiki.org are a wasteland of unanswered questions and outdated conversations, which is [https://www.mediawiki.org/wiki/Help:Talk_pages poor form] for a wiki. However, if you communicate well, you can get great help from their [https://www.mediawiki.org/wiki/Communication support forum, irc, and mailing list].
1090 '''Bash here documents, EOF vs 'EOF' '''
1092 Here documents are used throughout this page, some people may not be aware of a small but important syntax. When the delimiter is quoted, as in <<'EOF', then the contents of the here document are exactly verbatim. Otherwise $ and ` are expanded as in bash, and must be escaped by prefixing them with \, which itself must then also be escaped to be used literally.
1095 ''' Mediawiki automation tools survey 7/2014 '''
1098 * https://github.com/ianweller/mw
1099 * http://search.cpan.org/~markj/WWW-Mediawiki-Client/bin/mvs
1100 * https://github.com/alexz-enwp/wikitools 3000 lines of code, no response to a bug reports in 2/2014
1102 Getting basic maintenance
1103 * https://github.com/mwclient/mwclient 2000 lines of code
1105 Actively developed, used by wikimedia foundation a lot.
1106 * [[mediawikiwiki:Manual:Pywikibot]]
1109 ''' Troubleshooting Errors '''
1111 If mediawiki fails to load, or shows an error in the browser, enable some settings and it will print much more useful information. [[mediawikiwiki:Manual:How to debug]]
1115 This page and this wiki is licensed under cc-by-sa 4.0.
1116 This means the code is compatible with gplv3.
1118 == todo list for this page ==
1120 * Get Visual editor extension.
1121 * Don't require registration for edits