MediaWiki is a free and open-source wiki software that powers the biggest wiki sites on the internet such as Wikipedia and Wikimedia. It’s extremely powerful, scalable, and extensible wiki software that offers feature-rich wiki implementations. MediaWiki is a web application developed in 2002, written mainly in PHP, and uses RDBMS such as MySQL and PostgreSQL for storing data.

MediaWiki also can be used as a collaboration and documentation platform. It helps you and your team to organize documentation and make it public for everyone. It also supports multilingual, which can be used to create a multilingual site. And it’s very customizable wiki software so you can choose different themes and editors for your wiki.

In this tutorial, we will show you how to install MediaWiki on the Ubuntu 22.04 server with the LAMP Stack (Linux, Apache2, MariaDB, and PHP). This tutorial includes the basic configuration of MediaWiki, so in the end, you will have a fully functional wiki site.

Prerequisite

For this example, we need the following prerequisites:

  • An Ubuntu 22.04 server.
  • A non-root user with root/administrator privileges.
  • A domain name pointed to the server IP address.

Installing LAMP Stack

In the first step, you will be installing the basic LAMP Stack on the ubuntu 22.04 server. In this example, you will be running the MediaWiki with the Apache2 web server.

Before you get started, you will need to install PHP 7.4 on your Ubuntu 22.04 server. The latest version of MediaWiki required PHP 7.4 and is not yet ready for the latest PHP 8.1. So you will need to set up a third-party repository on your Ubuntu system for installing PHP 7.4.

Run the following command to add the PHP 7.4 PPA repository to your system. This command also will automatically update and refresh all available repositories on your system.

sudo add-apt-repository ppa:ondrej/php -y

After all is completed, run the apt command below to install the LAMP Stack packages to the ubuntu 22.04 server.

sudo apt install apache2 mariadb-server imagemagick libapache2-mod-php7.4 php7.4 php7.4-common php7.4-intl php7.4-xml php7.4-curl php7.4-gd php7.4-mbstring php7.4-mysql php7.4-apcu

Input Y to confirm the installation and press ENTER to continue. And the LAMP Stack will begin.

After the LAMP Stack installation is finished, check and verify the Apache2 and MariaDB services using the following command. And you can see the Apache2 service is enabled and running.

sudo systemctl is-enabled apache2

sudo systemctl status apache2

For the MariaDB service, you can verify using the below command.

sudo systemctl is-enabled mariadb

sudo systemctl status mariadb

And on the following screenshot, you can see the MariaDB service is enabled, which will automatically be running at system startup. And the current status of the MariaDB service is running.

<img alt="check mariadb" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/2-check-mariadb.png62c700f98a4f3.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="274" loading="lazy" src="data:image/svg xml,” width=”750″>

After installing the LAMP Stack packages, you will now be configuring the PHP as requirements for the MediaWiki installation. This includes like configuration of “max_upload_filesize“, “memory_limit“, and “max_execution_time” of your PHP installation.

Edit the file “/etc/php/7.4/apache2/php.ini” using nano editor.

sudo nano /etc/php/7.4/apache2/php.ini

Change the default values of the following configuration like below.

upload_max_filesize = 80M

memory_limit = 512M

max_execution_time = 360

Save and close the file when you are done.

Lastly, run the command below to restart the apache2 service and apply new changes.

sudo systemctl restart apache2

Configuring MariaDB Database Server

After setting up the PHP installation, now it’s time to set up the MariaDB server. This includes the configuration of the MariaDB root password and deployment, and also you will need to create a new MariaDB database and user for the MediaWiki installation.

Run the following command to start configuring the MariaDB deployment.

sudo mysql_secure_installation

Now you will be asked the following questions for the MariaDB configurations:

  • The default MariaDB installation comes without a root password, press ENTER to continue.
  • Input n to keep the default authentication method and not use the unix_socket authentication (this is for the MariaDB root user).
  • Input Y to set up the MariaDB root password, then input the new password and repeat.
  • Input Y to remove the default anonymous user.
  • Input Y to disable the remote login for the MariaDB root user.
  • Input Y to delete the default database “test” from your MariaDB installation.
  • Lastly, input Y again to reload all tables privileges and apply new changes.

Now you have finished the basic configuration of MariaDB deployment.

Next, log in to the MariaDB shell as the root user using the following command.

