MediaWiki is a free and open-source wiki software platform that runs seamlessly on Rocky Linux, providing a powerful collaborative content creation and management solution. Designed originally for Wikipedia, MediaWiki is now widely used by numerous organizations and communities to build and maintain dynamic and information-rich websites. On Rocky Linux, an enterprise-grade Linux distribution known for its stability and security, MediaWiki benefits from a robust and reliable operating environment. This combination ensures that MediaWiki installations on Rocky Linux can handle high-traffic loads and extensive user contributions, making it an ideal choice for creating comprehensive and scalable wikis.

This guide will show you how to install MediaWiki on the Rocky Linux 9 server. You will install and configure MediaWiki with LAMP Stack (Apache/Httpd, MySQL/MariaDB, and PHP).

Prerequisites

To complete this guide, make sure you have the following:

  • A Rocky Linux 9 server.
  • A non-root user with sudo privileges.
  • A domain name pointed to a server IP address.
  • A SELinux with status permissive.

Installing LAMP Stack Dependencies

MediaWiki is an open-source wiki software based on PHP and MySQL/MariaDB. To install it, you must install the LAMP Stack (Apache/httpd, MySQL/MariaDB, and PHP) on your Rocky Linux system. In this example, you will install MediaWiki with PHP 8.1, so you need to add the third-party repository.

To start, run the command below to add EPEL and Remi repositories to your Rocky Linux server.

sudo dnf install epel-release dnf-utils http://rpms.remirepo.net/enterprise/remi-release-9.rpm

<img alt="setup repo" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/1-setup-repo.png66a800d0a8c9f.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="261" loading="lazy" src="data:image/svg xml,” width=”750″>

At this time, the MediaWiki requires PHP 8.1, so you must enable it through the Remi repository. Run the command below to enable the PHP 8.1 repository from the Remi repository.

sudo dnf module reset php

sudo dnf module enable php:remi-8.1

<img alt="enable php repo" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/2-enable-repo-php.png66a800d0dcab4.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="173" loading="lazy" src="data:image/svg xml,” width=”750″>

Now run the following command to install LAMP stack dependencies for MediaWiki. Input y to confirm with the installation.

sudo dnf install httpd httpd-tools mariadb-server mariadb php php-mysqlnd php-gd php-xml php-intl php-mbstring php-json php-curl wget

<img alt="install deps" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/3-install-deps.png66a800d127755.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="207" loading="lazy" src="data:image/svg xml,” width=”750″>

Once installation is complete, run the following systemctl command to start and enable the httpd service.

sudo systemctl start httpd

sudo systemctl enable httpd

Start and enable the MariaDB service with the command below.

sudo systemctl start mariadb

sudo systemctl enable mariadb

<img alt="start enable mysql apache" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/4-start-enable-httpd-mysql.png66a800d15e511.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="199" loading="lazy" src="data:image/svg xml,” width=”750″>

Lastly, verify the PHP version using the following command. You should get PHP 8.1 installed on your Rocky Linux system.

php -v

php -m

<img alt="check php" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/5-check-php.png66a800d17df74.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="307" loading="lazy" src="data:image/svg xml,” width=”659″>

Add HTTP and HTTPS Services to Firewalld

After installing LAMP Stack, you need to open both HTTP and HTTPS ports on your Rocky Linux server. On RHEL-based operating systems, firewalld is used to open and manage allowed traffic to the server.

Add the HTTP and HTTPS services to the firewalld by executing the following command.

sudo firewall-cmd --add-service=http --permanent

sudo firewall-cmd --add-service=https --permanent

Now reload the firewalld to apply new rules with the command below.

sudo firewall-cmd --reload

Once reloaded, verify the list rules on firewalld using the command below. You should see both HTTP and HTTPS services added to the firewalld.

sudo firewall-cmd --list-all

<img alt="setup firewalld" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/6-setup-firewalld.png66a800d1a20ed.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="278" loading="lazy" src="data:image/svg xml,” width=”654″>

Setting Up MariaDB Server

