MediaWiki-Docker-Dev

MediaWiki-Docker-Dev (or MDD) is a development environment for MediaWiki, based on Docker. It was authored by Addshore, with contributions from others. It can be installed from GitHub, and you can find instructions for setup in the README.

ConfigurationEdit

Adjusting database replication delayEdit

This is very useful for reproducing production bugs caused by replication delay.

First, connect to the replica database: docker-compose exec db-slave mysql -uroot -ptoor default

Then execute this SQL to set the delay to 2 seconds.

STOP SLAVE;
CHANGE MASTER TO MASTER_DELAY = 2;
START SLAVE;
SHOW SLAVE STATUS\G

The output should show SQL_Delay: 2

Log to STDERREdit

With this configuration, you can view MediaWiki's logs by running docker-compose logs -f web, or docker-compose logs -f web | grep '\[error\]' to view only error messages.

if ( !defined( 'STDERR' ) ) {
	define( 'STDERR', fopen( 'php://stderr', 'w' ) );
}

if ( !isset( $maintClass ) || ( isset( $maintClass ) && $maintClass !== 'PHPUnitMaintClass' ) ) {
	$wgMWLoggerDefaultSpi = [
		'class' => \MediaWiki\Logger\ConsoleSpi::class,
	];
}

Improve file system sync on macOSEdit

Docker for Mac users may notice a performance improvement by adjusting docker-compose.override.yml so that the volumes section under web has :cached set:

- ${DOCKER_MW_PATH}:/var/www/mediawiki:cached

Profiling with Tideways XHProf extensionEdit

If you want to Manual:Profiling your code, you can do something like this:

  1. Execute ./bash so you are in the web container.
  2. Then clone the Tidways XHProf extension into your tmpdirectory: git clone https://github.com/tideways/php-xhprof-extension /tmp
  3. Build the extension: cd /tmp && phpize && ./configure && make && make install
  4. Enable the extension: echo 'extension=tideways_xhprof.so' >> /usr/local/etc/php/conf.d/99-docker.ini
  5. Restart php-fpm: service restart php-fpm

Then in LocalSettings.php you can have a configure like:

$wgProfiler['class'] = ProfilerXhprof::class;
$wgProfiler['flags'] = TIDEWAYS_XHPROF_FLAGS_NO_BUILTINS;
$wgProfiler['output'] = [ 'ProfilerOutputDump' ];
$wgProfiler['outputDir'] = sys_get_temp_dir();

Then, you can clone the XHProf viewer and copy its xhprof_lib and xhprof_html directories into the root of your MediaWiki repo (doesn't matter if you do this on the host or in the container, since the files will sync across). From there you can navigate to http://default.web.mw.localhost/mediawiki/xhprof_html/ to view profiled requests.

Additional servicesEdit

EventLoggingEdit

  1. Clone the eventlogging repository
  2. Run ./bin/eventlogging-devserver. (Optional) If you have jq installed, you can run ./bin/eventlogging-devserver | jq '.' for improved formatting of the JSON output.

In Docker for Mac, add this to your LocalSettings.php:

$wgEventLoggingBaseUri = 'http://host.docker.internal:8100/event.gif';

RedisEdit

Using Redis for caching can significantly improve performance. It also enables the ChronologyProtector.

In docker-compose.override.yml add:

  redis:
    image: redis

In MediaWiki's LocalSettings.php, add:

$wgObjectCaches['redis'] = [
	'class' => 'RedisBagOStuff',
	'servers'=> [ 'redis:6379' ],
];
$wgMainCacheType = 'redis';
$wgSessionCacheType = 'redis';
$wgMainStash = 'redis';

The JobQueue can also be made to use Redis. This may improve performance on a production system, but probably makes little difference for a local development setup.

$wgJobTypeConf['default'] = [
	'class' => 'JobQueueRedis',
	'redisServer' => 'redis:6379',
	'redisConfig' => [],
	'claimTTL' => 3600,
	'daemonized' => true
];

Parsoid / VisualEditorEdit

See https://github.com/addshore/mediawiki-docker-dev/pull/83 for how to running Parsoid as a service locally.

Alternatively, you can use the approach from boxwiki:

$wgVirtualRestConfig['modules']['parsoid'] = array(
    // URL to the Parsoid instance
    // Use port 8142 if you use the Debian package
    'url' => 'https://en.wikipedia.org',
    // Parsoid "domain", see below (optional)
    'domain' => 'en.wikipedia.org',
    // Parsoid "prefix", see below (optional)
    'prefix' => 'localhost'
);
$wgVisualEditorFullRestbaseURL = 'https://en.wikipedia.org/api/rest_';

ElasticSearchEdit

In docker-compose.override.yml add:

  elasticsearch:
    image: elasticsearch:6.8.2
    ports: 
      - 9200:9200
      - 9300:9300
    environment:
      - discovery.type=single-node

Then follow the installation and configuration instructions from Extension:CirrusSearch, taking care to specify the hostname as elasticsearch rather than localhost.