This repo contains Docker Compose containers to run the MediaWiki software.
Clone the repo, create and start containers:
git clone https://github.com/pastakhov/compose-mediawiki-ubuntu.git
cd compose-mediawiki-ubuntu
docker-compose upWait for the completion of the build and initialization process and access it via http://localhost:8080 in a browser.
Enjoy with MediaWiki + VisualEditor + Elasticsearch + most popular extensions
Running sudo docker-compose up in a checkout of this repository will start containers:
db- A MySQL container, used as the database backend for MediaWiki.elasticsearch- An Elasticsearch container, used as the full-text search engine for MediaWikimemcached- A memory object caching system container, used as the cache system for MediaWikiparsoid- A bidirectional runtime wikitext parser container, used by VisualEditor, Flow and other MediaWiki extensionsproxy- Varnish reverse proxy server container which reduces the time taken to serve often-requested pagesrestbase- A REST storage and service dispatcher containerweb- An Apache/MediaWiki container with PHP 7.0 and MediaWiki 1.29
The elasticsearch, parsoid, restbase, proxy, web containers are based on Ubuntu 16.04
Settings are in the docker-compose.yml file, the environment sections
Was cloned from official mysql container and has the same environment variables.
The reason why it is better than the official is the ability to automatically update the database when upgrading the version of mysql.
The only one important environment variable for us is MYSQL_ROOT_PASSWORD, it specifies the password that will be set for the MySQL root superuser account.
If changed, make sure that MW_DB_INSTALLDB_PASS in web section was changed too.
PROXY_BACKEND_{name}defines backend using format 'host:port'. Generally backend name should be the same as container name. Example:PROXY_BACKEND_web=web:80.
More details on Varnish service page.
The proxy container are listening for connections on private port 80. By default the public port for connections is 8080:
ports:
- "8080:80"
You are welcome to change it to any you would like, just note: make sure that MW_SITE_SERVER has correct value
PARSOID_DOMAIN_{domain}defines uri and domain for the Parsoid service. The '{domain}' word should be the same as theMW_REST_DOMAINparameter in the web container. You can specify any number of such variables (by the number of domains used for the service).
More details on Parsoid service page.
RB_CONF_DOMAIN_{domain}defines uri and domain for the RESTBase service. The '{domain}' word should be the same as theMW_REST_DOMAINparameter in the web container. You can specify any number of such variables (by the number of domains used for the service). Example:RB_CONF_DOMAIN_web=http://web/w/api.php.RB_CONF_PARSOID_HOSTdefines uri to Parsoid service. Example:http://parsoid:8000.RB_CONF_API_URI_TEMPLATEdefines uri to the MediaWiki API. Example :http://{domain}/w/api.phpRB_CONF_BASE_URI_TEMPLATEdefines base uri for the links to RESTBase service. Example:http://{domain}/api/rest_v1.
More details on RESTbase service page.
MW_SITE_SERVERconfigures $wgServer, set this to the server host and include the protocol likehttp://my-wiki:8080MW_SITE_NAMEconfigures $wgSitenameMW_SITE_LANGconfigures $wgLanguageCodeMW_DEFAULT_SKINconfigures $wgDefaultSkinMW_ENABLE_UPLOADSconfigures $wgEnableUploadsMW_USE_INSTANT_COMMONSconfigures $wgUseInstantCommonsMW_ADMIN_USERconfigures default administrator usernameMW_ADMIN_PASSconfigures default administrator passwordMW_DB_NAMEspecifies database name that will be created automatically upon container startupMW_DB_USERspecifies database user for access to database specified inMW_DB_NAMEMW_DB_PASSspecifies database user passwordMW_DB_INSTALLDB_USERspecifies database superuser name for create database and user specified aboveMW_DB_INSTALLDB_PASSspecifies database superuser password, should be the same asMYSQL_ROOT_PASSWORDin db section.MW_PROXY_SERVERS(comma separated values) configures $wgSquidServers. Leave empty if no reverse proxy server used.MW_MAIN_CACHE_TYPEconfigures $wgMainCacheType.MW_MEMCACHED_SERVERSshould be provided forCACHE_MEMCACHED.MW_MEMCACHED_SERVERS(comma separated values) configures $wgMemCachedServers.MW_SEARCH_TYPEconfigures $wgSearchType. Leave empty or setCirrusSearchfor MediaWiki using Elasticsearch.MW_CIRRUS_SEARCH_SERVERSshould be provided forCirrusSearch.MW_FLOW_NAMESPACES(comma separated values) specifies namespaces where the Flow extension should be enabled.MW_REST_DOMAINspecifies the domain parameter used for the REST services such as Parsoid and RESTBase, generally should be the same as the name of the container.MW_REST_RESTBASE_PROXY_PATHif reverse proxy are used defines path for the $wgVisualEditorFullRestbaseURL and $wgVisualEditorRestbaseURL variables. Example:/api/rest_.MW_AUTOUPDATEiftrue(by default) run needed maintenance scripts automatically before web server start.MW_SHOW_EXCEPTION_DETAILSiftrue(by default) configures $wgShowExceptionDetails as true.PHP_LOG_ERRORSspecifieslog_errorsparameter inphp.inifile.PHP_ERROR_REPORTINGspecifieserror_reportingparameter inphp.inifile.E_ALLby default, on production should be changed toE_ALL & ~E_DEPRECATED & ~E_STRICT.
The LocalSettings.php devided to three parts:
- LocalSettings.php will be created automatically upon container startup, contains settings specific to the MediaWiki installed instance such as database connection, $wgSecretKey and etc. Should not be changed
- DockerSettings.php сontains settings specific to the released containers such as database server name, path to programs, installed extensions, etc. Should be changed if you make changes to the containers only
- CustomSettings.php - contains user defined settings such as user rights, extensions settings and etc. You should make changes there.
CustomSettings.phpplaced in folderwebAnd will be copied to the container during build
The $wgLogo variable is set to $wgScriptPath/logo.png value.
The web/logo.png file will be copied to $wgScriptPath/logo.png path during build.
For change the logo just replace the web/logo.png file by your logo file and rebuild container
The $wgFavicon variable is set to $wgScriptPath/favicon.ico value.
The web/favicon.ico file will be copied to $wgScriptPath/favicon.ico path during build.
For change the favicon just replace the web/favicon.ico file by your favicon file and rebuild container
How do I rebuild the containers to accept changes to the settings? Just use the command:
docker-compose up --buildIt picks up the changes by stopping and recreating the containers.
Why should I rebuild the container every time I change the settings? In this case you are able to check on changes locally before deploy ones to your server. This solution significantly reduces the likelihood that something will be broken on your server when you change the settings.
During the first start, the MediaWiki will be fully initialized according to the settings specified in the docker-compose.yml file.
This process includes:
- initialize database, create
rootuser - initialize elasticsearch storage
- initialize MediaWiki:
- run
install.phpmaintenance script that creates MediaWiki database, user and write settings to LocalSettings.php file. - include
web\DockerSettings.phpfile to LocalSettings.php that contains minimal needed settings for installed MediaWiki extensions - run
update.phpmaintenance script that updated MediaWiki database schema for MediaWiki extensions - generate elasticsearch index and bootstrap the search index
- get the latest data for CLDR and UniversalLanguageSelector extensions
- run
populateContentModel.phpmaintenance script that populates the fields nedeed for use the Flow extension on all namespaces
- run
Make a full backup of the wiki, including both the database and the files. While the upgrade scripts are well-maintained and robust, things could still go awry.
cd compose-mediawiki-ubuntu
docker-compose exec db /bin/bash -c 'mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD" 2>/dev/null | gzip | base64 -w 0' | base64 -d > backup_$(date +"%Y%m%d_%H%M%S").sql.gz
docker-compose exec web /bin/bash -c 'tar -c $MW_VOLUME $MW_HOME/images 2>/dev/null | base64 -w 0' | base64 -d > backup_$(date +"%Y%m%d_%H%M%S").tarpicking up the latest changes, stop, rebuld and start containers:
cd compose-mediawiki-ubuntu
git pull
docker-compose build
docker-compose stop
docker-compose upThe upgrade process is fully automated and includes the launch of all necessary maintenance scripts (only when it is really required)
web/var/www/html/w/images- files uploaded by users/mediawiki- contains info about the MediaWiki instance