Docker Compose bootstrap for WikiTeq's MediaWiki image
This is a sample bootstrap compose stack, see quick start instructions below.
- Clone the repository
- Copy the
.env.exampleto.env - Modify the
.envas needed - Run
./compose up -d
Note: the compose.sh is a special wrapper that provides support for
docker-compose.yml extensions. You'll find more information on the extension
below, but generally it's recommended to use ./compose instead of docker-compose.
The ./compose is a simple wrapper, so you can pass any arguments to it similarly
how it could be done with the original docker-compose, eg:
./compose ps
./compose up -d
./compose down
./compose restart
# etcThe stack is composed of the following containers:
Required:
db- MySQL, a database backend for MediaWiki.web- Apache/MediaWiki container with PHP on the board
Optional, can be enabled via compose-extension:
redis- Redis cache ( seedocker-compose/redis.yml.example)elasticsearch- ElasticSearch instance ( seedocker-compose/elasticsearch.yml.example)matomo- Matomo site analytics
All the configurations must be done via modifying the .env file,
see .env.example for a list of variables
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 the default administrator usernameMW_ADMIN_PASSconfigures the default administrator passwordMW_DB_NAMEspecifies the database name that will be created automatically upon container startupMW_DB_USERspecifies the database user for access to the database specified inMW_DB_NAMEMW_DB_PASSspecifies the database user passwordMW_DB_INSTALLDB_USERspecifies the database superuser name for create database and user specified aboveMW_DB_INSTALLDB_PASSspecifies the 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_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.MW_ENABLE_SITEMAP_GENERATORdefines if sitemap generation is enabled or notMW_SITEMAP_PAUSE_DAYSif the above is enabled, sets the delys between sitemap regenerationsPHP_UPLOAD_MAX_FILESIZEsets max upload sizePHP_POST_MAX_SIZEsets max post sizeLOG_FILES_COMPRESS_DELAYsets logs compression delay in secondsLOG_FILES_REMOVE_OLDER_THAN_DAYSsets lifespan for old logsMW_ENABLE_TRANSCODERdefines if the transcoder service is enabledMW_JOB_TRANSCODER_PAUSEsets the transcoder service delay in secondsMW_ENABLE_JOB_RUNNERdefines if the job runner service is enabledMW_JOB_RUNNER_PAUSEsets the job runner service delay in secondsMW_ENABLE_EMAILcontrols the$wgEnableEmailMW_ENABLE_USER_EMAILcontrols the$wgEnableUserEmailMW_EMERGENCY_CONTACTcontrols the$wgEmergencyContactMW_PASSWORD_SENDERcontrols the$wgPasswordSenderMW_DB_TYPEcontrols the$wgDBtypeMW_DB_SERVERcontrols the$wgDBserverMW_DB_NAMEcontrols the$wgDBnameMW_USE_CACHE_DIRECTORYcontrols the$wgCacheDirectory, if set totrueputs$IP/cacheas a valueMW_SECRET_KEYcontrols the$wgSecretKeyMW_USE_IMAGE_MAGICcontrols the$wgUseImageMagickMW_LOAD_SKINScontrols the list of extension to enable out of the pre-installed skins list (see below)MW_LOAD_EXTENSIONScontrols the list of extension to enable out of the pre-installed extensions list (see below)MATOMO_USER- Matomo username, fill in after initial Matomo setupMATOMO_PASSWORD- Matomo password, fill in after initial Matomo setupMATOMO_URL- URL of the Matomo instance within the network, keep as it in most cases
The stack will optionally load a settings file from the _settings/LocalSettings.php
and will append it to the bottom of the original LocalSettings.php of the container.
The proper way to make modifications or additions to the orignal
docker-compose.yml is to add override-files to the docker-compose
directory, see logo.yml.example. Only files with .yml extension
are loaded.
This is based on the Compose extends feature.
For example:
- Create
_resourcesdirectory and put your logo there (_resources/logo.png) - Create
logo.ymlfile inside thedocker-composedirectory with the following contents:
version: '3.1'
services:
web:
volumes:
- ./_resources/logo.png:/var/www/html/w/logo.png- And run or re-create the stack via
./compose up -d
Please refer to the https://docs.docker.com/compose/extends/#adding-and-overriding-configuration
for details about docker-compose.yml overriding specifics.
Pull the latest image, stop, rebuild and start containers:
docker pull ghcr.io/wikiteq/mediawiki:latest
./compose up -d./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
./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").tarOne of the way to keep the stack up to date and hence separated from your deployment changes if to follow the deployment procedure below:
- Clone the stack into, say,
docker-wikiteq-stack - Copy the
.env.exampleto.env(it's git-ignored) - Override compose stack with new files created within
docker-composedirectory (they're git-ignored too) - Follow the instructions above to put your custom files like logos or custom extensions into
_resourcesdirectory (which is fully git-ignored) - Keep the custom PHP settings files within the
_settingsdirectory (which is git-ignored too)
With the setup above you should have no issues with updating the stack base like below:
cd docker-wikiteq-stack && git pull
./compose up -dThe limitation of the approach above is that you can't version your own changes to the stack. To workaround this you can try another method like below:
-
Clone the stack into, say,
docker-wikiteq-stack -
Create new directory for your modifications, say,
docker-wikiteq-stack-MyWiki -
Put all your customizations there and symlink all the files to their directories within the
docker-wikiteq-stack. For example: -
docker-wikiteq-stack-MyWiki/_settings/LocalSettings.phpsymlinked todocker-wikiteq-stack/_settings/LocalSettings.php -
docker-wikiteq-stack-MyWiki/_resources/logo.pngsymlinked todocker-wikiteq-stack/_resources/logo.png -
docker-wikiteq-stack-MyWiki/docker-compose/redis.ymlsymlinked todocker-wikiteq-stack/docker-compose/redis.yml -
docker-wikiteq-stack-MyWiki/.evnsymlinked todocker-wikiteq-stack/.evn(if there is a reason to version.env)
In result, you'll be able to version your modifications via git keeping the stack files untouched and so be able to version the stack separately from your modifications.
By default the Matomo runs on 8182 port (to be shadowed with Nginx) and requires initial setup
on first run. Once installed, modify the .env file by adding MATOMO_USER and MATOMO_PASSWORD
variables matching user/password that was used during installation.
Make the matomo_import_logs.sh be run on Cron @daily close to midnight to keep the Matomo
fed with visits information, eg:
55 23 * * * cd ~/docker/ && ./import_logs_matomo.sh >> ~/import.log
# matomo
location /matomo/ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Uri /matomo;
proxy_read_timeout 300;
proxy_pass http://127.0.0.1:8182/;
proxy_set_header X-Forwarded-For $remote_addr;
}Plus once containers are started modify the Matomo config as below (the settings are intended to be generated automatically, but it's better to verify):
[General]
trusted_hosts[] = "127.0.0.1:8182"
assume_secure_protocol = 1
force_ssl=0
proxy_uri_header = 1