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 * Explicit automation support wherever practical
10 * Used to setup this site (style optional)
11 * Contributions welcome and will be updated/tested on this very site!
12 * Support for multiple gnu/linux distros
13 * Holistic scope (backups, server setup), but sections stand on their own
14 * Explicit support for production & local testing instance. Additions for production like https and web analytics.
15 * Edits to this page are closely monitored by the original author.
19 * Self hosting, single GNU/Linux system with Bash shell
20 * Root shell is assumed throughout
21 * Code blocks are [https://en.wikipedia.org/wiki/Idempotent idempotent]
25 Very minor adjustments needed for other distros. Help expand this list.
26 * Mediawiki 1.27 & 1.28
27 * Debian 8 + backports
29 * Debian testing (last tested Aug 7, 2016)
31 Pre 5/2016 revisions ran Mediawiki 1.23, tested on Fedora 20 and Ubuntu 14.04.
35 '''Getting a Server & a Domain'''
37 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.
41 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.
43 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]]
45 == Setup Guide Configuration ==
48 # Save the code in this section to a file (~/mw_vars is suggested)
49 # Source it at the beginning of scripts containing later commands
50 # Source it from your .bashrc file while you are setting up Mediawiki
52 '''Requires customization:'''
53 <source lang="bash" type="example">
54 # Replace REPLACE_ME as appropriate
56 export mwdescription="REPLACE_ME" # eg. Opinionated Free Software Wiki
58 # username/pass of the first wiki admin user
59 export wikiuser="REPLACE_ME"
60 export wikipass=REPLACE_ME
62 # root password for the mysql database
63 export dbpass=REPLACE_ME
65 export mwdomain=REPLACE_ME # domain name. for this site, it's ofswiki.org
67 # customize these questions. Try not to have the answer be a word in the question.
69 if ! grep -Fx '$localSettingsQuestyQuestions = array (' $mwc; then
71 $localSettingsQuestyQuestions = array (
72 "What is the name of the wiki software this site (and wikipedia) uses?" => "Mediawiki",
73 "REPLACE_ME with a question" => "REPLACE_ME with an answer"
79 # The rest of this section will work fine with no changes.
81 # git branch for mediawiki + extensions.
82 # This guide has only been tested with 1_28.
83 # branch names: https://git.wikimedia.org/branches/mediawiki%2Fcore.git
84 export mw_branch=REL1_28
86 # As set by gui installer when choosing cc by sa.
87 export mw_RightsUrl='https://creativecommons.org/licenses/by-sa/4.0/'
88 export mw_RightsText='Creative Commons Attribution-ShareAlike'
89 export mw_RightsIcon='$wgScriptPath/resources/assets/licenses/cc-by-sa.png'
91 # Alphanumeric site name for pywikibot.
92 # Here we use the domain minus the dots, which should work fine without changing.
93 export mwfamily=${mwdomain//./}
94 # install path for mediawiki. This should work fine.
95 export mw=/var/www/$mwdomain/html/w
98 # wiki sender address / wiki & wiki server contact email.
99 # see email section for more info on email
100 export mw_email="admin@$mwdomain"
103 mwc="$mw/LocalSettings.php"
106 == Download this page and run it ==
108 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.
110 ''' Requires manual step: inspect output file: /tmp/mw-setup, then run it'''
111 <source lang="bash" type="example">
112 start=' *<source lang="bash"> *'
114 ruby <<'EOF' | sed -rn "/^$start$/,/^$end$/{s/^$start|$end$/# \0/;p} > /tmp/mw-setup"
116 puts JSON.parse(`curl 'https://ofswiki.org/w/api.php?\
117 action=query&titles=Mediawiki_Setup_Guide&prop=revisions&rvprop=content&\
118 format=json'`.chomp)['query']['pages'].values[0]['revisions'][0]['*']
120 chmod +x /tmp/mw-setup
123 == Required Bash Functions ==
125 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.
128 # identify if this is a debian based distro
129 isdeb() { command -v apt &>/dev/null; }
130 # tee unique. append each stdin line if it does not exist in the file
134 for line in "${MAPFILE[@]}"; do
135 grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line"
139 # get and reset an extension/skin repository, and enable it
142 local original_pwd="$PWD"
144 local re='[^/]*/[^/]*$'
145 [[ $url =~ $re ]] ||:
146 target=$mw/${BASH_REMATCH[0]}
147 if [[ ! -e $target/.git ]]; then
148 git clone $url $target
150 if ! cd $target; then
151 echo "mw-ext error: failed cd $target";
155 git checkout -qf origin/$mw_branch || git checkout -qf origin/master
163 mw-clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/$ext
164 if [[ -e $mw/ext/$ext/extension.json ]]; then
165 # new style extension. remove old style declaration
166 sed -i --follow-symlinks '#^require_once( "\\\$IP/extensions/\$ext/\$ext\.php" );#d' $mwc
168 wfLoadExtension( '$ext' );
172 require_once( "\$IP/extensions/$ext/$ext.php" );
176 # --quick is quicker than default flags,
177 # but still add a sleep to make sure everything works right
178 sudo -u $apache_user php $mw/maintenance/update.php -q --quick; sleep 1
182 mw-clone https://gerrit.wikimedia.org/r/p/mediawiki/skins/$skin
183 sed -i --follow-symlinks '/^wfLoadSkin/d' $mwc
184 sed -i --follow-symlinks '/^\$wgDefaultSkin/d' $mwc
186 \$wgDefaultSkin = "${skin,,*}";
187 wfLoadSkin( '$skin' );
189 sudo -u $apache_user php $mw/maintenance/update.php -q --quick; sleep 1
192 if command -v apt &>/dev/null; then
200 == Install Mediawiki Dependencies ==
202 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.
204 [[mediawikiwiki:Main Page|Mediawiki Main Page]]: the beginning of the official docs.
206 [[mediawikiwiki:Manual:Installation_requirements|Manual:Installation_requirements]]: Overview of installation requirements.
208 Note, this guide needs a little adjustment before it will work with php7.0: make sure settings are still valid, update ini path.
213 # From here on out, exit if a command fails.
214 # This will prevent us from not noticing an important failure.
215 # We recommend setting this for the entire installation session.
216 # If you are running commands interactively, it might be best to
217 # put it in your ~/.bashrc temporarily.
219 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
224 # https://www.mediawiki.org/wiki/Manual:Running_MediaWiki_on_Ubuntu
226 DEBIAN_FRONTEND=noninteractive apt-get install -y imagemagick
227 if apt-get install -s mediawiki &>/dev/null; then
228 # mediawiki is packaged in jessie backports.
229 DEBIAN_FRONTEND=noninteractive apt-get -y install php5-apcu mediawiki
231 # https://www.mediawiki.org/wiki/Manual:Installation_requirements
232 if apt-get install -s php7.0 &>/dev/null; then
233 # note, 7.0 is untested by the editor here, since it's not
234 # available in debian 8. it's listed as supported
235 # in the mediawiki page.
236 # noninteractive to avoid mysql password prompt.
237 DEBIAN_FRONTEND=noninteractive apt-get install -y apache2 \
238 default-mysql-server \
239 php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-xml \
240 php7.0-apcu php7.0-mbstring
242 # note: mbstring is recommended, but it's not available for php5 in
244 DEBIAN_FRONTEND=noninteractive apt-get install -y apache2 \
245 default-mysql-server \
246 php5 php5-mysql libapache2-mod-php5 php5-apcu
249 service apache2 restart
252 # fedora deps are missing a database, so some is translated from debian packages
253 yum -y install mediawiki ImageMagick php-mysqlnd php-pecl-apcu mariadb-server
255 systemctl restart mariadb.service
256 systemctl enable mariadb.service
257 systemctl enable httpd.service
258 systemctl restart httpd.service
262 # slightly different depending on if we already set the root pass
263 if echo exit|mysql -u root -p"$dbpass"; then
264 # answer interactive prompts:
265 # mysql root pass, change pass? no, remove anon users? (default, yes)
266 # disallow remote root (default, yes), reload? (default, yes)
267 echo -e "$dbpass\nn\n\n\n\n" | mysql_secure_installation
269 # I had 1 less newline at the start when doing ubuntu 14.04,
270 # compared to debian 8, so can't say this is especially portable.
271 # It won't hurt if it fails.
272 echo -e "\n\n$dbpass\n$dbpass\n\n\n\n\n" | mysql_secure_installation
277 '''Skippable notes'''
280 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.
283 Additional packages rational
284 * ImageMagick is [https://www.mediawiki.org/wiki/Manual:Image_administration#Image_thumbnailing recommended].
285 * Gui install and [[mediawikiwiki:Manual:Cache]] recomend the apc package.
286 * 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.
288 == Install Mediawiki ==
291 Here, we [[mediawikiwiki:Download_from_Git]], or reset our installation if it is already there, and create the wiki database. [[mediawikiwiki:Manual:Installing_MediaWiki]]
296 # this will just fail if it already exists which is fine
297 if [[ ! -e .git ]]; then
298 git clone https://gerrit.wikimedia.org/r/p/mediawiki/core.git .
300 # to see available branches: https://www.mediawiki.org/wiki/Version_lifecycle
303 git checkout -f origin/$mw_branch
305 # Get the php libraries wmf uses. Based on:
306 # https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries
307 if [[ ! -e vendor/.git ]]; then
308 git clone https://gerrit.wikimedia.org/r/p/mediawiki/vendor.git
311 git checkout -f origin/$mw_branch
314 # Drop any previous database which may have been installed while testing.
315 # If upgrading, we should have a db backup which will get restored.
316 # https://www.mediawiki.org/wiki/Manual:Upgrading
317 mysql -u root -p$dbpass <<'EOF' ||:
318 drop database my_wiki;
321 php $mw/maintenance/install.php --pass $wikipass --scriptpath /w \
322 --dbuser root --dbpass $dbpass "$mwdescription" "$wikiuser"
324 # lock down the wiki to only the initial owner until anti-spam measures are put in place
325 # limit edits to registered users
326 $wgGroupPermissions['*']['edit'] = false;
327 # don't allow any account creation
328 $wgGroupPermissions['*']['createaccount'] = false;
333 Note: When testing, you may need to clear the apc cache to see changes take effect in the browser. Simplest solution is
334 just restart apache. http://stackoverflow.com/questions/911158/how-to-clear-apc-cache-entries
336 ''' Skippable Notes'''
338 If we wanted to reset our installation, but leave the extension repositories alone, alter the command above to be <code>git clean -fxd</code>
340 '''Rational for choosing git sources'''
342 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.
344 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.
346 == Configure Apache ==
348 Note, non-debian based installs: modify instructions below to use /etc/httpd/conf.d/$mwdomain.conf, and don't run a2ensite.
350 I use scripts I maintains separately to setup Let's Encrypt certificates and apache config: (url pending).
352 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.
354 '''Not for production:'''
355 <source lang="bash" type="example">
356 teeu /etc/hosts<<<"127.0.0.1 $mwdomain"
359 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:
361 '''Optional & requires additional steps:'''
362 <source lang="bash" type="example">
363 git clone https://github.com/certbot/certbot
365 ./certbot-auto apache
366 cd /etc/apache/sites-available
367 mv 000-default-le-ssl.conf $mwdomain.conf
368 rm ../sites-enabled/000-default-le-ssl.conf
369 # edit $mwdomain.conf, so documentroot is /var/www/$mwdomain/html
370 # and ServerName is $mwdomain
371 a2ensite $mwdomain.conf
373 Then, copy the input to apache-site below and insert it into the apache config.
375 Here, we use some scripts automate setting up the Let 's Encrypt cert and
381 git_site=https://iankelling.org/git
382 git clone $git_site/acme-tiny-wrapper
386 acme-tiny-wrapper/acme-tiny-wrapper -t $mwdomain
388 git clone $git_site/basic-https-conf
390 ServerAdmin $mw_email
392 # make the site's root url go to our main page
393 RewriteRule ^/?wiki(/.*)?\$ %{DOCUMENT_ROOT}/w/index.php [L]
394 # use short urls https://www.mediawiki.org/wiki/Manual:Short_URL
395 RewriteRule ^/*\$ %{DOCUMENT_ROOT}/w/index.php [L]
397 find -L $(readlink -f $mw) -name .htaccess \
398 | while read line; do
399 echo -e "<Directory ${line%/.htaccess}>\n $(< $line)\n</Directory>";
401 } | basic-https-conf/apache-site -r ${mw%/*} - $mwdomain
406 Now mediawiki should load in your browser at $mwdomain .
408 Allow proper search bots and internet archiver bots, via [[Mediawiki:Robots.txt]],
409 and install the default skin.
412 dd of=$mw/../robots.txt <<'EOF'
415 User-agent: ia_archiver
421 '''Skippable Notes'''
423 This section assumes we are redirecting www to a url without www.
425 [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.
427 == Mediawiki Settings ==
429 Overall reference: [[mediawikiwiki:Manual:Configuration_settings]].
431 Settings which the gui setup prompts for but aren't set by the automated install script.
434 \$wgServer = "https://$mwdomain";
435 \$wgDBserver = "localhost";
436 \$wgRightsUrl = "$mw_RightsUrl";
437 \$wgRightsText = "$mw_RightsText";
438 \$wgRightsIcon = "$mw_RightsIcon";
441 Settings I recommend which are different than the defaults.
444 \$wgPasswordSender = "$mw_email";
445 \$wgEmergencyContact = "$mw_email";
446 \$wgEnotifUserTalk = true; # UPO
447 \$wgEnotifWatchlist = true; # UPO
448 \$wgMainCacheType = CACHE_ACCEL;
449 \$wgEnableUploads = true;
450 \$wgUseInstantCommons = true;
457 # from https://www.mediawiki.org/wiki/Manual:Short_URL
458 $wgArticlePath = "/wiki/$1";
460 # https://www.mediawiki.org/wiki/Manual:Combating_spam
461 # check that url if our precautions don't work
462 # not using nofollow is good practice, as long as we avoid spam.
463 $wgNoFollowLinks = false;
464 # Allow user customization.
465 $wgAllowUserCss = true;
467 # use imagemagick over GD
468 $wgUseImageMagick = true;
472 # https://www.mediawiki.org/wiki/Manual:Configuring_file_uploads
473 # Increase from default of 2M to 100M.
474 # This will at least allow high res pics etc.
475 php_ini=$(php -r 'echo(php_ini_loaded_file());')
476 sed -i --follow-symlinks 's/^\(upload_max_filesize\|post_max_size\)\b.*/\1 = 100M/' $php_ini
478 service apache2 restart
480 systemctl restart httpd.service
483 # if you were to install as a normal user, you would need this for images
484 # sudo usermod -aG $apache_user $USER
486 # this doesn't propogate right away
487 chgrp -R $apache_user $mw/images
488 chmod -R g+w $mw/images
491 Style settings. Omit to use a different style.
495 #$wgFooterIcons = null;
497 # Make the toolbox go into the drop down.
499 if ! git remote show ian-kelling &>/dev/null; then
500 git remote add ian-kelling https://iankelling.org/git/forks/Vector
502 git fetch ian-kelling
503 git checkout ian-kelling/${mw_branch}-toolbox-in-dropdown
506 == Install and Configure Mediawiki Extensions ==
508 When installing extensions on a wiki with important content, backup first as a precaution.
510 ''' Extensions with no configuration needed '''
516 | [[mediawikiwiki:Extension:Cite|Extension:Cite]]
517 | Have references in footnotes.
519 | [[mediawikiwiki:Extension:CiteThisPage|Extension:CiteThisPage]]
520 | Ability to generate citations to pages in a variety of styles.
522 | [[mediawikiwiki:Extension:CSS|Extension:CSS]]
523 | Allows CSS stylesheets to be included in specific articles
525 | [[mediawikiwiki:Extension:Echo|Extension:Echo]]
526 | Notification subsystem for usage by other extensions
528 | [[mediawikiwiki:Extension:Gadgets|Extension:Gadgets]]
529 | UI extension system for users
531 | [[mediawikiwiki:Extension:ImageMap|Extension:ImageMap]]
532 | Links for a region of an image
534 | [[mediawikiwiki:Extension:Interwiki|Extension:Interwiki]]
535 | Tool for nice links to other wikis
537 | [[mediawikiwiki:Extension:News|Extension:News]]
538 | Embed or rss recent changes
540 | [[mediawikiwiki:Extension:Nuke|Extension:Nuke]]
541 | Mass delete of pages, in the case of spam
543 | [[mediawikiwiki:Extension:ParserFunctions|Extension:ParserFunctions]]
544 | Useful for templates
546 | [[mediawikiwiki:Extension:Poem|Extension:Poem]]
547 | Useful for formatting things various ways
549 | [[mediawikiwiki:Extension:SyntaxHighlight_GeSHi|Extension:SyntaxHighlight_GeSHi]]
550 | Source code highlighting
552 | [[mediawikiwiki:Extension:Variables|Extension:Variables]]
553 | Define per-page variables
557 mw-ext Cite CiteThisPage CSS Echo Gadgets ImageMap Interwiki News \
558 Nuke ParserFunctions Poem SyntaxHighlight_GeSHi Variables
562 ''' [[mediawikiwiki:Extension:AntiSpoof|Extension:AntiSpoof]]: Disallow usernames with unicode trickery to look like existing names'''
566 # recommended setup script to account for existing users
567 sudo -u $apache_user php $mw/extensions/AntiSpoof/maintenance/batchAntiSpoof.php
571 ''' [[mediawikiwiki:CheckUser|Extension:CheckUser]]: Get ip addresses from inside mediawiki so you can ban users'''
573 On <= 1.27, requires special install steps or we can get into a bad state. Add a sleep like the default of update.php to avoid errors.
576 if [[ -e $mw/extensions/CheckUser/install.php ]]; then
577 sudo -u $apache_user php $mw/extensions/CheckUser/install.php; sleep 1
582 '''[[mediawikiwiki:Extension:Wikidiff2|Extension:Wikidiff2]]: Faster and international character supported page diffs'''
584 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.
587 apt-get -y install php-wikidiff2
589 $wgExternalDiffEngine = 'wikidiff2';
591 dir=$(dirname $(php -r 'echo(php_ini_loaded_file());'))/../apache2/conf.d
592 ln -sf ../../mods-available/wikidiff2.ini $dir
593 service apache2 restart
598 ''' [[mediawikiwiki:Extension:Math|Extension:Math]] Display equations'''
602 # php5-curl according to Math readme
605 if ! apt-get -s install $curl_pkg &>/dev/null; then
608 apt-get -y install latex-cjk-all texlive-latex-extra texlive-latex-base \
609 ghostscript imagemagick ocaml $curl_pkg make
611 # todo, php5-curl equivalent on fedora
612 yum -y install texlive-cjk ghostscript ImageMagick texlive ocaml
614 service apache2 restart
616 cd $mw/extensions/Math/math; make # makes texvc
617 cd $mw/extensions/Math/texvccheck; make
620 # Enable MathJax as rendering option
621 $wgUseMathJax = true;
622 # Enable LaTeXML as rendering option
623 $wgMathValidModes[] = 'latexml';
624 # Set LaTeXML as default rendering option, because it is nicest
625 $wgDefaultUserOptions['math'] = 'latexml';
629 '''Skippable notes'''
631 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.
634 ''' [[mediawikiwiki:Extension:SpamBlacklist|Extension:SpamBlacklist]]: Import/create IP blacklists, mainly for spam'''
638 if ! grep -F '$wgSpamBlacklistFiles = array(' $mwc &>/dev/null; then
640 $wgEnableDnsBlacklist = true;
641 $wgDnsBlacklistUrls = array( 'xbl.spamhaus.org', 'dnsbl.tornevall.org' );
643 ini_set( 'pcre.backtrack_limit', '10M' );
644 $wgSpamBlacklistFiles = array(
645 "[[m:Spam blacklist]]",
646 "http://en.wikipedia.org/wiki/MediaWiki:Spam-blacklist"
652 ''' [[mediawikiwiki:Extension:TitleBlacklist|Extension:TitleBlacklist]]: Anti-spam '''
655 mw-ext TitleBlacklist
656 if ! grep -F '$wgTitleBlacklistSources = array(' $mwc &>/dev/null; then
658 $wgTitleBlacklistSources = array(
661 'src' => 'MediaWiki:Titleblacklist',
665 'src' => 'http://meta.wikimedia.org/w/index.php?title=Title_blacklist&action=raw',
672 ''' [[mediawikiwiki:Extension:WikiEditor|Extension:WikiEditor]]: Editing box extras and a fast preview tab '''
677 # Enable Wikieditor by default
678 $wgDefaultUserOptions['usebetatoolbar'] = 1;
679 $wgDefaultUserOptions['usebetatoolbar-cgd'] = 1;
681 # Display the Preview and Changes tabs
682 $wgDefaultUserOptions['wikieditor-preview'] = 1;
686 ''' [[mediawikiwiki:CategoryTree|Extension:CategoryTree]]: Enables making nice outlines of pages in a category'''
690 # Mediawiki setting dependency for CategoryTree
695 ''' [[mediawikiwiki:Extension:AbuseFilter|Extension:AbuseFilter]]: Complex abilities to stop abuse '''
697 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:
701 $wgGroupPermissions['sysop']['abusefilter-modify'] = true;
702 $wgGroupPermissions['*']['abusefilter-log-detail'] = true;
703 $wgGroupPermissions['*']['abusefilter-view'] = true;
704 $wgGroupPermissions['*']['abusefilter-log'] = true;
705 $wgGroupPermissions['sysop']['abusefilter-private'] = true;
706 $wgGroupPermissions['sysop']['abusefilter-modify-restricted'] = true;
707 $wgGroupPermissions['sysop']['abusefilter-revert'] = true;
711 '''[[mediawikiwiki:Extension:ConfirmEdit|Extension:ConfirmEdit]]: Custom Captcha'''
713 Uses captchaArray defined in mw_vars.
719 wfLoadExtension( 'ConfirmEdit/QuestyCaptcha' );
720 $wgCaptchaClass = 'QuestyCaptcha';
721 # only captcha on registration
722 $wgGroupPermissions['user' ]['skipcaptcha'] = true;
723 $wgGroupPermissions['autoconfirmed']['skipcaptcha'] = true;
725 if ! grep -Fx 'foreach ( $localSettingsQuestyQuestions as $key => $value ) {' $mwc; then
727 foreach ( $localSettingsQuestyQuestions as $key => $value ) {
728 $wgCaptchaQuestions[] = array( 'question' => $key, 'answer' => $value );
734 Enable account creation that we initially disabled.
736 sed -i --follow-symlinks "/\\\$wgGroupPermissions\\['\\*'\\]\\['createaccount'\\] = false;/d" $mwc
739 == Additional Configuration with Pywikibot ==
741 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.
744 '''Pywikibot Install'''
746 [[mediawikiwiki:Manual:Pywikibot/Installation|Manual:Pywikibot/Installation]]
750 if [[ ! -e ~/pywikibot/.git ]]; then
751 git clone --recursive \
752 https://gerrit.wikimedia.org/r/pywikibot/core.git ~/pywikibot
761 '''Pywikibot Configuration'''
763 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]]
768 dd of=user-config.py <<EOF
770 usernames["$mwfamily"]['en'] = u'$wikiuser'
772 console_encoding = 'utf-8'
773 password_file = "secretsfile"
776 dd of=secretsfile <<EOF
777 ("$wikiuser", "$wikipass")
780 # it won't overrwrite an existing file. Remove if if one exists
781 rm -f pywikibot/families/${mwfamily}_family.py
783 apt-get install -y python-requests
785 yum -y install python-requests
788 python generate_family_file.py https://$mwdomain/wiki/Main_Page "$mwfamily"
790 # Note, this needed only for ssl site
791 tee -a pywikibot/families/${mwfamily}_family.py<<'EOF'
792 def protocol(self, code):
798 '''Pywikibot Script'''
800 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]].
805 dd of=scripts/${mwfamily}_setup.py<<EOF
809 site = pywikibot.Site()
811 page = pywikibot.Page(site, p)
813 #force is for some anti-bot thing, not necessary in my testing, but might as well include it
814 page.save(force=True)
816 # Small/medium noncommercial wiki should be fine with no privacy policy
817 # based on https://www.mediawiki.org/wiki/Manual:Footer
818 x("MediaWiki:Privacy")
820 # licenses for uploads. Modified from the mediawiki's wiki
821 x("MediaWiki:Licenses", u"""* Same as this wiki's text (preferred)
822 ** CC BY-SA or GFDL| Creative Commons Attribution ShareAlike or GNU Free Documentation License
824 ** Unknown_copyright|I don't know exactly
825 ** PD|PD: public domain
826 ** CC BY|Creative Commons Attribution
827 ** CC BY-SA|Creative Commons Attribution ShareAlike
828 ** GFDL|GFDL: GNU Free Documentation License
829 ** GPL|GPL: GNU General Public License
830 ** LGPL|LGPL: GNU Lesser General Public License""")
831 x("MediaWiki:Copyright", '$mw_license')
832 x("MediaWiki:Mainpage-description", "$mwdescription")
836 # The rest of the settings are for the site style
838 # Remove various clutter
839 x("MediaWiki:Lastmodifiedat")
840 x("MediaWiki:Disclaimers")
841 x("MediaWiki:Viewcount")
842 x("MediaWiki:Aboutsite")
843 # remove these lines from sidebar
844 # ** recentchanges-url|recentchanges
845 # ** randompage-url|randompage
847 x("MediaWiki:Sidebar", """* navigation
848 ** mainpage|mainpage-description
854 # helpfull doc: https://www.mediawiki.org/wiki/Manual:Interface/Sidebar
855 x("mediawiki:Common.css", """/* adjust sidebar to just be home link and up top */
856 /* panel width increased to fit full wiki name. */
857 div#mw-panel { top: 10px; padding-top: 0em; width: 20em }
858 div#footer, #mw-head-base, div#content { margin-left: 1em; }
859 #left-navigation { margin-left: 1em; }
862 /* logo, and toolbar hidden */
863 #p-logo, #p-tb.portal {
867 /* make the font size smaller for the misc stuff */
875 div#mw-content-text {
881 # this can spam a warning, so uniq it
882 python pwb.py ${mwfamily}_setup |& uniq
886 ''' Skippable Notes '''
888 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.
890 Family name, and all its duplicattions documented as supposed to be $wgSitename, but it works fine using any name.
892 == Automatic Backups ==
894 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.
896 <source lang="bash" type="backup">
897 backup_script=/etc/cron.daily/mediawiki_backup
898 sudo dd of=$backup_script <<'EOFOUTER'
900 # if we get an error, keep going but return it at the end
902 trap 'last_error=$?' ERR
904 # No strict because the host is likely not named the same as
906 ssh="ssh -oStrictHostKeyChecking=no"
907 logfile=/var/log/${mwdomain}_backup.log
909 echo "#### starting backup at $(date) ####"
910 $ssh root@$mwdomain <<ENDSSH
913 \$wgReadOnly = 'Dumping Database, Access will be restored shortly';
915 mkdir -p ~/wiki_backups
916 mysqldump -p$dbpass --default-character-set=binary my_wiki > ~/wiki_backups/wiki_db_backup
917 sed -i '\$ d' $mwc # delete read only setting
919 # add no strict option to the defaults
921 rdiff() { rdiff-backup --remote-schema "$ssh -C %s rdiff-backup --server" "$@"; }
923 rdiff root@$mwdomain::/root/wiki_backups ~/backup/${mwdomain}_wiki_db_backup
924 rdiff root@$mwdomain::$mw ~/backup/${mwdomain}_wiki_file_backup
926 echo "=== ending backup at $(date) ===="
928 if [[ $last_error != 0 ]]; then
929 echo "backup for $mwdomain failed. See $logfile"
934 sudo chmod +x $backup_script
937 '''Optional & requires additional steps'''
939 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].
941 == Restoring Backups ==
943 '''Whenever you implement a backup system, you should test that restoring the backup works.'''
945 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.
947 To test a backup restore:
948 # Do a backup of your wiki with some content in it, as described in the previous section
949 # Move your mediawiki install directory, or setup Mediawiki on a new machine
950 # Re-execute the mediawiki install steps
951 # Change REPLACE_ME in the code below (as in the backup section so you get the right variables),
952 # Execute the code on the backup machine.
955 <source lang="bash" type="example">
958 restore="rdiff-backup --force -r now"
959 $restore ~/backup/${mwdomain}_wiki_file_backup /tmp/wiki_file_restore
960 $restore ~/backup/${mwdomain}_wiki_db_backup /tmp/wiki_db_restore
961 o=-oStrictHostKeyChecking=no
962 scp $o -r /tmp/wiki_file_restore/images/* root@$mwdomain:$mw/images
963 scp $o -r /tmp/wiki_db_restore root@$mwdomain:/tmp
964 ssh $o root@$mwdomain <<EOF
966 chmod -R g+w $mw/images
967 chgrp -R www-data $mw/images
968 mysql -u root -p$dbpass my_wiki < /tmp/wiki_db_restore/wiki_db_backup
969 php $mw/maintenance/update.php
973 Then browse to your wiki and see if everything appears to work.
977 Subscribe to get release and security announcements [https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce MediaWiki-announce].
979 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).
981 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]]
983 Minor updates script:
985 s=/etc/cron.daily/mediawiki_update
990 for dir in extensions/* skins/* $mw; do
991 [[ -d $dir ]] || continue
993 branch=$(git describe --all)
994 branch=${branch#remotes/}
996 new_head=$(git rev-parse $branch)
997 log=$(git log HEAD..$new_head)
1002 git checkout -q $new_head
1005 php $mw/maintenance/update.php -q --quick
1010 == Upgrading Major Versions ==
1012 Reference documentation is at [[mediawikiwiki:Manual:Upgrading]]
1016 # Read the "Upgrade notices for MediaWiki administrators" on the upgrade version and any skipped versions at [[mediawikiwiki:Version_lifecycle]].
1017 # Setup a blank test wiki with the new version.
1018 # Backup the old database, restore it to the new wiki, run php maintenance/update.php.
1019 # If everything looks good, repeat and replace the old wiki with the new one.
1023 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:
1025 * Find new spam quickly, revert it & ban the user.
1026 ** 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."
1027 ** 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].
1028 * Require registration to edit, and a custom captcha question on registration.
1029 * Install all non-user inhibiting anti-spam extensions / settings that take a reasonable amount of time to figure out.
1031 == Choosing Extensions ==
1033 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.
1035 Here are brief descriptions of extensions that are part of distributions and why they were rejected for this wiki.
1037 {| class="wikitable"
1039 | '''InputBox''' || Add html forms to pages. Can't imagine using it. Would install if I did.
1041 | '''Pdfhandler''' || Gallery of pages from a pdf file. Can't imagine using it. Would install if I did.
1043 | '''Footnote''' || deprecated in newer versions
1045 | '''NewUserNotif''' || Send me a notification when a user registers. Seems like an excessive notification.
1047 | '''NewestPages''' || A page creation history that doesn't expire like recent-changes. Meh
1049 | '''RSSReader''' || Embed an rss feed. Can't imagine using it. Would install if I did.
1051 | '''Openid''' || Poor UI. 2 pages & 2 links <login> <login with openid> which is confusing & ugly.
1053 | '''Validator''' || dependency of of semantic
1055 | '''Semantic''' || Seems like a lot of trouble around analyzing kinds of data which my wiki will not have.
1057 | '''wikicalendar''' || Make a calendar of events etc. Can't imagine using it. Would install if I did.
1062 ''' Web Analytics Software '''
1064 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.
1066 ''' Mediawiki Documentation Quality '''
1068 Overall the documentation is good, but like wikipedia, it depends.
1070 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.
1072 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].
1075 '''Bash here documents, EOF vs 'EOF' '''
1077 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.
1080 ''' Mediawiki automation tools survey 7/2014 '''
1083 * https://github.com/ianweller/mw
1084 * http://search.cpan.org/~markj/WWW-Mediawiki-Client/bin/mvs
1085 * https://github.com/alexz-enwp/wikitools 3000 lines of code, no response to a bug reports in 2/2014
1087 Getting basic maintenance
1088 * https://github.com/mwclient/mwclient 2000 lines of code
1090 Actively developed, used by wikimedia foundation a lot.
1091 * [[mediawikiwiki:Manual:Pywikibot]]
1094 ''' Troubleshooting Errors '''
1096 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]]
1100 This page and this wiki is licensed under cc-by-sa 4.0.
1101 This means the code is compatible with gplv3.
1103 == todo list for this page ==
1105 * Check if there are any new default extensions 1.28 which I haven't evaluated.
1106 * Test for any new config values set by the 1.28 gui install method.
1107 * Get Visual editor extension.
1108 * Don't require registration for edits