Now that you have allowed traffic to the httpd web server, you can go next to secure MariaDB via the mariadb-secure-installation utility and create a new database and user that will be used by MediaWiki.

To secure MariaDB server installation, run the mariadb-secure-installation command below.

sudo mariadb-secure-installation

During the process, you will be asked about some of MariaDB server configurations – Input y to confirm the changes or n to reject the new configuration:

  • Switch to unix_socket authentication? Input n and press ENTER. The default MariaDB root user is already protected. You can also enable it by typing y for yes.
  • Change the root password?. Input y to confirm and set up your new MariaDB root password.
  • Remove anonymous user?. Input y to confirm.
  • Disallow root login remotely? Input y to confirm. Only local connection will be allowed if you use the MariaDB root user.
  • Can you remove the test database and access to it? Input y to confirm and remove the default database ‘test’.
  • Lastly, input y again to reload all tables privileges on your MariaDB server and apply new changes.

With the MariaDB server secured, you can create a new database and user for MediaWiki.

Log in to the MariaDB server using the command below. Type your MariaDB root password when prompted.

sudo mariadb -u root -p

Now run the following queries to create a new database and user for MediaWiki. In this example, you will create a new database mediawikidb and user wikiuser with the password p4ssw0rd. You can adjust the following database details with your information.

CREATE DATABASE mediawikidb;

GRANT ALL PRIVILEGES ON mediawikidb.* TO 'wikiuser'@'localhost' IDENTIFIED BY 'p4ssw0rd' WITH GRANT OPTION;

FLUSH PRIVILEGES;

<img alt="create db" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/7-create-db.png66a800d1c0001.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="164" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, run the query below to verify the privileges for user wikiuser. Make sure that the user wikiuser can access the database mediawikidb.

SHOW GRANTS FOR 'wikiuser'@'localhost';

Lastly, type quit to exit from the MariaDB server.

<img alt="show db privileges" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/8-show-privileges.png66a800d1ea71f.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="230" loading="lazy" src="data:image/svg xml,” width=”750″>

Now that you have configured the MariaDB server, you will download the MediaWiki source code and set up proper permission for the installation directory.

Move to the /var/www/ directory and download the MediaWiki source code using the wget command below. Check the MediaWiki download page to grab the link for its latest version.

cd /var/www/

wget https://releases.wikimedia.org/mediawiki/1.41/mediawiki-1.41.0.tar.gz

Once downloaded, run the command below to extract the MediaWiki source code and rename the extracted directory to ‘mediawiki’. With this, your document root for MediaWiki installation will be /var/www/mediawiki.

tar -zxpvf mediawiki-1.41.0.tar.gz

mv mediawiki-1.41.0 mediawiki

Now run the chown command below to change the ownership of /var/www/mediawiki to the ‘apache’ user and allow the httpd web server to access the MediaWiki source code.

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

If you have SELinux enabled, run the command below to fix labeling for the MediaWiki source code.

sudo restorecon -FR /var/www/mediawiki/

Setting Up Httpd Virtual Host

After downloading the MediaWiki source code, you will create a new virtual host configuration for MediaWiki. So make sure you have a domain name pointed to your server IP address.

Create a new configuration /etc/httpd/conf.d/mediawiki.conf using the following nano editor command.

sudo nano /etc/httpd/conf.d/mediawiki.conf

Insert the configuration below and make sure to change the ServerName option with your domain name.

ServerName dev.domainhere.info

ServerAlias dev.domainhere.info

ServerAdmin [email protected]

DocumentRoot /var/www/mediawiki

ErrorLog /var/log/httpd/dev.domainhere.info_error.log

CustomLog /var/log/httpd/dev.domainhere.info_access.log combined



Options FollowSymlinks

AllowOverride All

Require all granted

When you’re finished, save the file and exit the editor.

Now run the command below to verify your httpd syntax. If you get an output Syntax OK, that indicates that you have proper httpd configuration.

sudo apachectl configtest

Lastly, restart the httpd service to apply the new httpd virtual host configuration with the following command.

sudo systemctl restart httpd

