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"
http://localhost

How To Find your Server's Public IP Address

sudo apt install curl
curl http://icanhazip.com

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
<?php
    phpinfo();
?>
http://localhost/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 https://releases.wikimedia.org/mediawiki/1.30/mediawiki-1.30.0.tar.gz
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
CREATE DATABASE wikidb;
GRANT ALL PRIVILEGES ON wikidb.* TO 'wikiuser'@'localhost' IDENTIFIED BY 'password';

Step 8 — Run the installation script

http://localhost/w/index.php
sudo mv LocalSettings.php /var/www/html/w

Step 9 — Short URL/Apache

MediaWiki's default page addresses looks like these examples:

http://localhost/w/index.php/Page_title

Short URLpage addresses looks like these examples:

http://localhost/wiki/Page_title

  • 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
    </Directory>
    # 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.
    #ServerName www.example.com

    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
</VirtualHost>

# 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
## http://www.mediawiki.org/wiki/Manual:Short_URL/Apache

# 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]

LocalSettings.php

sudo vim /var/www/html/w/LocalSettings.php
## https://www.mediawiki.org/wiki/Manual:Short_URL
$wgScriptPath = "/w";        // this should already have been configured this way
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;

Step 10 — Extension:SyntaxHighlight

Troubleshooting

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 https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py
sudo pip install Pygments
which pygmentize
/usr/local/bin/pygmentize
sudo vim /var/www/html/w/LocalSettings.php
$wgPygmentizePath = "/usr/local/bin/pygmentize";

References

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

INSTALL MEDIAWIKI ON UBUNTU 18.04 LTS WITH APACHE2, MARIADB AND PHP 7.1 SUPPORT

Manual:Installation guide

Manual:Installation requirements

Manual:Installing MediaWiki

Manual:Config script

Manual:Short URL/Apache

Extension:SyntaxHighlight

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