Actions

System Administrator's Guide/Installing Mahara/MySQL and Docker

From Mahara Wiki

< System Administrator's Guide‎ | Installing Mahara

Note: This is intended to assist developers. If you are using this in a production environment it is expected that you will be rolling your own docker config for much higher security than this offers.

tl;dr;

Docker can make things easy. It can also be fiddly. This worked for me.

  • Create the docker-compose.yml file
  • Update your config.php file
  • Spin up the container: docker-compose run --service-ports -d db
  • Point a browser at your site.

The longer version

Composer

Add this to a docker-compose.yml file. This file can live anywhere and doesn't need to be in your checked out repo.

version: '3'
services:
   db:
       image: mysql
       command: --default-authentication-plugin=mysql_native_password
       restart: always
       environment:
           MYSQL_ROOT_PASSWORD: "password"
           MYSQL_USER: "maharauser"
           MYSQL_PASSWORD: "maharapassword"
           MYSQL_DATABASE: "mahara"
       ports:
           - 3323:3306
       volumes:
           - my-datavolume:/var/lib/mysql
volumes:
   my-datavolume:

Spin up the container

docker-compose run --service-ports -d db

What is this doing?

We are creating a service (db) and a volume (for persistent storage).

The image is the official image.

The environment tells the container to set the root users password to "password" and to create another user that we will connect to the DB as. It also creates the "mahara" database.

The ports map port 3323 on the host to port 3306 in the container. Set 3323 to anything you like if this is in conflict. This is preconfigured to a non-standard port just for ease of copy/paste. By default MySQL will be running on port 3306 and if you already have a different version running this will let you spin up your target version without conflicting with the existing one. Update the image with the version you want. The current value will fetch the latest version.

The volumes tells docker to use persistent storage so your data will still be there after a restart of the container. The lack of settings on my-datavolume tells docker to pick how to manage this.

Mahara

config.php

Add the following to your config.php file:

$cfg->dbtype = 'mysql';
$cfg->dbhost = '127.0.0.1';
$cfg->dbport = 3323;
$cfg->dbuser = 'maharauser';
$cfg->dbpass = 'maharapassword';
$cfg->dbname = 'mahara';

It is important to use 127.0.0.1 as the host. If mysql receives localhost here it will try and connect via the local unix socket on the filesystem despite having a port set.

Gotchas

I have had issues with the maharauser not being able to create triggers and these are needed on site install. To get around this connect to the database as root and run the following:

GRANT ALL PRIVILEGES ON *.* TO 'maharauser'@'%';

THIS IS DANGEROUS... Do not do this anywhere except in a development environment. I could not figure out why, but running this on mahara.* was not enough.