2019-11-13 15:34:03 +00:00
# MediaWiki Developers
Welcome to the MediaWiki community! Please see [How to become a MediaWiki
hacker](https://www.mediawiki.org/wiki/How_to_become_a_MediaWiki_hacker) for
general information on contributing to MediaWiki.
## Docker Developer Environment
MediaWiki provides an extendable local development environment based on
Docker Compose.
The default environment provides PHP, Apache, XDebug and a SQLite database.
(**Do not run this stack in production! Bad things might happen!**)
2020-02-29 21:59:38 +00:00
More documentation as well as example overrides and configuration recipes
are available at [mediawiki.org/wiki/MediaWiki-Docker][mw-docker].
2019-11-13 15:34:03 +00:00
Support is available on the [Freenode IRC network][freenode] at `#mediawiki`
and on Wikimedia Phabricator at [#MediaWiki-Docker][mw-docker-phab].
2020-02-29 21:59:38 +00:00
[mw-docker]: https://www.mediawiki.org/wiki/MediaWiki-Docker
2020-02-24 17:11:59 +00:00
[mw-docker-phab]: https://phabricator.wikimedia.org/project/profile/3094/
2019-11-13 15:34:03 +00:00
[freenode]: https://freenode.net/
### Requirements
You'll need a locally running Docker and Docker Compose:
- [Docker installation instructions][docker-install]
- [Docker Compose installation instructions][docker-compose]
[docker-install]: https://docs.docker.com/install/
[docker-compose]: https://docs.docker.com/compose/install/
2020-03-16 13:03:26 +00:00
---
**Linux users**
2020-03-29 15:40:29 +00:00
* We recommend installing `docker-compose` by [downloading the binary release ](https://docs.docker.com/compose/install/#install-compose-on-linux-systems ). You can also use `pip` , your OS package manager, or even run it in a container, but downloading the binary release is the easiest method.
* Follow the instructions to ["Manage Docker as a non-root user" ](https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user )
2020-03-16 13:03:26 +00:00
---
2019-11-13 15:34:03 +00:00
### Quickstart
2020-03-04 21:15:31 +00:00
Create a `.env` file for defining environment variables for the development environment:
```bash
echo "MW_DOCKER_PORT=8080
MW_DOCKER_UID=$(id -u)
MW_DOCKER_GID=$(id -g)
MW_SCRIPT_PATH=/
MW_SERVER=http://localhost:8080
MEDIAWIKI_USER=Admin
MEDIAWIKI_PASSWORD=dockerpass
XDEBUG_CONFIG=''" > .env
```
2019-11-13 15:34:03 +00:00
2020-03-04 21:15:31 +00:00
#### Linux users
2019-11-13 15:34:03 +00:00
2020-03-04 21:15:31 +00:00
If you are on a Linux system, first create a
2019-11-13 15:34:03 +00:00
`docker-compose.override.yml` containing the following:
2020-03-04 21:15:31 +00:00
2019-11-13 15:34:03 +00:00
```yaml
version: '3.7'
services:
mediawiki:
# On Linux, these lines ensure file ownership is set to your host user/group
2020-02-25 12:01:40 +00:00
user: "${MW_DOCKER_UID}:${MW_DOCKER_GID}"
2019-11-13 15:34:03 +00:00
```
#### Start environment and install MediaWiki
Start the environment:
```sh
# -d is detached mode - runs containers in the background:
docker-compose up -d
```
Install Composer dependencies:
```sh
docker-compose exec mediawiki composer update
```
Install MediaWiki in the environment:
```sh
2020-03-28 13:55:21 +00:00
docker-compose exec mediawiki /bin/bash /docker/install.sh
2019-11-13 15:34:03 +00:00
```
##### Re-install
Remove or rename `LocalSettings.php` , delete the `cache/sqlite` directory, then
re-run the installation command above. Copy over any changes from your previous
`LocalSettings.php` and then run `maintenance/update.php` .
### Usage
#### Running commands
You can use `docker-compose exec mediawiki bash` to open a bash shell in the
MediaWiki container, or you can run commands in the container from your host,
for example: `docker-compose exec mediawiki php maintenance/update.php`
#### Running tests
##### PHPUnit
Run all tests:
```sh
docker-compose exec mediawiki php tests/phpunit/phpunit.php
```
Run a single test:
```sh
docker-compose exec mediawiki php tests/phpunit/phpunit.php /path/to/test
```
See [PHPUnit Testing][phpunit-testing] on MediaWiki.org for more help.
[phpunit-testing]: https://www.mediawiki.org/wiki/Manual:PHP_unit_testing/Running_the_unit_tests
##### Selenium
You can use [Fresh][fresh] to run [Selenium in a dedicated
container][selenium-dedicated]. Example usage:
```sh
export MW_SERVER=http://localhost:8080
export MW_SCRIPT_PATH=/
export MEDIAWIKI_USER=Admin
export MEDIAWIKI_PASSWORD=dockerpass
fresh-node -env -net
npm ci
npm run selenium
```
[selenium-dedicated]: https://www.mediawiki.org/wiki/Selenium/Node.js/Target_Local_MediaWiki_(Container)
#### API Testing
You can use [Fresh][fresh] to run [API tests in a dedicated
container][api-dedicated]. Example usage:
```sh
export MW_SERVER=http://localhost:8080/
export MW_SCRIPT_PATH=/
export MEDIAWIKI_USER=Admin
export MEDIAWIKI_PASSWORD=dockerpass
fresh-node -env -net
# Create .api-testing.config.json as documented on
# https://www.mediawiki.org/wiki/MediaWiki_API_integration_tests
npm ci
npm run api-testing
```
2020-03-04 23:46:06 +00:00
[fresh]: https://github.com/wikimedia/fresh
2019-11-13 15:34:03 +00:00
[api-dedicated]: https://www.mediawiki.org/wiki/MediaWiki_API_integration_tests
### Modifying the development environment
You can override the default services with a `docker-compose.override.yml`
file, and configure those overrides with changes to `LocalSettings.php` .
2020-02-29 21:59:38 +00:00
Example overrides and configurations can be found at [MediaWiki-Docker ](https://www.mediawiki.org/wiki/MediaWiki-Docker )
2019-11-13 15:34:03 +00:00
After updating `docker-compose.override.yml` , run `docker-compose down`
followed by `docker-compose up -d` for changes to take effect.
#### Installing extra packages
If you need root on the container to install packages for troubleshooting,
you can open a shell as root with `docker-compose exec --user root mediawiki
bash`.
2020-02-27 16:58:17 +00:00
#### Use Vector skin
Clone the skin to `skins/Vector` :
```sh
git clone "https://gerrit.wikimedia.org/r/mediawiki/skins/Vector" skins/Vector
```
Configure MediaWiki to use the skin:
```sh
echo "wfLoadSkin( 'Vector' );" >> LocalSettings.php
```
2020-03-04 21:21:04 +00:00
#### XDebug
You can override the XDebug configuration included with the default image by
2020-03-04 21:15:31 +00:00
passing `XDEBUG_CONFIG={your config}` in the `.env` file at the root of the MediaWiki repository:
2020-03-04 21:21:04 +00:00
2020-03-04 21:15:31 +00:00
```
XDEBUG_CONFIG=remote_enable=1 remote_host=172.17.0.1 remote_log=/tmp/xdebug.log remote_port=9009
2020-03-04 21:21:04 +00:00
```
2019-11-13 15:34:03 +00:00
##### Troubleshooting
###### Port conflicts
If you installed php-fpm on your host, that is listening on port 9000 and
will conflict with XDebug. The workaround is to tell your IDE to listen on a
different port (e.g. 9009) and to set the configuration in your
2020-03-04 21:15:31 +00:00
`.env` file: `XDEBUG_CONFIG=remote_port=9009`
2019-11-13 15:34:03 +00:00
###### Linux desktop, host not found
The image uses `host.docker.internal` as the `remote_host` value which
should work for Docker for Mac/Windows. On Linux hosts, you need to specify
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
2020-03-04 21:15:31 +00:00
IP address into the config, like `XDEBUG_CONFIG=remote_host=172.17.0.1`
2019-11-13 15:34:03 +00:00
###### Generating logs
Switching on the remote log for XDebug comes at a performance cost so only
2020-03-04 21:15:31 +00:00
use it while troubleshooting. You can enable it like so: `XDEBUG_CONFIG=remote_log=/tmp/xdebug.log`