How To Install MediaWiki on Ubuntu 18.04 LTS

Step 1 — Installing Apache and Updating the Firewall

Adjust the Firewall to Allow Web Traffic

sudo apt update
sudo apt upgrade
sudo apt install apache2
sudo ufw app list
sudo ufw app info "Apache Full"
sudo ufw allow in "Apache Full"

How To Find your Server's Public IP Address

sudo apt install curl

Step 2 — Installing MySQL

sudo apt install mysql-server
sudo mysql_secure_installation

Step 3 — Installing PHP

sudo apt install php libapache2-mod-php php-mysql
apt search php- | less

Step 4 — Testing PHP Processing on your Web Server

sudo vim /var/www/html/info.php

Step 5 — Before installation

Installation requirements

sudo apt install php-apcu php-cli php-curl php-gd php-intl php-mbstring php-pear php-xml
pear list
sudo pear install Net_Socket
sudo pear install Mail
sudo pear install Net_SMTP
sudo apt install imagemagick
sudo apt install texlive
sudo apt install git
sudo systemctl reload apache2
sudo systemctl restart apache2

Step 6 — Installing MediaWiki

curl -O
tar xvzf mediawiki-*.tar.gz
sudo mkdir /var/www/html/w
sudo mv mediawiki-1.30.0/* /var/www/html/w

Step 7 — Create a database

sudo mysql -u root -p
GRANT ALL PRIVILEGES ON wikidb.* TO 'wikiuser'@'localhost' IDENTIFIED BY 'password';

Step 8 — Run the installation script

sudo mv LocalSettings.php /var/www/html/w

Step 9 — Short URL/Apache

MediaWiki's default page addresses looks like these examples:


Short URLpage addresses looks like these examples:


  • The MediaWiki directory is located at: /w
  • The desired short url format is: /wiki/Page_title

Enabling mod_rewrite

sudo a2enmod rewrite
sudo systemctl restart apache2

Setting up Apache2

cd  /etc/apache2/sites-available
sudo cp 000-default.conf mediawiki.conf
sudo vim /etc/apache2/sites-available/mediawiki.conf
<VirtualHost *:80>
    <Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
sudo a2ensite mediawiki.conf
sudo a2dissite 000-default.conf
sudo apache2ctl configtest
sudo systemctl restart apache2

Setting up the rewrite rules

sudo vim /var/www/html/.htaccess

# Enable the rewrite engine
RewriteEngine On

# Short URL for wiki pages
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]

# Redirect / to Main Page
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]


sudo vim /var/www/html/w/LocalSettings.php
$wgScriptPath = "/w";        // this should already have been configured this way
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;

Step 10 — Extension:SyntaxHighlight


After updating to MediaWiki v1.26 and above, some users started reporting problems with the extension.

  • Try pointing $wgPygmentizePath in LocalSettings.php towards an external pygmentize binary.
  • See the phabricator task on this for further suggestions and information.
sudo apt install python
curl -o
sudo python
sudo pip install Pygments
which pygmentize
sudo vim /var/www/html/w/LocalSettings.php
$wgPygmentizePath = "/usr/local/bin/pygmentize";


How To Install MediaWiki on Ubuntu 14.04

How To Rewrite URLs with mod_rewrite for Apache on Ubuntu 16.04

How To Install the Apache Web Server on Ubuntu 18.04

How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 18.04


Manual:Installation guide

Manual:Installation requirements

Manual:Installing MediaWiki

Manual:Config script

Manual:Short URL/Apache


posted @ 2018-05-07 17:27 yongwu 阅读(...) 评论(...) 编辑 收藏