mao
mao
Intern
Intern
  • UID1374
  • Fans1
  • Follows0
  • Posts8
Reads:1260Replies:0

Alibaba Cloud Tech Share - Self-host your personal knowledgebase: Mediawiki with Semantic MediaWiki

Created#
More Posted time:Feb 28, 2017 21:20 PM
MediaWiki is free and open-source wiki software, it runs on many websites, including Wikipedia, Wiktionary and Wikimedia Commons. It is written in the PHP programming language and stores the contents into a database. It's licensed under GPLv2+ so you are free to host your own instance on your Aliyun.

Currently Aliyun is running a great promotion of hosting package deal, order before March 31st 2017 and you can get free Data Transfer Plan, Domain and DNS for one year! Absolutely amazing deal! Follow this link to learn more about this special plan.

Semantic MediaWiki is an advanced extension of MediaWiki to improve its ability to search, organise, tag, browse, evaluate, and share the wiki's content. Semantic MediaWiki enables wikis to make their knowledge computer-processable, so that you can find and display the answer to this question - and to many more. Semantic MediaWiki has grown a long way from its roots as an academic research project. It is currently in active use in hundreds of sites, in many languages, around the world, including Fortune 500 companies, biomedical projects, government agencies and consumer directories. Here are quite a few exciting features of Semantic MediaWiki: automatically-generated lists, visual display of information, improved data structure, searching information, external reuse, integrate and mash-up data, you can find more detailed description and usage tutorials on the Semantic MedaiWiki website.

Below is a tutorial for you to self-host your personal knowledgebase on you Aliyun instance powered by MediaWiki and Semantic MediaWIki, this tutorial explains how to install MediaWiki and Semantic MediaWiki on a LEMP webserver stack:

MediaWiki runs on PHP and Mysql database so we need to first setup the environment for the application to run, so we are installing the LEMP (Linux, Nginx, Mysql and PHP) stack on our Aliyun instance. First log in into your Aliyun instance using SSH, the example is done on an Aliyun instance running Debian 8 Jessie x64, the current stable branch of Debian Linux. This tutorial should also work with Ubuntu, please use sudo command when you execute the commands.

Installing Mysql Database:

1) apt-get update && apt-get upgrade
2) apt-get install mysql-server
3) mysql_install_db
4) /usr/bin/mysql_secure_installation

The prompt will ask you for your current root password, choose a secure password for your Mysql database:

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Type "N" when asked again to change the root password.

Installing nginx webserver:
1) sudo apt-get install nginx
2) service nginx start

3) cat /etc/nginx/sites-available/default

Code snippet of the default nginx configuration
##################################
[...]
server {
        listen   80;

        root /usr/share/nginx/www;
        index index.php index.html index.htm;

        server_name example.com;

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

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;
        }

        # pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
                
        }

}
[...]
##################################

nano /etc/nginx/sites-available/wiki

paste the following contents:
##################################
server {
    server_name [YOUR DOMAIN NAME HERE];
    root /var/www/mediawiki;

    client_max_body_size 5m;
    client_body_timeout 60;

    location / {
        try_files $uri $uri/ @rewrite;
    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?title=$1&$args;
    }

    location ^~ /maintenance/ {
        return 403;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/php5-fpm.sock;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        try_files $uri /index.php;
        expires max;
        log_not_found off;
    }

    location = /_.gif {
        expires max;
        empty_gif;
    }


    location ^~ /cache/ {
        deny all;
    }

    location /dumps {
        root /var/www/mediawiki/local;
        autoindex on;
    }
}
##################################

Use Ctrl-O to write the changes and  use Ctrl-W to exit nano.

Install PHP to server the applications:

1) apt-get install php5-fpm php5-mysql
2) nano /etc/php5/fpm/php.ini

Find "cgi.fix_pathinfo=1" and change the 1 to 0.

cgi.fix_pathinfo=0

Use Ctrl-O to write the changes and  use Ctrl-W to exit nano.

3) nano /etc/php5/fpm/pool.d/www.conf

Find "listen = 127.0.0.1:9000", and change the "127.0.0.1:9000 to /var/run/php5-fpm.sock".

listen = /var/run/php5-fpm.sock

Use Ctrl-O to write the changes and  use Ctrl-W to exit nano.

4) service php5-fpm restart

Finally restart nginx webserver with service nginx restart.

Now we can proceed to install MediaWiki:
First we need to create a home for mediawiki:

mkdir /var/www/mediawiki
cd /var/www/mediawiki

You can download a release version of MediaWiki from the official download page: generally, if you're using a production environment, you want to be running the stable release.
To download MediaWiki 1.28.0, which is the latest stable release version, use the following command:

1) wget https://releases.wikimedia.org/mediawiki/1.28/mediawiki-1.28.0.tar.gz
2) tar xvzf mediawiki-*.tar.gz

Log in into your mysql database using mysql -u root -p, enter the mysql root password when prompted:
3) CREATE DATABASE wikidb;
GRANT ALL PRIVILEGES ON wikidb.* TO 'root'@'localhost' IDENTIFIED BY 'password';
4) GRANT ALL PRIVILEGES ON wikidb.* TO 'root'@'mediawiki.example.com' IDENTIFIED BY 'password';
5) exit;

Now point your domain name to your Aliyun instance, if your domain is registered elsewhere, you can use the domain control panel to add a A entry pointing at your Aliyun IP, @ or * would suffice. If you purchased your domain name as part of your Aliyun hosting package, you can refer to the Aliyun help documentation for instructions.

Open your browser, type in your domain name and the installation process should automatically start, remember to use correct mysql credentials and database name during the process. You can customize your MediaWiki installation during the process as well.

Now let's add Semantic MediaWiki to your MediaWiki installation:

Install Composer:
curl -s https://getcomposer.org/installer | php

Check if Composer is installed:

composer -V

cd /var/www/mediawiki

Run the following "initialization" command from the base directory of your MediaWiki installation (/var/www/mediawiki):

php composer.phar require mediawiki/semantic-media-wiki "~2.1" --update-no-dev

Run the setup script from the base directory of your MediaWiki installation (/var/www/mediawiki):

php maintenance/update.php

nano LocalSettings.php
add enableSemantics( 'example.org' );

Check the "Special:Version" page on your wiki and verify that the extension has been successfully installed and enabled.

Now you've finished the whole process and you can now start exploring the powerful knowledgebase system of MediaWiki and Semantic MediaWiki, have fun with your Aliyun!


References:
[1] https://www.semantic-mediawiki.org/wiki/Help:Introduction_to_Semantic_MediaWiki
[2] https://www.mediawiki.org/wiki/Manual:Installing_MediaWiki#Download_MediaWiki_software
[3] https://getcomposer.org/doc/00-intro.md#installation-nix
[4] https://www.mediawiki.org/wiki/FAQ#Installation_and_configuration
[5] https://www.nginx.com/resources/wiki/start/topics/recipes/mediawiki/


Update 1: deletion of extra spaces to make the tutorial look nicer, correction to php socket configuration.
[mao edited the post at Mar 1, 2017 14:23 PM]
Guest