Jump to content

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

From Wiki
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Step 1: Downloading MediaWiki==
__NOTOC__
===Step 1: Downloading MediaWiki===
*Download the latest stable version of MediaWiki:
*Download the latest stable version of MediaWiki:
  wget https://releases.wikimedia.org/mediawiki/1.36/mediawiki-1.36.2.tar.gz
  wget <nowiki>https://releases.wikimedia.org/mediawiki/1.36/mediawiki-1.36.2.tar.gz</nowiki>


*Extract the archive to /var/www/.
*Extract the archive to /var/www/.
Line 21: Line 22:
  sudo composer install --no-dev
  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.
<blockquote>
'''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.
</blockquote>


*Once all dependencies are installed, run the following command to set web server user (www-data) as the owner of this directory.
*Once all dependencies are installed, run the following command to set web server user (www-data) as the owner of this directory.
Line 27: Line 30:
  sudo chown www-data:www-data /var/www/mediawiki/ -R
  sudo chown www-data:www-data /var/www/mediawiki/ -R


==Step 2: Creating a Database==
===Step 2: Creating a Database===
*Log into MariaDB server with the command below.
*Log into [[MariaDB]] server with the command below.
  sudo mysql -u root
  sudo mysql -u root


Line 42: Line 45:
  exit;
  exit;


==Step 3: Create Apache Virtual Host or Nginx Config File for MediaWiki==
===Step 3: Create Apache Virtual Host or Nginx Config File for MediaWiki===
===Nginx===
===Nginx===
*If you use Nginx web server, create a server block file for MediaWiki under <code>/etc/nginx/conf.d/</code> directory.
*If you use Nginx web server, create a server block file for MediaWiki under <code>/etc/nginx/conf.d/</code> directory.
Line 82: Line 85:
*Save and close the file. Then test Nginx configuration.
*Save and close the file. Then test Nginx configuration.
  sudo nginx -t
  sudo nginx -t
'''Output sample'''
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


*If the test is successful, reload Nginx web server.
*If the test is successful, reload Nginx web server.
  sudo systemctl reload nginx
  sudo systemctl reload nginx


==Step 4: Enabling HTTPS==
===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.
*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
  sudo apt install certbot
Line 97: Line 104:


'''Where'''
'''Where'''
*--nginx: Use the nginx plugin.
*<code>--nginx</code>: Use the nginx plugin.
*--apache: Use the Apache plugin.
*<code>--apache</code>: Use the Apache plugin.
*--agree-tos: Agree to terms of service.
*<code>--agree-tos</code>: Agree to terms of service.
*--redirect: Force HTTPS by 301 redirect.
*<code>--redirect</code>: 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.
*<code>--hsts</code>: 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.
*<code>--staple-ocsp</code>: 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.
*The certificate should now be obtained and automatically installed.
==Terkait==
*[[MariaDB]]
*[[Server]]
*[[MediaWiki]]
[[Category:Tutorial]]
[[Category:CMS]]
[[Category:Server]]

Latest revision as of 14:45, 19 December 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
  • 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

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

Output sample

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
  • 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 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.

Terkait