sudo mysql -u root -p

Now run the following MySQL/MariaDB queries to create a new database “mediawikidb” with the user “mediawiki” and the password “mediawikipassdb“. This database and user will be used for storing MediaWiki data.

CREATE DATABASE mediawikidb;

CREATE USER [email protected] IDENTIFIED BY 'mediawikipassdb';

GRANT ALL ON mediawikidb.* TO [email protected] WITH GRANT OPTION;

FLUSH PRIVILEGES;

<img alt="create database" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/4-create-database.png62c700f9a7b04.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="243" loading="lazy" src="data:image/svg xml,” width=”750″>

After that, run the query below to check the list of database access for the user “[email protected]” and exit from the MariaDB shell. Now be sure the MariaDB user “[email protected]” has access to the database “mediawikidb“.

SHOW GRANTS FOR [email protected];

quit

<img alt="check user privileges" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/5-checking-privileges.png62c700f9c73a3.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="186" loading="lazy" src="data:image/svg xml,” width=”750″>

You have now completed the basic configuration of LAMP Stack for the MediaWiki installation. It’s time to download the MediaWiki source code to your Ubuntu machine.

Now go to the “/var/www/” directory and download the MediaWiki source code using the wget command as below. At the current time, the latest version of MediaWiki is v1.38.1. And you will get the file “mediawiki-1.38.1.tar.gz”.

cd /var/www/

wget https://releases.wikimedia.org/mediawiki/1.38/mediawiki-1.38.1.tar.gz

Run the following command to extract the MediaWiki source code “mediawiki-1.38.1.tar.gz” and rename the extracted directory to the “mediawiki“. So the MediaWiki installation directory will be “/var/www/mediawiki“.

tar -xvzf mediawiki-*.tar.gz

mv mediawiki-*/ mediawiki/

Lastly, run the following command to change the ownership of the MediaWiki installation directory “/var/www/mediawiki” to the correct user “www-data” and the permission to “755″.

sudo chown -R www-data:www-data /var/www/mediawiki

sudo chmod 755 /var/www/mediawiki

Setting Up Apache2 Virtual Host for MediaWiki

Now you will be setting up the Apache2 virtual host for the MediaWiki. In this example, the MediaWiki will be running with the domain name “wiki.hwdomain.io” and the secure SSL/HTTPS connection enabled on top of the Apache2 virtual host.

Before starting creating the virtual host configuration, run the following command to enable Apache2 modules rewrite and ssl.

sudo a2enmod rewrite ssl

Create a new virtual host configuration “/etc/apache2/sites-available/mediawiki.conf” using nano editor.

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

Add the following configuration to the file. Also, do not forget to change the domain name and the path of SSL certificates.

    ServerName wiki.hwdomain.io

    ServerAdmin [email protected]

    # Redirect Requests to SSL

    Redirect permanent "https://www.howtoforge.com/" "https://wiki.hwdomain.io/"

    ErrorLog ${APACHE_LOG_DIR}/wiki.hwdomain.io.error.log

    CustomLog ${APACHE_LOG_DIR}/wiki.hwdomain.io.access.log combined

   

        ServerName wiki.hwdomain.io

        ServerAdmin [email protected]

        DocumentRoot /var/www/mediawiki

        # According MWiki Manual:Security

        php_flag register_globals off

        ErrorLog ${APACHE_LOG_DIR}/wiki.hwdomain.io.error.log

        CustomLog ${APACHE_LOG_DIR}/wiki.hwdomain.io.access.log combined

        SSLEngine on

        SSLCertificateFile /etc/letsencrypt/live/wiki.hwdomain.io/fullchain.pem

        SSLCertificateKeyFile /etc/letsencrypt/live/wiki.hwdomain.io/privkey.pem

       

                SSLOptions StdEnvVars

       

       

                SSLOptions StdEnvVars

       

       

                Options None FollowSymLinks

                #Allow .htaccess

                AllowOverride All

                Require all granted

               

                        SecRuleEngine Off

                        # or disable only problematic rules

               

       

        # According to MWiki Manual:Security

       

                # Ignore .htaccess files

                AllowOverride None

                # Serve HTML as plaintext, don't execute SHTML

                AddType text/plain .html .htm .shtml .php .phtml .php5

                # Don't run arbitrary PHP code.

                php_admin_flag engine off

                # If you've other scripting languages, disable them too.

       

        #According to MWiki Manual:Security

       

                Deny from all

                AllowOverride AuthConfig Limit

                Require local

       

   

