From Void-Byte
Jump to navigation Jump to search

Install Apache2

MediaWiki requires a web server utilizing NGINX or Apache2 to function. In this guide we will install Apache instead of NGINX on our Ubuntu 18.04 server.

Install Apache2 by running the following command.

sudo apt -y install apache2

Once Apache2 is installed we will disable directory listings.

sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/apache2/apache2.conf

Now we will stop the service (if previously enabled), start it, and enable it so it starts after a system reboot.

sudo systemctl restart apache2.service && sudo systemctl enable apache2.service

Install MariaDB

MediaWiki is dependent on a database, and as such a database service must be installed and configured. We will install and configure MariaDB as shown below.

sudo apt install mariadb-server mariadb-client

Now we will stop the service (if previously enabled), start it, and enable it so it starts after a system reboot.

sudo systemctl restart mariadb.service && sudo systemctl enable mariadb.service

Once MariaDB has been installed we will secure our installation.

sudo mysql_secure_installation

You will be prompted to answer the following questions. Ensure you set the following options as shown below.

Enter current password for root (enter for none): Press Enter
Set root password? [Y/n]: Y
New password: Enter Password
Re-enter new password: Confirm Password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]:  Y
Reload privilege tables now? [Y/n]:  Y

Once completed restart MariaDB.

sudo systemctl restart mariadb.service

Install PHP and Dependencies

Use the following commands to install PHP and required dependencies for MediaWiki.

sudo apt install php php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysql php-cli php-ldap php-zip php-curl

Open the PHP initialization file.

sudo vim /etc/php/7.2/apache2/php.ini

Set the following parameters in the PHP file.

file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Phoenix

Create a MediaWiki database

Once all of the previous steps have been completed you can now create your MediaWiki database. Follow the steps below to create your MediaWiki database.

sudo mysql -u root -p

Create a database called mediawiki


Create a database user called mwadmin with a new password.

CREATE USER 'mwadmin'@'localhost' IDENTIFIED BY 'enterYourPassword';

Grant mwadmin full access to the database.

GRANT ALL ON mediawiki.* TO 'mwadmin'@'localhost' IDENTIFIED BY 'YourPassword' WITH GRANT OPTION;

Now save your changes, and exit.


Download and Install MediaWiki

Visit to find the latest iteration of MediaWiki for download. Then follow the commands below to download and install.

Change directory to /tmp and download the latest version.

cd /tmp && wget

Create a directory, and extract the files to the new directory.

sudo mkdir -p /var/www/html/mediawiki
sudo tar -zxvf mediawiki*.tar.gz
sudo mv mediawiki-1.34.0/* /var/www/html/mediawiki

Change the directories ownership and permissions.

sudo chown -R www-data:www-data /var/www/html/mediawiki/ && sudo chmod -R 755 /var/www/html/mediawiki/

Configure Apache2 and MediaWiki Configuration Files

Now that MediaWiki has been installed and placed into its new directory we must create a configuration file in Apache2.

sudo vim /etc/apache2/sites-available/mediawiki.conf

You can now set up your mediawiki.conf file as seen below.

<VirtualHost *:80>
  DocumentRoot /var/www/html/mediawiki
  ServerName wikiserver
  <Directory /var/www/html/mediawiki/>
    Options +FollowSymlinks
    AllowOverride All
    Require all granted

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

  <Directory /var/www/html/mediawiki/images/>
    AllowOverride None
    AddType text/plain .html .htm .shtml .phtml
    php_admin_flag engine off

Now save your file and exit.


Enable and Configure MediaWiki

Enable your new configuration file and enable rewriting.

sudo a2dissite 000-default.conf
sudo a2ensite mediawiki.conf
sudo a2enmod rewrite

Restart Apache2 to reload all settings and configurations.

sudo systemctl restart apache2.service

Visit your hostname or IP address to start MediaWiki setup, and press "set up the wiki" to begin.

Mw installation 1.png

Select the users language, and the language of the MediaWiki server.

Mw installation 2.png

Review environmental checks. If any issues are present then resolve those issues before continuing on.

Mw installation 3.png

Enter in the name of your database (mediawiki) and the username/password (mwadmin, password).

Mw installation 4.png

Select "use the same account as for installation" (mwadmin).

Mw installation 5.png

Set the name of your server, and create an administrator account.

Mw installation 6.png

Finalize your setup, and download the LocalSettings.php file.

Mw installation 7.png

Transfer the LocalSettings.php file from your host to the wikiservers mediawiki root directory.

scp /Downloads/LocalSettings.php username@IPAddressORHostname:/var/www/html/mediawiki

Adjust the ownership and permissions of the LocalSettings.php file.

chown www-data:www-data LocalSettings.php && chmod 755 LocalSettings.php

Now click "enter your wiki" on your wikiserver. It will inform you that you must install a skin.

Mw installation 8.png

Download the skin, place in the /mediawiki/skins directory, extract the files, set the correct file permissions/ownership

cd /var/www/html/mediawiki/skins && wget
sudo tar -zxvf Vector-REL1_34-f39a3f0.tar.gz && rm Vector-REL1_34-f39a3f0.tar.gz
sudo chown -R www-data:www-data Vector && sudo chmod -R 755 Vector

Add the LoadSkin argument to the LocalSettings.php file.

Echo "wfLoadSkin( 'Vector' );" >> /var/www/html/mediawiki/LocalSettings.php

Now reload your wikiserver webpage, and you should be presented with a front page shown below.

Mw installation 9.png


sudo apt-get install certbot python3-certbot-apache