Giter Club home page Giter Club logo

mediawiki-docker's Introduction

All-in-one Mediawiki Docker

OpenZIM Mediawiki Docker offers a straight forward solution to deploy Mediawki within only one Docker container.

CodeFactor License: GPL v3

Run

To create your Docker container:

sudo docker pull -a ghcr.io/offspot/mediawiki
sudo docker run -p 8080:80 \
  -v <YOUR_CUSTOM_DATA_DIRECTORY>:/var/www/data -it ghcr.io/offspot/mediawiki

Connect to your Docker container with your browser at http://localhost:8080/

User credentials

  • user: admin
  • password: mediawikipass

Note: you can temporarily restrict access to your mediawiki by setting the HTPASSWORD environment variable. This will not affect your wiki's configuration but accessing it will require to log-in with their browser using Username user and the passed password.

Customise

The data directory contains the database, images, file config and images. Everything which makes your Mediawiki instance unique. It is initialized when the container is created if needed files are not present (LocalSettings.custom.php and the MySQLite file).

You can customise the Mediawiki by editing your config/LocalSettings.custom.php. If you want to know more, have a look to this documentation: https://www.mediawiki.org/wiki/Manual:LocalSettings.php

Backup

All your data are available in your <YOUR_CUSTOM_DATA_DIRECTORY> data directory.

Build your own Docker image

docker build -t my_mediawiki .

Choose the database system

Set DATABASE_TYPE environnement variable at sqlite (default) or mysql.

Example:

sudo docker run -p 8080:80 \
  -e DATABASE_TYPE=mysql \
  -v <YOUR_CUSTOM_DATA_DIRECTORY>:/var/www/data -it ghcr.io/offspot/mediawiki

The SQLite file is in the data directory. The MySQL data dir is the mysql sub-directory of the data directory.

SQLite database initialisation

If the SQLite file do not exist, the database is initialized with a empty Mediawiki (only de Main_Page will exists).

MySQL database initialisation

To init a MySQL databse set MYSQL_INIT to 1.

To choose the database name set DATABASE_NAME. Default is my_wiki.

If a file import.sql exist in data direcory, it used to init the database.

If a SQLite file exist, the content of the database is imported in the MySQL database.

Example:

docker run -p 8080:80 \
  -e DATABASE_TYPE=mysql -e MYSQL_INIT=1 \
  -v /var/opt/florent/data/kiwix:/var/www/data -it ghcr.io/offspot/mediawiki

Initialize the data directory with a tarball

You can initialize your Mediawiki with existing images or a SQLite file from a downloaded database. Set VOLUME_TAR_URL environnement variable.

Export data

To export data as a tarbal, use this URL:

http://localhost:8080/export_data.php?token=EXPORT_TOKEN

You can set the secret export token when you run the container:

-e EXPORT_TOKEN=secret

Generate a SQLite database file from a MySQL database

Requirement:

  • A running MySQL service with a Mediawiki 1.31 database
  • Python 3
  • MySQL db module for Python 3

To prepare your environnement run:

apt-get install python3 python3-pip libmysqlclient-dev
python3 -m virtualenv env
source env/bin/activate
pip install -r mysql2sqlite_requirement.txt

To generate the SQLite database file, run:

./mysql2sqlite.py <mysqlHost> <mysqlUser> <mysqlPassword> <mysqlDatabase> <sqliteFile>

With:

  • mysqlHost : host where the MySQL service
  • mysqlUser : MySQL user
  • mysqlPassword : MySQL password
  • sqliteFile : SQLite database filename to generate

Example:

./mysql2sqlite.py localhost root secret my_wiki.sqlite

Then copy SQLite file in your custom data directory used by the docker container. Set the correct SQLite filename in config/LocalSettings.custom.php. If your data diretory is empty, run once the container to initialized it.

If your MySQL Mediawiki database is in a lower version of 1.31, you might migrate your database to 1.31 before generating the SQLite file. Then, upgrade your Mediawiki version to 1.31 first and generate the SQLite file as described above.

