MediaWiki master
|
Welcome to the MediaWiki community! Please see How to become a MediaWiki hacker for general information on contributing to MediaWiki.
MediaWiki provides an extendable local development environment based on Docker Compose. This environment provides PHP, Apache, Xdebug and a SQLite database.
Do not use the development environment to serve a public website! Bad things would happen!
More documentation, examples, and configuration recipes are available at mediawiki.org/wiki/MediaWiki-Docker.
Support is available on the Libera IRC network in the #mediawiki channel, and on Phabricator by creating tasks with the MediaWiki-Docker tag.
You'll need to have Docker installed:
Linux users:
docker-ce
, docker-ce-cli
, containerd.io
, and docker-compose-plugin
by downloading the server releases for your distribution rather than Docker Desktop. You can also install the binaries.Windows users:
Running Docker from a Windows terminal and using the Windows file system will result in MediaWiki being very slow. For Windows 10 and higher, we recommend configuring Docker and Windows to use the Windows Subsystem for Linux (WSL). Turn on WSL in your Windows settings, then run the following commands: wsl --install -d ubuntu
and wsl --set-version ubuntu 2
. Then go into Docker -> Settings -> General -> tick "Use the WSL 2 based engine", then go into Docker -> Settings -> Resources -> WSL Integration -> tick "Ubuntu". git clone
the mediawiki repository into a WSL folder such as home/yourusername/mediawiki
so that the files are inside WSL. Then you can run most of the commands in this tutorial outside of WSL, by opening PowerShell, navigating to the WSL directory with cd \\wsl.localhost\Ubuntu\home\yourusername\mediawiki
, and executing shell commands as normal. To access WSL from PowerShell (rare but may be needed sometimes), you can use the command ubuntu
to turn a PowerShell console into a WSL console. To navigate to WSL folders in File Explorer, show the Navigation Pane, then towards the bottom, look for "Linux" (it will be close to "This PC").
Mac users:
If you're using Docker Desktop and have the Use Rosetta for x86/amd64 emulation on Apple Silicon
setting enabled, you may encounter an issue where loading the wiki results in a blank page or a 503 error. To resolve this, disable the setting and restart Docker Desktop. See this page for more information.
Download the latest MediaWiki files to your computer. One way to download the latest alpha version of MediaWiki is to install git, open a shell, navigate to the directory where you want to save the files, then type git clone https://gerrit.wikimedia.org/r/mediawiki/core.git mediawiki
.
Optional: If you plan to submit patches to this repository, you will probably want to create a Gerrit account, then type git remote set-url origin ssh://YOUR-GERRIT-USERNAME-HERE@gerrit.wikimedia.org:29418/mediawiki/core
, replacing YOUR-GERRIT-USERNAME-HERE with your Gerrit username. Please see the official MediaWiki Gerrit tutorial for more information.
.env
fileUsing a text editor, create a .env
file in the root of the MediaWiki core repository, and copy these contents into that file:
Windows users: Run the following command to add a blank user ID and group ID to your .env
file:
Non-Windows users: Run the following command to add your user ID and group ID to your .env
file:
Linux users: If you'd like to use Xdebug features inside your IDE, then create a docker-compose.override.yml
file as well:
Start the containers:
The "up" command makes sure that the PHP and webserver containers are running (and any others in the docker-compose.yml
file). It is safe to run at any time, and will do nothing if the containers are already running.
The first time, it may take a few minutes to download new Docker images.
The -d
argument stands for "detached" mode, which run the services in the background. If you suspect a problem with one of the services, you can run it without -d
to follow the server logs directly from your terminal. You don't have to stop the services first, if you ran it with -d
and then without, you'll get connected to the already running containers including a decent back scroll of server logs.
Note that MediaWiki debug logs go to /cache/*.log
files (not sent to docker).
Done! The wiki should now be available for you at http://localhost:8080.
You can use docker compose exec mediawiki bash
to open a Bash shell in the MediaWiki container. You can then run one or more commands as needed and stay within the container shell.
You can also run a single command in the container directly from your host shell, for example: docker compose exec mediawiki php maintenance/run.php update
.
Run a single PHPUnit file or directory:
See PHPUnit on mediawiki.org for more examples.
You can use Fresh to run Selenium in a dedicated container. Example usage:
You can use Fresh to run API tests in a dedicated container. Example usage:
You can override the default services from a docker-compose.override.yml
file, and make use of those overrides by changing LocalSettings.php
.
Example overrides and configurations can be found under MediaWiki-Docker on mediawiki.org.
After updating docker-compose.override.yml
, run docker compose down
followed by docker compose up -d
for changes to take effect.
If you need root on the container to install system packages with apt-get
for troubleshooting, you can open a shell as root with docker compose exec --user root mediawiki bash
.
To install an extension or skin, follow the instructions of the mediawiki.org page for the extension or skin in question, and look for any dependencies or additional steps that may be needed.
For most extensions, only two steps are needed: download the code to the right directory, and then enable the component from LocalSettings.php
.
To install the Vector skin:
LocalSettings.php
: To install the EventLogging extension:
Clone the extension repository:
Alternatively, if you have extension repositories elsewhere on disk, mount each one as an overlapping volume in docker-compose.override.yml
. This is comparable to a symlink, but those are not well-supported in Docker.
LocalSettings.php
: By default, you will need to set XDEBUG_TRIGGER=1
in the GET/POST, or as an environment variable, to turn on Xdebug for a request.
You can also install a browser extension for controlling whether Xdebug is active. See the official Xdebug Step Debugging, particularly the "Activating Step Debugging" section, for more details.
If you wish to run Xdebug on every request, you can set start_with_request=yes
in XDEBUG_CONFIG
in your .env file:
You can pass any of Xdebug's configuration values in this variable. For example:
This shouldn't be necessary for basic use cases, but see the Xdebug settings documentation for available settings.
You can use your local version of Codex instead of the one bundled with MediaWiki. This is useful when testing how changes in Codex affect Codex-based features in MediaWiki.
If your clone of the Codex repository is outside of the MediaWiki directory (this is common), add the following to your docker-compose.override.yml
. Replace ~/git/codex
with the path to your Codex clone.
docker-compose.override.yml
, you have to recreate the environment: Enable Codex development mode by adding the following to the bottom of LocalSettings.php
:
To disable Codex development mode and use the regular version of Codex, delete or comment out this line.
npm run build-all
in the Codex directory.Stop the environment, perhaps to reduce the load when working on something else. This preserves the containers, to be restarted later quickly with the docker compose up -d
command.
Destroy and re-create the environment. This will delete the containers, including any logs, caches, and other modifications you may have made via the shell.
To empty the wiki database and re-install it:
LocalSettings.php
file.cache/sqlite
directory.You can now restore or copy over any modifications you had in your previous LocalSettings.php
file. And if you have any additional extensions installed that required a database table, then also run: docker compose exec mediawiki php maintenance/run.php update
.
If you suspect a change is not applying due to caching, start by hard refreshing the browser.
If that doesn't work, you can narrow it down by disabling various server-side caching layers in LocalSettings.php
, as follows:
The default settings of MediaWiki are such that caching is smart and changes propagate immediately. Using the above settings may slow down your wiki significantly. Especially on macOS and Windows, where Docker Desktop uses a VM internally and thus has longer file access times.
See Manual:Caching on mediawiki.org for more information.
Older versions of Xdebug used port 9000, which could conflict with php-fpm running on the host. This document used to recommend a workaround of telling your IDE to listen on a different port (e.g., 9009) and setting XDEBUG_CONFIG=remote_port=9009
in your .env
.
Xdebug 3.x now uses the client_port
value, which defaults to 9003. This should no longer conflict with local php-fpm installations, but you may need to change the settings in your IDE or debugger.
The image uses host.docker.internal
as the client_host
value which should allow Xdebug work for Docker for Mac/Windows.
On Linux, you need to create a docker-compose.override.yml
file with the following contents:
With the latest version of Docker on Linux hosts, this should work transparently as long as you're using the recommended docker-compose.override.yml
. If it doesn't, first check docker version
to make sure you're running Docker 20.10.2 or above, and docker compose version
to make sure it's 1.27.4 or above.
If Xdebug still doesn't work, try specifying the hostname or IP address of your host. The IP address works more reliably. You can obtain it by running e.g. ip -4 addr show docker0
and copying the IP address into the config in .env
, like XDEBUG_CONFIG=remote_host=172.17.0.1
Switching on the remote log for Xdebug comes at a performance cost so only use it while troubleshooting. You can enable it like so: XDEBUG_CONFIG=remote_log=/tmp/xdebug.log
See if you're able to run any docker commands to start with. Try running docker container ls
, which should also throw a permission error. If not, go through the following steps to get access to the socket that the docker client uses to talk to the daemon.
sudo usermod -aG docker $USER
And then relogin
(or newgrp docker
) to re-login with the new group membership.
The environment's working directory has recently changed to /var/www/html/w
. Reconfigure this in your LocalSettings.php
by ensuring that the following values are set correctly:
The permissions with the cache/sqlite
directory have to be set manually on Windows:
Make sure you have the MW_DOCKER_UID
and MW_DOCKER_GID
set in your .env
file (instructions above).