28.6 C
Jaipur
Sunday, August 1, 2021

How to Install MediaWiki with Nginx and Let’s Encrypt SSL on Ubuntu 20.04

Must read

MediaWiki is an open-source wiki software written in PHP. It allows you to create your own self-hosted wiki website on the server. It is one of the most popular wiki platforms due to its simplicity and customizability. Currently, it is used by many companies to manage their wiki pages. It provides a versatile and free tool for publishing content on the internet.

In this tutorial, we will show you how to install MediaWiki with Nginx web server and Let’s Encrypt SSL on Ubuntu 20.04.

Prerequisites

  • A server running Ubuntu 20.04.
  • A valid domain name pointed with your server IP.
  • A root password is configured on the server.

Getting Started

First, update the system packages to the updated version by running the following command:

apt-get update -y

Once all the packages are updated, you can proceed to the next step.

Install Nginx, MariaDB and PHP

MediaWiki requires Nginx web server, MariaDB database server, PHP, and other extensions. You can install all of them with the following command:

apt-get install nginx mariadb-server php php-fpm php-mbstring php-xml php-json php-mysql php-curl php-intl php-gd php-mbstring texlive imagemagick unzip -y

Once all the packages are installed, install the Composer with the following command:

apt-get install composer -y

Next, edit the php.ini file and change the default settings:

nano /etc/php/7.4/fpm/php.ini

Change the following lines:

memory_limit = 512M
post_max_size =32M
upload_max_filesize = 32M
date.timezone = Asia/Kolkata

Save and close the file then restart the PHP-FPM to apply the changes:

systemctl restart php7.4-fpm

Once you are finished, you can proceed to the next step.

Create a MariaDB Database

MediaWiki uses MariaDB as a database backend so you will need to create a database and user for MediaWiki.

First, connect to the MariaDB with the following command:

mysql

Once you are connected, create a database and user with the following command:

MariaDB [(none)]> CREATE DATABASE mediadb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON mediadb.* TO 'mediauser'@'localhost' IDENTIFIED BY 'password';

Next, flush the privileges and exit from the MariaDB with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Once you are finished, you can proceed to the next step.

First. go to the MediaWiki website and pick the latest version of the MediaWiki. Then, run the following command to download it to your server:

wget https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.2.zip

Once the download is completed, unzip the downloaded file with the following command:

unzip mediawiki-1.35.2.zip

Next, move the extracted directory to the Nginx web root directory with the following command:

mv mediawiki-1.35.2 /var/www/html/mediawiki

Next, change the directory to the MediaWiki and install all PHP dependencies with the following command:

cd /var/www/html/mediawiki
composer install --no-dev

Once all the dependencies are installed, set proper permission and ownership with the following command:

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

Once you are finished, you can proceed to the next step.

Next, you will need to create an Nginx virtual host configuration file for MediaWiki. You can create it with the following command:

nano /etc/nginx/conf.d/wiki.conf

Add the following lines:

server {
        listen 80;
        server_name wiki.example.com;

        root /var/www/html/mediawiki;
        index index.php;
   
        error_log /var/log/nginx/mediawiki.error;
        access_log /var/log/nginx/mediawiki.access;

        location / {
                try_files $uri $uri/ /index.php;
        }


        location ~ /.ht {
          deny all;
         }

        location ~ .php$ {
            fastcgi_pass unix:/run/php/php7.4-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            include snippets/fastcgi-php.conf;
        }
}

Save and close the file then verify the Nginx for any syntax error with the following command:

nginx -t

You should see the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Next, restart the Nginx service to apply the changes:

systemctl restart nginx

You can also verify the status of the Nginx with the following command:

systemctl status nginx

You should see the following output:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-06-02 05:06:48 UTC; 3s ago
       Docs: man:nginx(8)
    Process: 24594 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 24605 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 24606 (nginx)
      Tasks: 2 (limit: 2353)
     Memory: 2.8M
     CGroup: /system.slice/nginx.service
             ??24606 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??24607 nginx: worker process

Jun 02 05:06:48 ubuntu2004 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 02 05:06:48 ubuntu2004 systemd[1]: Started A high performance web server and a reverse proxy server.

Now, open your web browser and type the URL http://wiki.example.com. You will be redirected to the following page:

Now, click on the set up the wiki button. You should see the following page:

Select language

Here, choose your wiki language and click on the Continue button. You should see the following page:

Accept license

Now, click on the Continue button. You should see the following page:

MySQL database settings

Now, provide your database details and click on the Continue button. You should see the following page:

MediaWiki Installation

Select use the same account as for installation and click on the Continue button. You should see the following page:

Wiki name

Now, provide your wiki site name, username, and password. Then, click on the Continue button. You should see the following page:

Start the installation procedure

Click on the Continue button to start the installation. You should see the following page:

Installation finished successfully

Click on the Continue button. Once the installation is finished, you should see the following page:

Local settings

Now, click on the download button to download the LocalSettings.php file to your system. Then, copy this file to your server inside the MediaWiki root directory and set proper permission with the following command:

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

Next, go back to your web browser and click on enter your wiki. You should see the MediaWiki dashboard on the following page:

MediaWiki installed

Next, you will need to install the Certbot client package to install the manage the Let’s Encrypt SSL.

First, install the Certbot with the following command:

apt-get install python3-certbot-nginx -y

Once the installation is finished, run the following command to install the Let’s Encrypt SSL on your website:

certbot --nginx -d wiki.example.com

You will be asked to provide a valid email address and accept the term of service as shown below:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for wiki.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/wiki.conf

Next, choose whether or not to redirect HTTP traffic to HTTPS as shown bellow:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Type 2 and hit Enter to finish the installation. You should see the following output:

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/wiki.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://wiki.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=wiki.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/wiki.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/wiki.example.com/privkey.pem
   Your cert will expire on 2021-12-30. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

Now, your website is secured with Let’s Encrypt SSL. You can access it securely using the URL https://wiki.example.com.

Conclusion

Congratulations! you have successfully installed MediaWiki with Nginx and Let’s Encrypt SSL on Ubuntu 20.04. You can now easily host your own wiki site with MediaWiki.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -

Latest article