Custom favicon or logo

You can put your custom favicon.ico or logo.png in the directory site_root of your data volume. They will be linked to the real Web site root at the container start.

Author

Florent Kaisser [email protected]

License

GPLv3 or later, see LICENSE for more details.

mediawiki-docker's People

Contributors

florentk avatar kelson42 avatar rgaudin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

xiaosimple

mediawiki-docker's Issues

Mysql compatible backup solution

Improve the export data script we already have to:

  • export all the data even if MySQL is used
  • Allow to put a password to the export data URL to secure it. A password which would be set as a environment variable to the docker container

www.kiwix.org need additional extensions

$ grep "LANG"  LocalSettings.*
LocalSettings.custom.php:$LANG_EXT = "$IP/extensions/";
LocalSettings.custom.php:require_once( "$LANG_EXT/Babel/Babel.php" );
LocalSettings.custom.php:require_once( "$LANG_EXT/cldr/cldr.php" );
LocalSettings.custom.php:require_once( "$LANG_EXT/CleanChanges/CleanChanges.php" );
LocalSettings.custom.php:require_once( "$LANG_EXT/LocalisationUpdate/LocalisationUpdate.php" );
LocalSettings.custom.php:require_once( "$LANG_EXT/Translate/Translate.php" );
LocalSettings.custom.php:require_once( "$LANG_EXT/UniversalLanguageSelector/UniversalLanguageSelector.php" );

[Question] Where do I put custom skins?

Very new to this.

I want to install a custom skin and have updated the localsettings.custom.php but where do I upload the skin files to?
Do I need to mount a different volume for this?

Use nginx with phpfpm (instead of Apache)

Here is an example of virtualhost configuration

server {
  listen 443 ssl;
  server_name wiki.kiwix.org;

  # SSL
  ssl_certificate /etc/letsencrypt/live/wiki.kiwix.org/fullchain.pem; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/wiki.kiwix.org/privkey.pem; # managed by Certbot
  include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

#  access_log off;

  proxy_buffering on;
  proxy_cache nginx_cache;
  proxy_cache_min_uses 2;

  proxy_connect_timeout 5;
  proxy_send_timeout 90;
  proxy_read_timeout 600;
  
  client_max_body_size 0;

  set_real_ip_from 127.0.0.1;
  set_real_ip_from 88.190.13.50;
  real_ip_header X-Forwarded-For;

  location /w/images/ {
    alias /var/www/www.kiwix.org/w/images/;
    expires max;
  }

  location /w/skins/ {
    alias /var/www/www.kiwix.org/w/skins/;
    expires max;
  }

  location /logo.png {
    alias /var/www/www.kiwix.org/logo.png;
    expires max;
  }

  location /favicon.ico {
    alias /var/www/www.kiwix.org/favicon.ico;
    expires max;
  }

  location /robots.txt {
    alias /var/www/www.kiwix.org/robots.txt;
    expires max;
  }

  location /library.xml {
    return 301 $scheme://download.kiwix.org/library$request_uri;
  }
  
  location / {
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_pass http://localhost:82;
    proxy_set_header Host $host;
  }
}

Broken Special:Upload link in the sidebar

The link in the sidebar:

https://mediawiki.openzim.org/wiki/Special:Upload

fails

But:

https://mediawiki.openzim.org/index.php?title=Special:Upload

works

There is a problem I guess in the reverse proxy configuration.