Save and close the file when you are done.

Next, activate the virtual host configuration “mediawiki.conf”, then verify your Apache2 configuration. If you get the output message such as “Syntax OK“, then your Apache2 configuration is correct.

sudo a2ensite mediawiki.conf

sudo apachectl configtest

Lastly, run the command below to restart the Apache2 service and apply new changes. Now you have completed the LAMP Stack configuration for the MediaWiki, and now you are ready to start the MediaWiki configuration.

sudo systemctl restart apache2

Open your web browser and type the MediaWiki installation domain name (i.e https://wiki.hwdomain.io/) on the address bar. Click the link “set up the wiki” to start configuring your MediaWiki installation.

<img alt="setup mediawiki" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/6-setup-mediawiki.png62c700fa064f0.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="265" loading="lazy" src="data:image/svg xml,” width=”750″>

Choose the default language for your Wiki and click “Continue“.

<img alt="language settings" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/7-choose-language.png62c700fa2c414.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="328" loading="lazy" src="data:image/svg xml,” width=”750″>

Now the MediaWiki installer will be checking all requirements for the installation. Be sure you get the message “The environment has been checked. You can install MediaWiki” on the screen, then click “Continue“.

<img alt="check system requirements" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/8-check-system-requirements.png62c700fa59b67.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="524" loading="lazy" src="data:image/svg xml,” width=”750″>

Input details MariaDB database and user for your MediaWiki and click “Continue” again.

<img alt="setup database" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/9-setup-database.png62c700fa7e194.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="591" loading="lazy" src="data:image/svg xml,” width=”750″>

For the database settings, leave it as default and click “Continue“.

<img alt="default database settings" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/10-default-database-settings.png62c700faa449f.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="324" loading="lazy" src="data:image/svg xml,” width=”750″>

Now input the title of your wiki and input details admin user and password for your MediaWiki and click “Continue“.

<img alt="create admin user" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/11-create-admin-user.png62c700facd30b.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="512" loading="lazy" src="data:image/svg xml,” width=”750″>

For the additional options/configurations for the MediaWiki, you can leave it as default and click “Continue“.

<img alt="additional options mediawiki" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/12-options-mediawiki.png62c700fb00716.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="610" loading="lazy" src="data:image/svg xml,” width=”750″>

Click “Continue” again to confirm and start the MediaWiki installation.

<img alt="confirm install mediawiki" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/13-continue-to-install.png62c700fb2dbba.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="324" loading="lazy" src="data:image/svg xml,” width=”750″>

After MediaWiki installation is completed, click “Continue” again.

<img alt="installation completed" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/14-installation-mediawiki.png62c700fb5e78e.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="357" loading="lazy" src="data:image/svg xml,” width=”750″>

Now you will need to download the file “LocalSettings.php” file to your local machine and upload it to the MediaWiki server.

Another option, you can create a new file “/var/www/mediawiki/LocalSettings.php” using nano editor.

nano /var/www/mediawiki/LocalSettings.php

Add the script from the LocalSettings.php file on your local machine.

Now change the ownership of the file to the correct user “www-data“.

sudo chown www-data:www-data /var/www/mediawiki/LocalSettings.php

Now click the link “enter your wiki” to see the result of the installation.

<img alt="wiki installation completed" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/15-download-localsettings.png62c700fb8720e.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="428" loading="lazy" src="data:image/svg xml,” width=”750″>

And now you will get the default index page of your MediaWiki installation.

<img alt="mediawiki home page" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/16-mediawiki-home.png62c700fbc387a.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="304" loading="lazy" src="data:image/svg xml,” width=”750″>

Now click the “Login” link on the top right, then input your admin user and password for your MediaWiki and click “Log in“. And you should be logged into the MediaWiki.

<img alt="login to mediawiki" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/07/echo/17-login-admin-mediawiki.png62c700fc1dbac.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="630" loading="lazy" src="data:image/svg xml,” width=”640″>

Conclusion

Congratulation! you have now successfully installed MediaWiki on the Ubuntu 22.04 server with the LAMP Stack. With this type of installation, you have the MediaWiki running securely with HTTPS/SSL enabled on top of your MediaWiki installation.