Jump to content

MediaWiki:Installasi on Ubuntu 20.04 (Nginx): Difference between revisions

From Wiki
Created page with "MediaWiki is a wiki application written in PHP that the Wikimedia Foundation developed to run several of their projects. The encyclopedia Wikipedia is the most popular of thes..."
 
No edit summary
Line 1: Line 1:
MediaWiki is a wiki application written in PHP that the Wikimedia Foundation developed to run several of their projects. The encyclopedia Wikipedia is the most popular of these projects.
==Step 1: Downloading MediaWiki==
*Download the latest stable version of MediaWiki:
wget https://releases.wikimedia.org/mediawiki/1.36/mediawiki-1.36.2.tar.gz


A wiki is a type of website that allows its users to create and edit content in a collaborative manner. It can be used in several ways, including as a knowledge base, documentation library, community website, or company intranet.
*Extract the archive to /var/www/.
sudo mkdir -p /var/www/


These kinds of websites are especially useful in contexts where several people need to create and modify pages in a quick and easy way.
sudo tar xvf mediawiki-1.36.2.tar.gz -C /var/www/


This guide will show you how to install and set up the application, giving you the basis to deploy your own wiki site.
*Rename the directory.
We will use the domain name “mediawiki.example.com” in this guide. Replace it with the domain name or IP address you have configured on your server.


==Prerequisites==
sudo mv /var/www/mediawiki-1.36.2 /var/www/nama_situs
*An Ubuntu 20.04 server. You can run MediaWiki on a different flavor of GNU/Linux, but the steps outlined below could differ.
*A root password is set up on the server.


===Step 1 – Create Atlantic.Net Cloud Server===
Then we need to install some PHP extensions required by MediaWiki.
First, log in to your Cloud Server. Create a new server, choosing Ubuntu 20.04 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.


Once you are logged in to your Ubuntu 20.04 server, run the following command to update your base system with the latest available packages.
sudo apt install php7.4-mbstring php7.4-xml php7.4-fpm php7.4-json php7.4-mysql php7.4-curl php7.4-intl php7.4-gd php7.4-mbstring texlive imagemagick


apt-get update -y
If you use Apache web server, then you need to restart Apache.


===Step 2 – Install LAMP Server===
sudo systemctl restart apache2
*First, you will need to install the Apache, MariaDB, PHP and other PHP extensions to your server. You can install all of them using the following command:
apt-get install apache2 mariadb-server php libapache2-mod-php 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, you can proceed to create a database.
Next, we need to install external dependencies via Composer (a PHP dependency manager).


===Step 3 – Create a Database===
sudo apt install composer
*Next, login to the MariaDB shell with the following command:
mysql


*Once you are login, create a database and user for MediaWiki with the following command:
cd /var/www/mediawiki/
CREATE DATABASE mediawiki;
GRANT ALL PRIVILEGES ON mediawiki.* TO 'wikiuser'@'localhost' IDENTIFIED BY 'password';


*Next, flush the privileges and exit from the MariaDB with the following command:
sudo composer install --no-dev
flush privileges;
exit;


*At this point, your MariaDB database is created.
Note that MediaWiki currently doesn’t support PHP8.0. If you have installed PHP8.0 on your Ubuntu server, then you should run sudo update-alternatives --config php command to set PHP7.4 as the default version.


===Step 4 – Download MediaWiki===
Once all dependencies are installed, run the following command to set web server user (www-data) as the owner of this directory.
*Next, you will need to download the latest version of MediaWiki to the Apache web root directory. You can download it with the following command:
wget https://releases.wikimedia.org/mediawiki/1.36/mediawiki-1.36.2.zip


*Once the download is completed, unzip the downloaded file with the following command:
sudo chown www-data:www-data /var/www/mediawiki/ -R
unzip mediawiki-1.36.2.zip


*Next, move the extracted directory to the Apache web root directory:
Step 2: Creating a Database
mv mediawiki-1.36.2 /var/www/html/mediawiki


*Next, you will need to install Composer in your system. You can install it with the following command:
Log into MariaDB server with the command below.
apt-get install composer -y


*Once the Composer is installed, change the directory to the MediaWiki and install all PHP dependencies using the following command:
sudo mysql -u root
cd /var/www/html/mediawiki
composer install --no-dev