<img alt="setup httpd" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/9-setup-httpd.png66a800d214493.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="176" loading="lazy" src="data:image/svg xml,” width=”620″>

If you’re installing MediaWiki on the public domain, make sure you implement HTTPS. In this example, you will generate SSL/TLS certificates from Letsencrypt and secure MediaWiki with HTTPS.

First, run the dnf command below to install Certbot and the Apache plugin to your system. Input y to confirm with the installation.

sudo dnf install certbot python3-certbot-apache

Once the installation is finished, run the certbot command below to generate SSL/TLS certificates for your MediaWiki domain name. Make sure to change the domain name and email address with your information.

sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d wiki.howtoforge.local

After the process, your MediaWiki installation should be secured with HTTPS and your SSL/TLS certificates should be available at /etc/letsencrypt/live/ directory.

Installing MediaWiki

Launch your web browser and visit your MediaWiki domain name such as http://wiki.howtoforge.local/. If everything goes well, you should get the welcome page of MediaWiki.

Click on the link to set up the wiki.

<img alt="setup wiki" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/10-setup-wiki.png66a800d246bdf.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="388" loading="lazy" src="data:image/svg xml,” width=”641″>

Select the MediaWiki default language and click Continue. The MediaWiki supports various languages as you need.

<img alt="select default language" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/11-setup-language.png66a800d269177.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="395" loading="lazy" src="data:image/svg xml,” width=”750″>

On the environment check process, make sure that your system meets MediaWiki requirements. Then click continue again.

<img alt="check env" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/12-checks.png66a800d2be826.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="451" loading="lazy" src="data:image/svg xml,” width=”750″>

Now input the database name, user, and password. Then click Continue.

<img alt="setup db" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/13-setup-db.png66a800d311fef.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="538" loading="lazy" src="data:image/svg xml,” width=”750″>

Tick the option to use the same account as for the installation and click Continue. With this, you will use the same database for MediaWiki users.

<img alt="db settings" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/14-db-setting.png66a800d361da7.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="394" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, input your admin user, password, and email address, then click Continue. This user will be used as an admin for MediaWiki.

<img alt="setup user" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/15-user.png66a800d3b5b28.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="550" loading="lazy" src="data:image/svg xml,” width=”750″>

For the additional configuration, click Continue again. You can configure these later after the installation is complete.

<img alt="additional settings" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/16-settings.png66a800d41025f.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="530" loading="lazy" src="data:image/svg xml,” width=”750″>

Now click Continue to confirm the MediaWiki installation.

<img alt="installation" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/17-start-installation.png66a800d462458.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="394" loading="lazy" src="data:image/svg xml,” width=”750″>

After the installation is finished, you will an output below – Click Continue to proceed to the next section:

<img alt="installation complete" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/18-finished.png66a800d487f66.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="431" loading="lazy" src="data:image/svg xml,” width=”750″>

You will see additional instructions to complete the MediaWiki installation:

  • Download the LocalSettings.php file.
  • Place the LocalSettings.php on the DocumentRoot directory.

<img alt="installation complete" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/19-localsettings.png66a800d4ab1c2.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="451" loading="lazy" src="data:image/svg xml,” width=”750″>

Back to your server terminal and run the command below to create a new file LocalSettings.php

touch /var/www/mediawiki/LocalSettings.php

sudo chown apache:apache /var/www/mediawiki/LocalSettings.php

Edit the file LocalSettings.php using the nano editor command and input the PHP script that you have downloaded into it.

nano /var/www/mediawiki/LocalSettings.php

Save and exit the file.

Move back to the MediaWiki installation page and click the link to enter your wiki. You will see the default main page of mediaWiki like the following:

<img alt="default home" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/07/echo/20-mediawiki.png66a800d4f1807.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="330" loading="lazy" src="data:image/svg xml,” width=”750″>

Conclusion

Congratulations! You have completed the installation of MediaWiki with the LAMP Stack (Apache/httpd, MariaDB, and PHP) on a Rocky Linux 9 server. You have also secured MediaWiki with HTTPS via Certbot and Letsencrypt.