MediaWiki-Docker/Configuration recipes/Alternative databases
Jump to navigation
Jump to search
Alternative databases[edit]
The default configuration uses SQLite for the database backend, but you can use MySQL (with replication or without) or Postgres instead.
MySQL (database replication)[edit]
These instruction assume a new installation (no LocalSettings.php).
docker-compose.override.yml
version: '3.7'
services:
mariadb-main:
image: 'bitnami/mariadb:latest'
volumes:
- mariadbdata:/bitnami/mariadb
environment:
- MARIADB_REPLICATION_MODE=master
- MARIADB_REPLICATION_USER=repl_user
- MARIADB_REPLICATION_PASSWORD=repl_password
- MARIADB_ROOT_PASSWORD=main_root_password
- MARIADB_USER=my_user
- MARIADB_PASSWORD=my_password
- MARIADB_DATABASE=my_database
mariadb-replica:
image: 'bitnami/mariadb:latest'
depends_on:
- mariadb-main
environment:
- MARIADB_REPLICATION_MODE=slave
- MARIADB_REPLICATION_USER=repl_user
- MARIADB_REPLICATION_PASSWORD=repl_password
- MARIADB_MASTER_HOST=mariadb-main
- MARIADB_MASTER_PORT_NUMBER=3306
- MARIADB_MASTER_ROOT_PASSWORD=main_root_password
volumes:
mariadbdata:
driver: local
TODO: Add install command. (You can use the web installer and specify mariadb-main as the server name, "root" as the user and "main_root_password" as the password.
After installing, add these snippets so that MediaWiki knows to read from the replica but write to the main database.
LocalSettings.php
$wgDBname = 'my_database';
$dockerMainDb = [
'host' => "mariadb-main",
'dbname' => 'my_database',
'user' => 'root',
'password' => 'main_root_password',
'type' => "mysql",
'flags' => DBO_DEFAULT,
'load' => 0,
];
$dockerReplicaDb = [
'host' => "mariadb-replica",
'dbname' => 'my_database',
'user' => 'root',
'password' => 'main_root_password',
'type' => "mysql",
'flags' => DBO_DEFAULT,
'max lag' => 60,
'load' => 1,
];
// Integration tests fail when run with replication, due to not having the temporary tables.
if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
$wgDBservers = [ $dockerMainDb, $dockerReplicaDb ];
} else {
$wgDBserver = $dockerMainDb['host'];
$wgDBuser = $dockerMainDb['user'];
$wgDBpassword = $dockerMainDb['password'];
$wgDBtype = $dockerMainDb['type'];
}
MySQL (single database server)[edit]
![]() | This configuration is not ideal; better support for this will be built in to the existing dev-image and its tooling. |
These instruction assume a new installation (no LocalSettings.php).
docker-compose.override.yml
version: '3.7'
services:
database:
image: mariadb
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- /dbdata:/var/lib/mysql
volumes:
dbdata:
driver: local
To install the MediaWiki database tables, use:
docker-compose exec mediawiki php maintenance/install.php --server=http://localhost:8080 --scriptpath="/w" --dbuser=root --dbserver=database --lang en --pass dockerpass mediawiki admin
Postgres (single database server)[edit]
These instruction assume a new installation (no LocalSettings.php).
docker-compose.override.yml
version: '3.7'
services:
database:
image: postgres
environment:
POSTGRES_PASSWORD: example
volumes:
- /dbdata:/var/lib/postgresql/data
volumes:
dbdata:
driver: local
To install the MediaWiki database tables, use:
docker-compose exec mediawiki php maintenance/install.php --dbuser postgres --dbpass example --dbserver database --dbtype postgres
--lang en --pass dockerpass mediawiki admin