A few remarks about that:

  • Using Apache is OK but quite overkill for just a reverse proxy. Nginx would be more appropriate, I think this is what was used in WikiFundi 1.0
  • To avoid collisions on the / level (for example if you want to setup something like /favicon.png, Wikipedia has moved the Mediawiki on the w/ and `wiki/ paths I would recommend to stick to that configuration. I think WikiFundi was also configured that way.
  • Doing so and reuse the Nginx configuration like in WikiFundi would avoid all these problem.

Mediawiki listening port needs to be specified on the command line

Currently, and following the doc, the nginx listen on 80 within the Docker put is rooted to 8080 outside the docker. The problem of this is that any redirection is broken, because redirection are created on the fly assuming port 80, so people get a wrong redirection. For example, it you type http://localhost:8080/ in your browser, you will be redirected to http://localhost:80/wiki/ and you should get http://localhost:8080/wiki/

Restore Mailgun extension

With 1.36.1 upgrade, Mailgun extension had to be disabled because one of its dependency (Guzzle) was conflicting with Mediawiki which also depends on it.

The problem is that both MW and MailGun bundle it separately but the Mailgun version is found by MW and attempted to use. The two different versions have a different API and this crashes every webpage to be displayed.

This looks like a problem that would commonly arise so there are probably solutions for this. Needs to be looked into.

Upstream Ticket I guess: https://phabricator.wikimedia.org/T263748

Sample Error:

MediaWiki internal error.

Original exception: [65f52eb171cb6c6e697e9ed8] /wiki/Special:MyLanguage/Main_Page Error: Call to undefined method GuzzleHttp\Utils::chooseHandler()
Backtrace:
from /var/www/html/w/vendor/guzzlehttp/guzzle/src/functions.php(61)
#0 /var/www/html/w/extensions/Mailgun/vendor/guzzlehttp/guzzle/src/HandlerStack.php(42): GuzzleHttp\choose_handler()
#1 /var/www/html/w/includes/http/GuzzleHttpRequest.php(164): GuzzleHttp\HandlerStack::create(NULL)
#2 /var/www/html/w/includes/filerepo/ForeignAPIRepo.php(531): GuzzleHttpRequest->execute()
#3 /var/www/html/w/includes/filerepo/ForeignAPIRepo.php(575): ForeignAPIRepo::httpGet(string, string, array, NULL)
#4 /var/www/html/w/includes/libs/objectcache/wancache/WANObjectCache.php(1707): ForeignAPIRepo->{closure}(boolean, integer, array, NULL, array)
#5 /var/www/html/w/includes/libs/objectcache/wancache/WANObjectCache.php(1539): WANObjectCache->fetchOrRegenerate(string, integer, Closure, array, array)
#6 /var/www/html/w/includes/filerepo/ForeignAPIRepo.php(585): WANObjectCache->getWithSetCallback(string, integer, Closure, array)
#7 /var/www/html/w/includes/filerepo/ForeignAPIRepo.php(199): ForeignAPIRepo->httpGetCached(string, array)
#8 /var/www/html/w/includes/filerepo/file/ForeignAPIFile.php(65): ForeignAPIRepo->fetchImageQuery(array)
#9 /var/www/html/w/includes/filerepo/FileRepo.php(431): ForeignAPIFile::newFromTitle(Title, ForeignAPIRepo)
#10 /var/www/html/w/includes/filerepo/ForeignAPIRepo.php(115): FileRepo->newFile(Title, boolean)
#11 /var/www/html/w/includes/filerepo/FileRepo.php(471): ForeignAPIRepo->newFile(Title)
#12 /var/www/html/w/includes/filerepo/RepoGroup.php(161): FileRepo->findFile(Title, array)
#13 /var/www/html/w/includes/BadFileLookup.php(71): RepoGroup->findFile(Title)
#14 /var/www/html/w/includes/parser/Parser.php(2616): MediaWiki\BadFileLookup->isBadFile(string, Title)
#15 /var/www/html/w/includes/parser/Parser.php(2379): Parser->handleInternalLinks2(string)
#16 /var/www/html/w/includes/parser/Parser.php(1578): Parser->handleInternalLinks(string)
#17 /var/www/html/w/includes/parser/Parser.php(639): Parser->internalParse(string)
#18 /var/www/html/w/includes/content/WikitextContent.php(375): Parser->parse(string, Title, ParserOptions, boolean, boolean, integer)
#19 /var/www/html/w/includes/content/AbstractContent.php(591): WikitextContent->fillParserOutput(Title, integer, ParserOptions, boolean, ParserOutput)
#20 /var/www/html/w/includes/Revision/RenderedRevision.php(263): AbstractContent->getParserOutput(Title, integer, ParserOptions, boolean)
#21 /var/www/html/w/includes/Revision/RenderedRevision.php(235): MediaWiki\Revision\RenderedRevision->getSlotParserOutputUncached(WikitextContent, boolean)
#22 /var/www/html/w/includes/Revision/RevisionRenderer.php(217): MediaWiki\Revision\RenderedRevision->getSlotParserOutput(string, array)
#23 /var/www/html/w/includes/Revision/RevisionRenderer.php(154): MediaWiki\Revision\RevisionRenderer->combineSlotOutput(MediaWiki\Revision\RenderedRevision, array)
#24 [internal function]: MediaWiki\Revision\RevisionRenderer->MediaWiki\Revision\{closure}(MediaWiki\Revision\RenderedRevision, array)
#25 /var/www/html/w/includes/Revision/RenderedRevision.php(197): call_user_func(Closure, MediaWiki\Revision\RenderedRevision, array)
#26 /var/www/html/w/includes/poolcounter/PoolWorkArticleView.php(137): MediaWiki\Revision\RenderedRevision->getRevisionParserOutput()
#27 /var/www/html/w/includes/poolcounter/PoolCounterWork.php(162): PoolWorkArticleView->doWork()
#28 /var/www/html/w/includes/page/ParserOutputAccess.php(281): PoolCounterWork->execute()
#29 /var/www/html/w/includes/page/Article.php(746): MediaWiki\Page\ParserOutputAccess->getParserOutput(WikiPage, ParserOptions, MediaWiki\Revision\RevisionStoreRecord, integer)
#30 /var/www/html/w/includes/page/Article.php(561): Article->generateContentOutput(User, ParserOptions, integer, OutputPage, array)
#31 /var/www/html/w/includes/actions/ViewAction.php(74): Article->view()
#32 /var/www/html/w/includes/MediaWiki.php(531): ViewAction->show()
#33 /var/www/html/w/includes/MediaWiki.php(315): MediaWiki->performAction(Article, Title)
#34 /var/www/html/w/includes/MediaWiki.php(913): MediaWiki->performRequest()
#35 /var/www/html/w/includes/MediaWiki.php(546): MediaWiki->main()
#36 /var/www/html/w/index.php(53): MediaWiki->run()
#37 /var/www/html/w/index.php(46): wfIndexMain()
#38 {main}

Exception caught inside exception handler: [65f52eb171cb6c6e697e9ed8] /wiki/Special:MyLanguage/Main_Page Error: Call to undefined method GuzzleHttp\Utils::chooseHandler()
Backtrace:
from /var/www/html/w/vendor/guzzlehttp/guzzle/src/functions.php(61)
#0 /var/www/html/w/extensions/Mailgun/vendor/guzzlehttp/guzzle/src/HandlerStack.php(42): GuzzleHttp\choose_handler()
#1 /var/www/html/w/includes/http/GuzzleHttpRequest.php(164): GuzzleHttp\HandlerStack::create(NULL)
#2 /var/www/html/w/includes/filerepo/ForeignAPIRepo.php(531): GuzzleHttpRequest->execute()
#3 /var/www/html/w/includes/filerepo/ForeignAPIRepo.php(575): ForeignAPIRepo::httpGet(string, string, array, NULL)
#4 /var/www/html/w/includes/libs/objectcache/wancache/WANObjectCache.php(1707): ForeignAPIRepo->{closure}(boolean, integer, array, NULL, array)
#5 /var/www/html/w/includes/libs/objectcache/wancache/WANObjectCache.php(1539): WANObjectCache->fetchOrRegenerate(string, integer, Closure, array, array)
#6 /var/www/html/w/includes/filerepo/ForeignAPIRepo.php(585): WANObjectCache->getWithSetCallback(string, integer, Closure, array)
#7 /var/www/html/w/includes/filerepo/ForeignAPIRepo.php(199): ForeignAPIRepo->httpGetCached(string, array)
#8 /var/www/html/w/includes/filerepo/file/ForeignAPIFile.php(65): ForeignAPIRepo->fetchImageQuery(array)
#9 /var/www/html/w/includes/filerepo/FileRepo.php(431): ForeignAPIFile::newFromTitle(Title, ForeignAPIRepo)
#10 /var/www/html/w/includes/filerepo/ForeignAPIRepo.php(115): FileRepo->newFile(Title, boolean)
#11 /var/www/html/w/includes/filerepo/FileRepo.php(471): ForeignAPIRepo->newFile(Title)
#12 /var/www/html/w/includes/filerepo/RepoGroup.php(161): FileRepo->findFile(Title, array)
#13 /var/www/html/w/includes/BadFileLookup.php(71): RepoGroup->findFile(Title)
#14 /var/www/html/w/includes/parser/Parser.php(2616): MediaWiki\BadFileLookup->isBadFile(string, Title)
#15 /var/www/html/w/includes/parser/Parser.php(2379): Parser->handleInternalLinks2(string)
#16 /var/www/html/w/includes/parser/Parser.php(1578): Parser->handleInternalLinks(string)
#17 /var/www/html/w/includes/parser/Parser.php(639): Parser->internalParse(string)
#18 /var/www/html/w/includes/OutputPage.php(2115): Parser->parse(string, Title, ParserOptions, boolean, boolean, integer)
#19 /var/www/html/w/includes/OutputPage.php(2065): OutputPage->parseInternal(string, Title, boolean, boolean)
#20 /var/www/html/w/includes/skins/Skin.php(2035): OutputPage->parseAsInterface(string)
#21 /var/www/html/w/includes/libs/objectcache/wancache/WANObjectCache.php(1707): Skin->{closure}(boolean, integer, array, NULL, array)
#22 /var/www/html/w/includes/libs/objectcache/wancache/WANObjectCache.php(1539): WANObjectCache->fetchOrRegenerate(string, integer, Closure, array, array)
#23 /var/www/html/w/includes/skins/Skin.php(2036): WANObjectCache->getWithSetCallback(string, integer, Closure)
#24 /var/www/html/w/includes/skins/Skin.php(2063): Skin->getCachedNotice(string)
#25 /var/www/html/w/includes/skins/SkinMustache.php(180): Skin->getSiteNotice()
#26 /var/www/html/w/skins/Vector/includes/SkinVector.php(177): SkinMustache->getTemplateData()
#27 /var/www/html/w/includes/skins/SkinMustache.php(136): SkinVector->getTemplateData()
#28 /var/www/html/w/includes/skins/SkinTemplate.php(146): SkinMustache->generateHTML()
#29 /var/www/html/w/includes/OutputPage.php(2634): SkinTemplate->outputPage()
#30 /var/www/html/w/includes/exception/MWExceptionRenderer.php(147): OutputPage->output()
#31 /var/www/html/w/includes/exception/MWExceptionRenderer.php(66): MWExceptionRenderer::reportHTML(Error)
#32 /var/www/html/w/includes/exception/MWExceptionHandler.php(106): MWExceptionRenderer::output(Error, integer)
#33 /var/www/html/w/includes/exception/MWExceptionHandler.php(185): MWExceptionHandler::report(Error)
#34 /var/www/html/w/includes/MediaWiki.php(568): MWExceptionHandler::handleException(Error, string)
#35 /var/www/html/w/index.php(53): MediaWiki->run()
#36 /var/www/html/w/index.php(46): wfIndexMain()
#37 {main}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.