Difference between revisions of "Install MediaWiki"
(41 intermediate revisions by the same user not shown) | |||
Line 13: | Line 13: | ||
Add to the new file: | Add to the new file: | ||
− | + | location /wiki/ { | |
− | location /wiki/ { | + | rewrite ^/wiki/([^?]*)(?:\?(.*))? /wiki/index.php?title=$1&$2 last; |
− | + | ||
− | + | location ~* ^/images/.*.(html|htm|shtml|php|js)$ { | |
− | + | types { } | |
− | + | default_type text/plain; | |
− | + | } | |
− | + | ||
− | + | location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { | |
− | + | try_files $uri /wiki/index.php; | |
− | + | expires max; | |
− | + | log_not_found off; | |
− | + | } | |
− | + | ||
− | + | location ~ (index|load|api).*\.php$ { | |
− | + | include global-configs/php.conf; | |
− | + | } | |
− | + | ||
− | + | location ~ /cache/ { deny all; } | |
− | + | ||
− | + | location ~ \.php$ { deny all; } | |
− | + | } | |
− | } | ||
− | |||
username@servername:~$ sudo nano /etc/nginx/package-configs/mediawiki_https.conf | username@servername:~$ sudo nano /etc/nginx/package-configs/mediawiki_https.conf | ||
Add to the new file: | Add to the new file: | ||
− | |||
− | |||
− | |||
− | + | location /wiki/ { | |
− | + | rewrite ^/wiki/([^?]*)(?:\?(.*))? /wiki/index.php?title=$1&$2 last; | |
− | + | ||
− | + | location ~* ^/images/.*.(html|htm|shtml|php|js)$ { | |
− | + | types { } | |
− | + | default_type text/plain; | |
− | + | } | |
− | + | ||
− | + | location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { | |
− | + | try_files $uri /wiki/index.php; | |
− | + | expires max; | |
− | + | log_not_found off; | |
− | + | } | |
− | + | ||
− | + | location ~ (index|load|api).*\.php$ { | |
− | + | include global-configs/php_https.conf; | |
− | + | } | |
− | + | ||
− | } | + | location ~ /cache/ { deny all; } |
− | + | ||
+ | location ~ \.php$ { deny all; } | ||
+ | } | ||
=== Sites-available file === | === Sites-available file === | ||
Line 73: | Line 70: | ||
In the HTTP server block, add: | In the HTTP server block, add: | ||
− | + | ||
− | + | include package-configs/mediawiki.conf; | |
− | |||
In the HTTPS server block, add: | In the HTTPS server block, add: | ||
− | + | ||
− | + | include package-configs/mediawiki_https.conf; | |
− | </ | + | |
+ | For the categories feature of MediaWiki to function properly, it is important require nginx to serve the domain as either only <tt>example.com</tt> or only one subdomain, such as <tt>www.example.com</tt>. The <code>sites-available</code> file can be edited as discussed in the [[Install nginx#Redirecting_subdomains|nginx installation article]]. | ||
==== 404 error_page ==== | ==== 404 error_page ==== | ||
Note that if the <code>error_page</code> directive is being used to redirect 404 errors, be sure it is in the <code>location /</code> block: | Note that if the <code>error_page</code> directive is being used to redirect 404 errors, be sure it is in the <code>location /</code> block: | ||
− | + | ||
− | location / { | + | location / { |
− | + | try_files $uri $uri/ =404; | |
− | + | error_page 404 /404.html; | |
− | } | + | } |
− | |||
If it is directly in the <code>server</code> block, MediaWiki will not attempt to create pages when a wrong page is requested. | If it is directly in the <code>server</code> block, MediaWiki will not attempt to create pages when a wrong page is requested. | ||
Line 108: | Line 104: | ||
Mediawiki will require a few packages to be installed to run: | Mediawiki will require a few packages to be installed to run: | ||
− | username@servername:~$ sudo aptitude install imagemagick php5-intl | + | username@servername:~$ sudo aptitude install imagemagick php5.6-intl |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Test nginx and restart services: | Test nginx and restart services: | ||
Line 121: | Line 110: | ||
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | ||
nginx: configuration file /etc/nginx/nginx.conf test is successful | nginx: configuration file /etc/nginx/nginx.conf test is successful | ||
− | username@servername:~$ sudo service php5-fpm restart | + | username@servername:~$ sudo service php5.6-fpm restart |
username@servername:~$ sudo service nginx reload | username@servername:~$ sudo service nginx reload | ||
− | + | ||
+ | The [//www.mediawiki.org/wiki/Version_lifecycle MediaWiki project offers two different release types]: major releases every six months that are immediately retired upon the next release and LTS releases every 2 years, that are supported for an additional year after the next release. Currently the LTS version is 1.35, which will be supported until September, 2023. | ||
Download Mediawiki: | Download Mediawiki: | ||
− | username@servername:~$ wget <nowiki>https://releases.wikimedia.org/mediawiki/1. | + | username@servername:~$ wget <nowiki>https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.5.tar.gz</nowiki> |
− | username@servername:~$ tar -xzf mediawiki-1. | + | username@servername:~$ tar -xzf mediawiki-1.35.5.tar.gz |
− | username@servername:~$ mv mediawiki-1. | + | username@servername:~$ mv mediawiki-1.35.5/ /var/www/example.com/public/wiki |
− | username@servername:~$ find /var/www/example.com/public/wiki/ -type d | xargs chmod 775 | + | username@servername:~$ find /var/www/example.com/public/wiki/ -type d | xargs -d '\n' chmod 775 |
− | username@servername:~$ find /var/www/example.com/public/wiki/ -type f | xargs chmod 664 | + | username@servername:~$ find /var/www/example.com/public/wiki/ -type f | xargs -d '\n' chmod 664 |
username@servername:~$ sudo chown -R www-data:www-data /var/www/example.com/public/wiki/ | username@servername:~$ sudo chown -R www-data:www-data /var/www/example.com/public/wiki/ | ||
− | username@servername:~$ rm mediawiki-1. | + | username@servername:~$ rm mediawiki-1.35.5.tar.gz |
Navigate to '''secure''' <tt><nowiki>https://www.example.com/wiki</nowiki></tt> and complete the Mediawiki installation. Most admins will prefer to use the 'Authorized editors only' option under 'User rights profile:'. Select 'PHP object caching (APC, XCache or WinCache)' in the Advanced Configuration options and be sure to sign up for update notifications. | Navigate to '''secure''' <tt><nowiki>https://www.example.com/wiki</nowiki></tt> and complete the Mediawiki installation. Most admins will prefer to use the 'Authorized editors only' option under 'User rights profile:'. Select 'PHP object caching (APC, XCache or WinCache)' in the Advanced Configuration options and be sure to sign up for update notifications. | ||
Line 146: | Line 136: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | Enable < | + | Enable <syntaxhighlight lang="PHP" inline>$wgCacheDirectory</syntaxhighlight>: |
+ | |||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
$wgCacheDirectory = "$IP/cache"; | $wgCacheDirectory = "$IP/cache"; | ||
Line 166: | Line 157: | ||
$wgGroupPermissions['*']['createpage'] = false; | $wgGroupPermissions['*']['createpage'] = false; | ||
$wgGroupPermissions['*']['writeapi'] = false; | $wgGroupPermissions['*']['writeapi'] = false; | ||
+ | $wgGroupPermissions['*']['edit'] = false; | ||
$wgGroupPermissions['user']['edit'] = false; | $wgGroupPermissions['user']['edit'] = false; | ||
$wgGroupPermissions['user']['createtalk'] = false; | $wgGroupPermissions['user']['createtalk'] = false; | ||
Line 199: | Line 191: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | The < | + | The <syntaxhighlight lang="PHP" inline>*</syntaxhighlight> user group means all users, including anonymous users. |
Below that, add: | Below that, add: | ||
Line 213: | Line 205: | ||
Now paste the entire contents from the computer's text editor to the <code>LocalSettings.php</code> file on the server: | Now paste the entire contents from the computer's text editor to the <code>LocalSettings.php</code> file on the server: | ||
+ | |||
username@servername:~$ nano /var/www/example.com/public/wiki/LocalSettings.php | username@servername:~$ nano /var/www/example.com/public/wiki/LocalSettings.php | ||
Line 232: | Line 225: | ||
Add to the bottom of the file: | Add to the bottom of the file: | ||
+ | |||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
# Disables page counters | # Disables page counters | ||
Line 248: | Line 242: | ||
username@servername:~$ tar -xzf MobileFrontend-REL1_25-c193468.tar.gz | username@servername:~$ tar -xzf MobileFrontend-REL1_25-c193468.tar.gz | ||
username@servername:~$ mv MobileFrontend/ /var/www/example.com/public/wiki/extensions/ | username@servername:~$ mv MobileFrontend/ /var/www/example.com/public/wiki/extensions/ | ||
− | username@servername:~$ find /var/www/example.com/public/wiki/extensions/MobileFrontend/ -type d | xargs chmod 775 | + | username@servername:~$ find /var/www/example.com/public/wiki/extensions/MobileFrontend/ -type d | xargs -d '\n' chmod 775 |
− | username@servername:~$ find /var/www/example.com/public/wiki/extensions/MobileFrontend/ -type f | xargs chmod 664 | + | username@servername:~$ find /var/www/example.com/public/wiki/extensions/MobileFrontend/ -type f | xargs -d '\n' chmod 664 |
username@servername:~$ sudo chown -R www-data:www-data /var/www/example.com/public/wiki/extensions/MobileFrontend/ | username@servername:~$ sudo chown -R www-data:www-data /var/www/example.com/public/wiki/extensions/MobileFrontend/ | ||
username@servername:~$ rm MobileFrontend-REL1_25-c193468.tar.gz | username@servername:~$ rm MobileFrontend-REL1_25-c193468.tar.gz | ||
Line 255: | Line 249: | ||
Add to the bottom of the file: | Add to the bottom of the file: | ||
+ | |||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
# Enables MobileFrontend extension | # Enables MobileFrontend extension | ||
Line 274: | Line 269: | ||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
− | + | # Use the site's JavaScript (MediaWiki:Common.js) | |
− | + | $wgUseSiteJS = true; | |
</syntaxhighlight> | </syntaxhighlight> | ||
Navigate to <tt><nowiki>https://www.example.com/wiki/MediaWiki:Common.js</nowiki></tt> while logged in as an administrator and add the Piwik javascript code: | Navigate to <tt><nowiki>https://www.example.com/wiki/MediaWiki:Common.js</nowiki></tt> while logged in as an administrator and add the Piwik javascript code: | ||
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="JavaScript"> |
var _paq = _paq || []; | var _paq = _paq || []; | ||
_paq.push(['trackPageView']); | _paq.push(['trackPageView']); | ||
Line 325: | Line 320: | ||
=== File upload extension management === | === File upload extension management === | ||
− | Use < | + | Use <syntaxhighlight lang="PHP" inline>$wgFileExtensions</syntaxhighlight> to add file extensions available for upload by adding the following, edited as desired, to <code>LocalSettings.php</code>: |
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
Line 349: | Line 344: | ||
It will be necessary to tell nginx to serve these filetypes as files. Change the <code>try_files</code> block in both <code>mediawiki.conf</code> and <code>mediawiki_https.conf</code> to support the desired filetypes: | It will be necessary to tell nginx to serve these filetypes as files. Change the <code>try_files</code> block in both <code>mediawiki.conf</code> and <code>mediawiki_https.conf</code> to support the desired filetypes: | ||
− | + | location ~* \.(css|gif|ico|jpeg|jpg|js|png|azw|azw3|doc|docx|epub|mobi|mpp|ods|odt|pdf|ppt|pptx|xls|xlsx)$ { | |
− | + | try_files $uri /wiki/index.php; | |
− | + | expires max; | |
− | + | log_not_found off; | |
− | + | } | |
− | |||
− | |||
=== Increase Mediawiki max file upload size === | === Increase Mediawiki max file upload size === | ||
− | Mediawiki is set by default with a max upload file size of 100 MB, calculated as 1024*1024*100. To change this, in addition to necessary configuration changes in <code>nginx.conf</code> and <code>php.ini</code>, change the | + | Mediawiki is set by default with a max upload file size of 100 MB, calculated as 1024*1024*100. To change this, in addition to necessary configuration changes in [[Install_nginx#Configure_nginx|<code>nginx.conf</code>]] and [[Install_PHP#php.ini|<code>php.ini</code>]], change the [//www.mediawiki.org/wiki/Manual:$wgMaxUploadSize <syntaxhighlight lang="PHP" inline>$wgMaxUploadSize</syntaxhighlight>] parameter to other than default by adding the following to <code>LocalSettings.php</code>: |
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
Line 368: | Line 361: | ||
=== AntiSpam === | === AntiSpam === | ||
− | MediaWiki now installs with the [//www.mediawiki.org/wiki/Extension:ConfirmEdit ConfirmEdit] extension that includes [//www.mediawiki.org/wiki/Extension:QuestyCaptcha QuestyCaptcha], a configurable bot-checking tool that can be applied to specific pages, such as only the account creation page, or to every page. QustyCaptcha is still in Beta, but should work well on most installations. | + | MediaWiki now installs with the [//www.mediawiki.org/wiki/Extension:ConfirmEdit ConfirmEdit] extension that includes [//www.mediawiki.org/wiki/Extension:QuestyCaptcha QuestyCaptcha], a configurable bot-checking tool that can be applied to specific pages, such as only the account creation page, or to every page. QustyCaptcha is still in Beta, but should work well on most installations. Questions can be applied to several MediaWiki actions and is by default enabled on <code>createaccount</code>. Here is a sample configuration: |
+ | |||
+ | <syntaxhighlight lang="PHP"> | ||
+ | // Enable QuestyCaptcha | ||
+ | // Questions will appear exactly as written and answers are case-insensitive | ||
+ | // For more info see https://www.mediawiki.org/wiki/Extension:QuestyCaptcha | ||
+ | require_once( "$IP/extensions/ConfirmEdit/ConfirmEdit.php" ); | ||
+ | require_once( "$IP/extensions/ConfirmEdit/QuestyCaptcha.php"); | ||
+ | $wgCaptchaClass = 'QuestyCaptcha'; | ||
+ | $arr = array ( | ||
+ | "What was Ben Kenobi also known as?" => array('obi wan','obi-wan','obi wan kenobi','obi-wan kenobi') | ||
+ | ); | ||
+ | foreach ( $arr as $key => $value ) { | ||
+ | $wgCaptchaQuestions[] = array( 'question' => $key, 'answer' => $value ); | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === SyntaxHighlight === | ||
+ | |||
+ | The [https://www.mediawiki.org/wiki/Extension:SyntaxHighlight SyntaxHighlight] plugin is available by default but requires some configuring. | ||
+ | |||
+ | Add the following to LocalSettings.php: | ||
+ | |||
+ | <syntaxhighlight lang="PHP"> | ||
+ | wfLoadExtension( 'SyntaxHighlight_GeSHi' ); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Make the <code>pygmentize</code> binary executable: | ||
+ | |||
+ | username@servername:~$ chmod a+x /var/www/unpm.org/public/wiki/extensions/SyntaxHighlight_GeSHi/pygments/pygmentize | ||
== Upgrading MediaWiki == | == Upgrading MediaWiki == | ||
− | Upgrading MediaWiki is done through the command line. For minor version upgrades, a patch file may be made available, | + | Upgrading MediaWiki is done through the command line. For minor version upgrades, a patch file may be made available, however, due to a longstanding bug, many installations will not support upgrade via patch, thus a complete reinstall from backup is essentially performed. The best way to find the locations of an update's files and options is from the announcement email, presumably subscribed to during the mediawiki setup process, also available by subscribing to [//twitter.com/mediawiki @mediawiki] or even the [//twitter.com/unpm_org @unpm_org] account, which only retweets official announcements, and also by simply browsing through [//releases.wikimedia.org/mediawiki/ releases.wikimedia.org/mediawiki]. |
=== Maintenance mode === | === Maintenance mode === | ||
Line 387: | Line 409: | ||
$wgReadOnly="We are upgrading MediaWiki, please be patient. This wiki will be back shortly."; | $wgReadOnly="We are upgrading MediaWiki, please be patient. This wiki will be back shortly."; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== Upgrade without patch === | === Upgrade without patch === | ||
Line 416: | Line 416: | ||
==== Install new version to new directory ==== | ==== Install new version to new directory ==== | ||
− | The actual new version will depend on what version it is desired to upgrade to. All versions of MediaWiki may be found [ | + | The actual new version will depend on what version it is desired to upgrade to. All versions of MediaWiki may be found [//releases.wikimedia.org/mediawiki/ here]. |
− | username@servername:~$ wget <nowiki>https://releases.wikimedia.org/mediawiki/1. | + | username@servername:~$ wget <nowiki>https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.5.tar.gz</nowiki> |
− | username@servername:~$ tar -xzf mediawiki-1. | + | username@servername:~$ tar -xzf mediawiki-1.35.5.tar.gz -C /var/www/example.com/public/ |
− | username@servername:~$ find /var/www/example.com/public/mediawiki-1. | + | username@servername:~$ find /var/www/example.com/public/mediawiki-1.35.5/ -type d | xargs -d '\n' chmod 775 |
− | username@servername:~$ find /var/www/example.com/public/mediawiki-1. | + | username@servername:~$ find /var/www/example.com/public/mediawiki-1.35.5/ -type f | xargs -d '\n' chmod 664 |
− | username@servername:~$ sudo chown -R www-data:www-data /var/www/example.com/public/mediawiki-1. | + | username@servername:~$ sudo chown -R www-data:www-data /var/www/example.com/public/mediawiki-1.35.1/ |
− | username@servername:~$ cp -p /var/www/example.com/public/wiki/LocalSettings.php /var/www/example.com/public/mediawiki-1. | + | username@servername:~$ cp -p /var/www/example.com/public/wiki/LocalSettings.php /var/www/example.com/public/mediawiki-1.35.5/ |
− | username@servername:~$ cp -rpfu /var/www/example.com/public/wiki/extensions/* /var/www/example.com/public/mediawiki-1. | + | username@servername:~$ cp -rpfu /var/www/example.com/public/wiki/extensions/* /var/www/example.com/public/mediawiki-1.35.5/extensions/ |
− | username@servername:~$ cp -rpfu /var/www/example.com/public/wiki/images/* /var/www/example.com/public/mediawiki-1. | + | username@servername:~$ cp -rpfu /var/www/example.com/public/wiki/images/* /var/www/example.com/public/mediawiki-1.35.5/images/ |
− | username@servername:~$ cp -rpfu /var/www/example.com/public/wiki/skins/* /var/www/example.com/public/mediawiki-1. | + | username@servername:~$ cp -rpfu /var/www/example.com/public/wiki/skins/* /var/www/example.com/public/mediawiki-1.35.5/skins/ |
Note that any other additional files not a part of the MediaWiki package should also be copied to the new directory. Files that have been customized should be customized again using the file in the new installation. | Note that any other additional files not a part of the MediaWiki package should also be copied to the new directory. Files that have been customized should be customized again using the file in the new installation. | ||
==== Copy database to new database ==== | ==== Copy database to new database ==== | ||
+ | |||
+ | Before copying the database, clear pending jobs: | ||
+ | |||
+ | username@servername:~$ php /var/www/example.com/wiki/maintenance/runJobs.php | ||
Log in to phpMyAdmin as the root MySQL user. Select the database used by MediaWiki and navigate to the <tt>Operations</tt> page. Enter the name of the new database in the <tt>Copy database to:</tt> field, leaving the default selections for copying and select <tt>Go</tt> | Log in to phpMyAdmin as the root MySQL user. Select the database used by MediaWiki and navigate to the <tt>Operations</tt> page. Enter the name of the new database in the <tt>Copy database to:</tt> field, leaving the default selections for copying and select <tt>Go</tt> | ||
− | Navigate to phpMyAdmin home page and select <tt> | + | Navigate to phpMyAdmin home page and select <tt>User accounts</tt>. Click <tt>Edit privileges</tt> next to the user assigned to the original MediaWiki database. Under <tt>Database-specific privileges</tt>, select the new database in the <tt>Add privileges on the following database:</tt> drop-down menu. In the following page, click <tt>Check all</tt>, then uncheck <tt>GRANT</tt> and click <tt>Go</tt>. |
Now update the name of the database in the new <code>LocalSettings.php</code> file: | Now update the name of the database in the new <code>LocalSettings.php</code> file: | ||
− | username@servername:~$ nano /var/www/example.com/public/mediawiki-1. | + | username@servername:~$ nano /var/www/example.com/public/mediawiki-1.35.5/LocalSettings.php |
Change: | Change: | ||
Line 449: | Line 453: | ||
username@servername:~$ mkdir /var/www/example.com/backup/wiki/ | username@servername:~$ mkdir /var/www/example.com/backup/wiki/ | ||
− | username@servername:~$ mv /var/www/example.com/public/wiki /var/www/example.com/backup/wiki/mediawiki-1. | + | username@servername:~$ mv /var/www/example.com/public/wiki /var/www/example.com/backup/wiki/mediawiki-1.31.8 |
− | username@servername:~$ mv /var/www/example.com/public/mediawiki-1. | + | username@servername:~$ mv /var/www/example.com/public/mediawiki-1.35.5/ /var/www/example.com/public/wiki |
− | username@servername:~ | + | username@servername:~$ php /var/www/example.com/public/wiki/maintenance/update.php |
− | |||
− | |||
Navigate to the wiki and verify it is functioning properly. If it is not functioning properly and the problem cannot repaired, then restore the archived version until the update can be successfully performed. | Navigate to the wiki and verify it is functioning properly. If it is not functioning properly and the problem cannot repaired, then restore the archived version until the update can be successfully performed. | ||
+ | |||
+ | ===== Text search broken ===== | ||
+ | |||
+ | If the search function is broken, edit <code>LocalSettings.php</code> by adding the following to the bottom of the file: | ||
+ | |||
+ | <syntaxhighlight lang="PHP"> | ||
+ | # Enables backtrace for error details | ||
+ | $wgShowExceptionDetails = true; | ||
+ | </syntaxhighlight> | ||
+ | Perform the search again and if it reports <tt>Error 1191: Can't find FULLTEXT index matching the column list (localhost)</tt>, rebuild the index with the following command: | ||
+ | |||
+ | username@servername:~$ php /var/www/example.com/public/wiki/maintenance/rebuildtextindex.php | ||
+ | |||
+ | Verify text search is now functioning properly then comment out <syntaxhighlight lang="PHP" inline>$wgShowExceptionDetails = true;</syntaxhighlight>. | ||
== External links == | == External links == | ||
+ | |||
+ | [//releases.wikimedia.org/mediawiki/ Mediawiki release downloads] | ||
[//mailinator.com Mailinator] provides a free, disposable email service that is very convenient for testing. | [//mailinator.com Mailinator] provides a free, disposable email service that is very convenient for testing. |
Latest revision as of 16:30, 30 July 2022
MediaWiki is the most popular wiki package and is the open source software that powers Wikipedia, among a great many other sites. This article covers installing MediaWiki to a UNPM Server.
This article assumes that MediaWiki is to be installed to a sub-directory called /wiki/
, though it can be installed to a sub-directory of any name or depth (additional sub-directories). Note that the WikiMedia Foundation recommends against installation to a site's root directory as this will break many aspects of the site.
Nginx configuration
Package-configs files
Create the package-configs
files mediadwiki.conf
and mediawiki_https.conf
:
username@servername:~$ sudo nano /etc/nginx/package-configs/mediawiki.conf
Add to the new file:
location /wiki/ { rewrite ^/wiki/([^?]*)(?:\?(.*))? /wiki/index.php?title=$1&$2 last; location ~* ^/images/.*.(html|htm|shtml|php|js)$ { types { } default_type text/plain; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { try_files $uri /wiki/index.php; expires max; log_not_found off; } location ~ (index|load|api).*\.php$ { include global-configs/php.conf; } location ~ /cache/ { deny all; } location ~ \.php$ { deny all; } }
username@servername:~$ sudo nano /etc/nginx/package-configs/mediawiki_https.conf
Add to the new file:
location /wiki/ { rewrite ^/wiki/([^?]*)(?:\?(.*))? /wiki/index.php?title=$1&$2 last; location ~* ^/images/.*.(html|htm|shtml|php|js)$ { types { } default_type text/plain; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { try_files $uri /wiki/index.php; expires max; log_not_found off; } location ~ (index|load|api).*\.php$ { include global-configs/php_https.conf; } location ~ /cache/ { deny all; } location ~ \.php$ { deny all; } }
Sites-available file
Open the sites-available file for the domain:
username@servername:~$ sudo nano /etc/nginx/sites-available/example.com
In the HTTP server block, add:
include package-configs/mediawiki.conf;
In the HTTPS server block, add:
include package-configs/mediawiki_https.conf;
For the categories feature of MediaWiki to function properly, it is important require nginx to serve the domain as either only example.com or only one subdomain, such as www.example.com. The sites-available
file can be edited as discussed in the nginx installation article.
404 error_page
Note that if the error_page
directive is being used to redirect 404 errors, be sure it is in the location /
block:
location / { try_files $uri $uri/ =404; error_page 404 /404.html; }
If it is directly in the server
block, MediaWiki will not attempt to create pages when a wrong page is requested.
Create MediaWiki database and database user
Create a MediaWiki database and database user:
username@servername:~$ sudo mysql -uroot -p MariaDB [(none)]> create database databasename; MariaDB [(none)]> grant all on databasename.* to 'databasenameusername'@'localhost' identified by 'databasenameusernamepassword'; MariaDB [(none)]> exit
Note that the databasename
, databasenameusername
and databasenameusernamepassword
will be required for the MediaWiki configuration process.
Install Mediawiki
Mediawiki will require a few packages to be installed to run:
username@servername:~$ sudo aptitude install imagemagick php5.6-intl
Test nginx and restart services:
username@servername:~$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful username@servername:~$ sudo service php5.6-fpm restart username@servername:~$ sudo service nginx reload
The MediaWiki project offers two different release types: major releases every six months that are immediately retired upon the next release and LTS releases every 2 years, that are supported for an additional year after the next release. Currently the LTS version is 1.35, which will be supported until September, 2023.
Download Mediawiki:
username@servername:~$ wget https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.5.tar.gz username@servername:~$ tar -xzf mediawiki-1.35.5.tar.gz username@servername:~$ mv mediawiki-1.35.5/ /var/www/example.com/public/wiki username@servername:~$ find /var/www/example.com/public/wiki/ -type d | xargs -d '\n' chmod 775 username@servername:~$ find /var/www/example.com/public/wiki/ -type f | xargs -d '\n' chmod 664 username@servername:~$ sudo chown -R www-data:www-data /var/www/example.com/public/wiki/ username@servername:~$ rm mediawiki-1.35.5.tar.gz
Navigate to secure https://www.example.com/wiki and complete the Mediawiki installation. Most admins will prefer to use the 'Authorized editors only' option under 'User rights profile:'. Select 'PHP object caching (APC, XCache or WinCache)' in the Advanced Configuration options and be sure to sign up for update notifications.
LocalSettings.php
After completing the online setup, MediaWiki will prompt to download the LocalSettings.php
file. This is the main configuration file for MediaWiki. It is easiest to open the file in a text editor and then copy and paste the contents into the LocalSettings.php
file on the server. However, before doing that, the file still requires at least a few edits.
To support loading MediaWiki in non-secure sessions, but require secure session for logging in, change:
$wgserver = "//www.example.com";
Enable $wgCacheDirectory
:
$wgCacheDirectory = "$IP/cache";
To create a user rights management system better suited to smaller wikis, change:
$wgGroupPermissions['*']['createaccount'] = true;
Then, just below the permissions created by MediaWiki, add:
# The following permissions were added to allow user account creation without
# granting new users the ability to edit. The admin accounts may elevate new
# users to the added editor role to grant permission to edit
$wgGroupPermissions['*']['createtalk'] = false;
$wgGroupPermissions['*']['createpage'] = false;
$wgGroupPermissions['*']['writeapi'] = false;
$wgGroupPermissions['*']['edit'] = false;
$wgGroupPermissions['user']['edit'] = false;
$wgGroupPermissions['user']['createtalk'] = false;
$wgGroupPermissions['user']['createpage'] = false;
$wgGroupPermissions['user']['minoredit'] = false;
$wgGroupPermissions['user']['move'] = false;
$wgGroupPermissions['user']['movefile'] = false;
$wgGroupPermissions['user']['move-subpages'] = false;
$wgGroupPermissions['user']['move-rootuserpages'] = false;
$wgGroupPermissions['user']['reupload-shared'] = false;
$wgGroupPermissions['user']['reupload'] = false;
$wgGroupPermissions['user']['purge'] = false;
$wgGroupPermissions['user']['sendemail'] = false;
$wgGroupPermissions['user']['upload'] = false;
$wgGroupPermissions['user']['writeapi'] = false;
$wgGroupPermissions['editor'] = $wgGroupPermissions['user'];
$wgGroupPermissions['editor']['edit'] = true;
$wgGroupPermissions['editor']['createtalk'] = true;
$wgGroupPermissions['editor']['createpage'] = true;
$wgGroupPermissions['editor']['minoredit'] = true;
$wgGroupPermissions['editor']['move'] = true;
$wgGroupPermissions['editor']['move-subpages'] = true;
$wgGroupPermissions['editor']['upload'] = true;
$wgGroupPermissions['editor']['reupload'] = true;
$wgGroupPermissions['editor']['sendemail'] = true;
$wgGroupPermissions['sysop']['edit'] = true;
$wgGroupPermissions['sysop']['createpage'] = true;
$wgGroupPermissions['sysop']['createtalk'] = true;
$wgGroupPermissions['sysop']['minoredit'] = true;
$wgWikiEditorModules['toolbar']['global'] = true;
$wgWikiEditorModules['toolbar']['user'] = false;
$wgGroupPermissions['bureaucrat']['usermerge'] = true;
The *
user group means all users, including anonymous users.
Below that, add:
# Enable requirement for secure login:
$wgSecureLogin = true;
# Enable pretty URLs
$wgUsePathInfo = true;
$wgArticlePath = "/wiki/$1";
Now paste the entire contents from the computer's text editor to the LocalSettings.php
file on the server:
username@servername:~$ nano /var/www/example.com/public/wiki/LocalSettings.php
Note that depending on the operating system and editor used, the code may paste in without things such as returns between paragraphs. This does happen with Notepad++ in Windows 7, but can easily be fixed by first pasting into a new Notepad++ tab and copying from there.
Configuring MediaWiki
MediaWiki configuration is different from most of the popular PHP packages. Configuring is done through the LocalSettings.php
file, extensions, which must be installed server-side with accompanied LocalSettings.php
entries, and various different hard-to-find pages in the web interface. The MediaWiki Manual is an invaluable resource. Below are some simple and common extension and configuration settings.
Sidebar
To edit the MediaWiki Sidebar, while logged in with an admin account, simply navigate to https://www.example.com/wiki/MediaWiki:Sidebar.
Disable page counts
By default, MediaWiki will display page counts at the bottom of every page. This can be disabled with the following:
username@servername:~$ nano /var/www/example.com/public/wiki/LocalSettings.php
Add to the bottom of the file:
# Disables page counters
$wgDisableCounters = true;
Change logo image
The logo image location is set in LocalSettings.php
with the $wgLogo
directive, for which the default is "$wgStylePath/common/images/wiki.png";
. Replacing wiki.png
with a different image while using the same name will be overwritten when updating MediaWiki, so it is better to use a file in a different location. MediaWiki updates generally ignore anything in the /images
directory, so putting the logo there and setting $wgLogo = "$wgScriptPath/images/filename";
is a reasonable solution, though other locations may work just as well.
MobileFrontend extension
Although there are options to automatically detect mobile devices and display a mobile-friendly theme, the disadvantage of this feature is it requires disabling caching unless an additional domain is used, such as placing an m in the subdomain. A compromise is to install the MobileFrontend extension which creates a Mobile view link at the bottom of every page. It is important to check the extension page and verify the latest version.
username@servername:~$ wget https://extdist.wmflabs.org/dist/extensions/MobileFrontend-REL1_25-c193468.tar.gz username@servername:~$ tar -xzf MobileFrontend-REL1_25-c193468.tar.gz username@servername:~$ mv MobileFrontend/ /var/www/example.com/public/wiki/extensions/ username@servername:~$ find /var/www/example.com/public/wiki/extensions/MobileFrontend/ -type d | xargs -d '\n' chmod 775 username@servername:~$ find /var/www/example.com/public/wiki/extensions/MobileFrontend/ -type f | xargs -d '\n' chmod 664 username@servername:~$ sudo chown -R www-data:www-data /var/www/example.com/public/wiki/extensions/MobileFrontend/ username@servername:~$ rm MobileFrontend-REL1_25-c193468.tar.gz username@servername:~$ nano /var/www/example.com/public/wiki/LocalSettings.php
Add to the bottom of the file:
# Enables MobileFrontend extension
require_once "$IP/extensions/MobileFrontend/MobileFrontend.php";
$wgMFAutodetectMobileView = false;
Tracking with Piwik
Piwik may be used by simply enabling and configuring the MediaWiki:Common.js feature or by installing the Piwik extension.
MediaWiki:Common.js
The easiest way to use Piwik to track users of the wiki is to simply use the Common.js feature of MediaWiki. Enable it in LocalSettings.php
:
username@servername:~$ nano /var/www/example.com/public/wiki/LocalSettings.php
Add to the file:
# Use the site's JavaScript (MediaWiki:Common.js)
$wgUseSiteJS = true;
Navigate to https://www.example.com/wiki/MediaWiki:Common.js while logged in as an administrator and add the Piwik javascript code:
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//www.example.com/randomsymlinkname/";
_paq.push(['setTrackerUrl', u+'js/']);
_paq.push(['setSiteId', 1]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'js/'; s.parentNode.insertBefore(g,s);
})();
Refer to the Piwik article for an explanation of randomsymlinkname
and js/
usage.
Piwik Integration extension
If more sophisticated tracking is required, such as ignoring certain users or user types, Using the Piwik extension may be preferable to the Common.js method. It is important to note that this extension may not support tracking while in Mobile view due to a bug.
Email notifications
If the server does not have any form of mail server installed, the $wgSMTP
setting may be used to configure an SMTP server for sending email.
username@servername:~$ nano /var/www/example.com/public/wiki/LocalSettings.php
Add the following array:
$wgSMTP = array(
'host' => "mail.example.com", // could also be an IP address. Where the SMTP server is located
'IDHost' => "example.com", // Generally this will be the domain name of your website
'port' => 25, // Port to use when connecting to the SMTP server
'auth' => true, // Should we use SMTP authentication (true or false)
'username' => "my_user_name", // Username to use for SMTP authentication (if being used)
'password' => "my_password" // Password to use for SMTP authentication (if being used)
);
Add the following PEAR packages so that PHP can support sending mail:
username@servername:~$ sudo pear install Mail username@servername:~$ sudo pear install Net_SMTP
File upload extension management
Use $wgFileExtensions
to add file extensions available for upload by adding the following, edited as desired, to LocalSettings.php
:
# Add new types to the existing list from DefaultSettings.php
$wgFileExtensions[] = 'azw';
$wgFileExtensions[] = 'azw3';
$wgFileExtensions[] = 'doc';
$wgFileExtensions[] = 'docx';
$wgFileExtensions[] = 'epub';
$wgFileExtensions[] = 'mobi';
$wgFileExtensions[] = 'mpp';
$wgFileExtensions[] = 'ods';
$wgFileExtensions[] = 'odt';
$wgFileExtensions[] = 'pdf';
$wgFileExtensions[] = 'ppt';
$wgFileExtensions[] = 'pptx';
$wgFileExtensions[] = 'xls';
$wgFileExtensions[] = 'xlsx';
Note that there are also options available to permit all extensions except those blacklisted. More information on this and other features related to uploads is available at Mediawiki Manual:Configuring file uploads.
It will be necessary to tell nginx to serve these filetypes as files. Change the try_files
block in both mediawiki.conf
and mediawiki_https.conf
to support the desired filetypes:
location ~* \.(css|gif|ico|jpeg|jpg|js|png|azw|azw3|doc|docx|epub|mobi|mpp|ods|odt|pdf|ppt|pptx|xls|xlsx)$ { try_files $uri /wiki/index.php; expires max; log_not_found off; }
Increase Mediawiki max file upload size
Mediawiki is set by default with a max upload file size of 100 MB, calculated as 1024*1024*100. To change this, in addition to necessary configuration changes in nginx.conf
and php.ini
, change the $wgMaxUploadSize
parameter to other than default by adding the following to LocalSettings.php
:
# Increase max upload file size to 200 MB
$wgMaxUploadSize = 209715200;
AntiSpam
MediaWiki now installs with the ConfirmEdit extension that includes QuestyCaptcha, a configurable bot-checking tool that can be applied to specific pages, such as only the account creation page, or to every page. QustyCaptcha is still in Beta, but should work well on most installations. Questions can be applied to several MediaWiki actions and is by default enabled on createaccount
. Here is a sample configuration:
// Enable QuestyCaptcha
// Questions will appear exactly as written and answers are case-insensitive
// For more info see https://www.mediawiki.org/wiki/Extension:QuestyCaptcha
require_once( "$IP/extensions/ConfirmEdit/ConfirmEdit.php" );
require_once( "$IP/extensions/ConfirmEdit/QuestyCaptcha.php");
$wgCaptchaClass = 'QuestyCaptcha';
$arr = array (
"What was Ben Kenobi also known as?" => array('obi wan','obi-wan','obi wan kenobi','obi-wan kenobi')
);
foreach ( $arr as $key => $value ) {
$wgCaptchaQuestions[] = array( 'question' => $key, 'answer' => $value );
}
SyntaxHighlight
The SyntaxHighlight plugin is available by default but requires some configuring.
Add the following to LocalSettings.php:
wfLoadExtension( 'SyntaxHighlight_GeSHi' );
Make the pygmentize
binary executable:
username@servername:~$ chmod a+x /var/www/unpm.org/public/wiki/extensions/SyntaxHighlight_GeSHi/pygments/pygmentize
Upgrading MediaWiki
Upgrading MediaWiki is done through the command line. For minor version upgrades, a patch file may be made available, however, due to a longstanding bug, many installations will not support upgrade via patch, thus a complete reinstall from backup is essentially performed. The best way to find the locations of an update's files and options is from the announcement email, presumably subscribed to during the mediawiki setup process, also available by subscribing to @mediawiki or even the @unpm_org account, which only retweets official announcements, and also by simply browsing through releases.wikimedia.org/mediawiki.
Maintenance mode
To prevent user edits to the wiki during upgrade, which might be saved to the old database, place the following statement at the bottom of LocalSettings.php
.
username@servername:~$ nano /var/www/example.com/public/wiki/LocalSettings.php
# Use $wgReadOnly to prevent changes to the database.
# Text in "" maybe changed as desired
# The database will be locked from edits as long as the line below
# is uncommented.
$wgReadOnly="We are upgrading MediaWiki, please be patient. This wiki will be back shortly.";
Upgrade without patch
To upgrade to versions without a patch, near complete reinstallation is performed. Note that this procedure transfers current MediaWiki settings and sets up the new MediaWiki version on a copy of the working database. This is to facilitate easy recovery to the currently functioning wiki since no changes are made to the wiki or its database.
Install new version to new directory
The actual new version will depend on what version it is desired to upgrade to. All versions of MediaWiki may be found here.
username@servername:~$ wget https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.5.tar.gz username@servername:~$ tar -xzf mediawiki-1.35.5.tar.gz -C /var/www/example.com/public/ username@servername:~$ find /var/www/example.com/public/mediawiki-1.35.5/ -type d | xargs -d '\n' chmod 775 username@servername:~$ find /var/www/example.com/public/mediawiki-1.35.5/ -type f | xargs -d '\n' chmod 664 username@servername:~$ sudo chown -R www-data:www-data /var/www/example.com/public/mediawiki-1.35.1/ username@servername:~$ cp -p /var/www/example.com/public/wiki/LocalSettings.php /var/www/example.com/public/mediawiki-1.35.5/ username@servername:~$ cp -rpfu /var/www/example.com/public/wiki/extensions/* /var/www/example.com/public/mediawiki-1.35.5/extensions/ username@servername:~$ cp -rpfu /var/www/example.com/public/wiki/images/* /var/www/example.com/public/mediawiki-1.35.5/images/ username@servername:~$ cp -rpfu /var/www/example.com/public/wiki/skins/* /var/www/example.com/public/mediawiki-1.35.5/skins/
Note that any other additional files not a part of the MediaWiki package should also be copied to the new directory. Files that have been customized should be customized again using the file in the new installation.
Copy database to new database
Before copying the database, clear pending jobs:
username@servername:~$ php /var/www/example.com/wiki/maintenance/runJobs.php
Log in to phpMyAdmin as the root MySQL user. Select the database used by MediaWiki and navigate to the Operations page. Enter the name of the new database in the Copy database to: field, leaving the default selections for copying and select Go
Navigate to phpMyAdmin home page and select User accounts. Click Edit privileges next to the user assigned to the original MediaWiki database. Under Database-specific privileges, select the new database in the Add privileges on the following database: drop-down menu. In the following page, click Check all, then uncheck GRANT and click Go.
Now update the name of the database in the new LocalSettings.php
file:
username@servername:~$ nano /var/www/example.com/public/mediawiki-1.35.5/LocalSettings.php
Change:
$wgDBname = "newdatabasename";
Archive the original /wiki/
installation, install the new installation in its place and run the update script:
username@servername:~$ mkdir /var/www/example.com/backup/wiki/ username@servername:~$ mv /var/www/example.com/public/wiki /var/www/example.com/backup/wiki/mediawiki-1.31.8 username@servername:~$ mv /var/www/example.com/public/mediawiki-1.35.5/ /var/www/example.com/public/wiki username@servername:~$ php /var/www/example.com/public/wiki/maintenance/update.php
Navigate to the wiki and verify it is functioning properly. If it is not functioning properly and the problem cannot repaired, then restore the archived version until the update can be successfully performed.
Text search broken
If the search function is broken, edit LocalSettings.php
by adding the following to the bottom of the file:
# Enables backtrace for error details
$wgShowExceptionDetails = true;
Perform the search again and if it reports Error 1191: Can't find FULLTEXT index matching the column list (localhost), rebuild the index with the following command:
username@servername:~$ php /var/www/example.com/public/wiki/maintenance/rebuildtextindex.php
Verify text search is now functioning properly then comment out $wgShowExceptionDetails = true;
.
External links
Mailinator provides a free, disposable email service that is very convenient for testing.
Send email via SMTP server by configuring $wgSMTP