*Once all the dependencies are installed, set proper permission to the MediaWiki with the following command:
Create a database for MediaWiki. This tutorial name the database mediawiki, but you can use whatever name you like.
chown -R www-data:www-data /var/www/html/mediawiki


===Step 5 – Configure Apache for MediaWiki===
CREATE DATABASE mediawiki;


*Next, create an Apache virtual host configuration file for MediaWiki with the following command:
Then run the following command at MariaDB prompt to create a database user and grant privileges to this user. Replace mediawiki, wikiuser and password with your preferred database name, database username and user password respectively.
nano /etc/apache2/sites-available/mediawiki.conf


*Add the following lines:
GRANT ALL PRIVILEGES ON mediawiki.* TO 'wikiuser'@'localhost' IDENTIFIED BY 'password';
<VirtualHost *:80>
    ServerAdmin admin@example.com
    DocumentRoot /var/www/html/mediawiki/
    ServerName mediawiki.example.com
    <Directory /var/www/html/mediawiki/>
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    ErrorLog /var/log/apache2/mediawiki_error
    CustomLog /var/log/apache2/mediawiki_access common
</VirtualHost>


*Save and close the file then enable the virtual host file and restart the Apache service with the following command:
Next, flush MariaDB privileges and exit.
a2ensite mediawiki.conf
systemctl reload apache2


==Source==
flush privileges;
*[https://bit.ly/3lX8yJj atlantic.net]
 
exit;
 
Step 3: Create Apache Virtual Host or Nginx Config File for MediaWiki
Apache
 
If you use Apache web server, create a virtual host for MediaWiki.
 
sudo nano /etc/apache2/sites-available/mediawiki.conf
 
Copy and paste the following text into the file. Replace wiki.your-domain.com with your actual domain name. Don’t forget to create DNS A record for this domain name.
 
<VirtualHost *:80>
    ServerAdmin admin@your-domain.com
    DocumentRoot /var/www//mediawiki/
    ServerName wiki.your-domain.com
 
    <Directory /var/www/html/mediawiki/>
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
 
    ErrorLog /var/log/apache2/mediawiki_error
    CustomLog /var/log/apache2/mediawiki_access common
</VirtualHost>
 
Save and close the file. Then enable this virtual host.
 
sudo a2ensite mediawiki.conf
 
Reload Apache for the above changes to take effect.
 
sudo systemctl reload apache2
 
Nginx
 
If you use Nginx web server, create a server block file for MediaWiki under /etc/nginx/conf.d/ directory.
 
sudo nano /etc/nginx/conf.d/mediawiki.conf
 
Copy the following text and paste it into the file. Replace wiki.your-domain.com with your actual domain name. Don’t forget to create DNS A record for this domain name.
 
server {
        listen 80;
        listen [::]:80;
        server_name wiki.your-domain.com;
 
        root /var/www/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 ~ /.well-known {
            allow all;
        }
 
        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 test Nginx configuration.
 
sudo nginx -t
 
If the test is successful, reload Nginx web server.
 
sudo systemctl reload nginx
 
Step 4: Enabling HTTPS
 
To encrypt the HTTP traffic, we can enable HTTPS by installing a free TLS certificate issued from Let’s Encrypt. Run the following command to install Let’s Encrypt client (certbot) on Ubuntu 20.04 server.
 
sudo apt install certbot
 
If you use Apache, install the Certbot Apache plugin.
 
sudo apt install python3-certbot-apache
 
And run this command to obtain and install TLS certificate.
 
sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d wiki.your-domain.com
 
If you use Nginx, then you also need to install the Certbot Nginx plugin.
 
sudo apt install python3-certbot-nginx
 
Next, run the following command to obtain and install TLS certificate.
 
sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d wiki.your-domain.com
 
Where
 
    --nginx: Use the nginx plugin.
    --apache: Use the Apache plugin.
    --agree-tos: Agree to terms of service.
    --redirect: Force HTTPS by 301 redirect.
    --hsts: Add the Strict-Transport-Security header to every HTTP response. Forcing browser to always use TLS for the domain. Defends against SSL/TLS Stripping.
    --staple-ocsp: Enables OCSP Stapling. A valid OCSP response is stapled to the certificate that the server offers during TLS.
 
The certificate should now be obtained and automatically installed.

Revision as of 11:34, 31 October 2021

Step 1: Downloading MediaWiki

  • Download the latest stable version of MediaWiki:
wget https://releases.wikimedia.org/mediawiki/1.36/mediawiki-1.36.2.tar.gz
  • Extract the archive to /var/www/.
sudo mkdir -p /var/www/
sudo tar xvf mediawiki-1.36.2.tar.gz -C /var/www/
  • Rename the directory.

sudo mv /var/www/mediawiki-1.36.2 /var/www/nama_situs

Then we need to install some PHP extensions required by MediaWiki.

sudo apt install php7.4-mbstring php7.4-xml php7.4-fpm php7.4-json php7.4-mysql php7.4-curl php7.4-intl php7.4-gd php7.4-mbstring texlive imagemagick

If you use Apache web server, then you need to restart Apache.

sudo systemctl restart apache2

Next, we need to install external dependencies via Composer (a PHP dependency manager).

sudo apt install composer

cd /var/www/mediawiki/

sudo composer install --no-dev

Note that MediaWiki currently doesn’t support PHP8.0. If you have installed PHP8.0 on your Ubuntu server, then you should run sudo update-alternatives --config php command to set PHP7.4 as the default version.

Once all dependencies are installed, run the following command to set web server user (www-data) as the owner of this directory.

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

Step 2: Creating a Database

Log into MariaDB server with the command below.

sudo mysql -u root

Create a database for MediaWiki. This tutorial name the database mediawiki, but you can use whatever name you like.

CREATE DATABASE mediawiki;

Then run the following command at MariaDB prompt to create a database user and grant privileges to this user. Replace mediawiki, wikiuser and password with your preferred database name, database username and user password respectively.

GRANT ALL PRIVILEGES ON mediawiki.* TO 'wikiuser'@'localhost' IDENTIFIED BY 'password';

Next, flush MariaDB privileges and exit.

flush privileges;

exit;

Step 3: Create Apache Virtual Host or Nginx Config File for MediaWiki Apache

If you use Apache web server, create a virtual host for MediaWiki.

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

Copy and paste the following text into the file. Replace wiki.your-domain.com with your actual domain name. Don’t forget to create DNS A record for this domain name.

<VirtualHost *:80>

   ServerAdmin admin@your-domain.com
   DocumentRoot /var/www//mediawiki/
   ServerName wiki.your-domain.com
   <Directory /var/www/html/mediawiki/>
       Options FollowSymLinks
       AllowOverride All
       Order allow,deny
       allow from all
   </Directory>
   ErrorLog /var/log/apache2/mediawiki_error
   CustomLog /var/log/apache2/mediawiki_access common

</VirtualHost>

Save and close the file. Then enable this virtual host.

sudo a2ensite mediawiki.conf

Reload Apache for the above changes to take effect.

sudo systemctl reload apache2

Nginx

If you use Nginx web server, create a server block file for MediaWiki under /etc/nginx/conf.d/ directory.

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

Copy the following text and paste it into the file. Replace wiki.your-domain.com with your actual domain name. Don’t forget to create DNS A record for this domain name.

server {

       listen 80;
       listen [::]:80;
       server_name wiki.your-domain.com;
       root /var/www/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 ~ /.well-known {
           allow all;
       }
       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 test Nginx configuration.

sudo nginx -t

If the test is successful, reload Nginx web server.

sudo systemctl reload nginx

Step 4: Enabling HTTPS

To encrypt the HTTP traffic, we can enable HTTPS by installing a free TLS certificate issued from Let’s Encrypt. Run the following command to install Let’s Encrypt client (certbot) on Ubuntu 20.04 server.

sudo apt install certbot

If you use Apache, install the Certbot Apache plugin.

sudo apt install python3-certbot-apache

And run this command to obtain and install TLS certificate.

sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d wiki.your-domain.com

If you use Nginx, then you also need to install the Certbot Nginx plugin.

sudo apt install python3-certbot-nginx

Next, run the following command to obtain and install TLS certificate.

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d wiki.your-domain.com

Where

   --nginx: Use the nginx plugin.
   --apache: Use the Apache plugin.
   --agree-tos: Agree to terms of service.
   --redirect: Force HTTPS by 301 redirect.
   --hsts: Add the Strict-Transport-Security header to every HTTP response. Forcing browser to always use TLS for the domain. Defends against SSL/TLS Stripping.
   --staple-ocsp: Enables OCSP Stapling. A valid OCSP response is stapled to the certificate that the server offers during TLS.

The certificate should now be obtained and automatically installed.