Environment setup
NOTE: You have options here.
- If you are using moodle-docker then you may find the Moodle-docker environment setup approach easier.
- If you are not, then try Andrew's environment setup
Option #1: Moodle-docker environment setup
This setup is a modified version of https://github.com/mattporritt/moodle-docker
You can follow along in more detail using the link.
You will require:
- PHP 8 or greater
- Docker
- OpenSSL
Docker
We start by cloning our fork of the Moodle Docker repository:
git clone git@github.com:mattporritt/moodle-docker.gitgit checkout omnibus
|
Copy the sample config file to your Moodle root:
cp moodle-docker/config.docker-template.php moodle_local/config.php
|
Copy the sample environment file:
cp moodle-docker/.env.example moodle-docker/.env
|
Update the MOODLE_DOCKER_WWWROOT variable in the .env file to the location of your Moodle root folder.
Host file
Update your local hosts file (etc/hosts)to include the following:
127.0.0.1 localhost synapse webserver keycloak element
|
SSL Setup
Make the self-signed certs so we can run Moodle and associated services over ssl/tls.
Change to the directory of the script first:
cd moodle-docker/moodle_dev/assets/certs
|
Run the script and fill out the certificate details. Pay attention to the prompts. Fill in all data:
./createcerts.sh webserver
|
The first time the script is run it will generate a root cert and key. After that it will re-use the root cert and just make the certs required for each service we want to run using SSL/TLS.
Run it for each additional service we need
./createcerts.sh keycloak
|
./createcerts.sh synapse
|
./createcerts.sh element
|
Next we add the root CA, this is to remove the browser self signed errors. To add the root CA to the Mac OS keychain. Run this on this host machine:
sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" ca.pem
|
Build and install
Next we need to build our version of the moodle dev container:
cd moodle-docker/moodle_dev
|
docker build -t "stevando:moodle_dev" .
|
Finally, actually start the services:
cd moodle-docker/bin
|
./moodle-docker-compose up -d
|
Synapse admin user
We also need to create an initial Synapse admin user. This is the user you'll need before you can use the Matrix API. To create an initial admin user:
docker exec -it CONTAINER_ID register_new_matrix_user \
|
-u admin \
|
-a \
|
-c /data/homeserver.yaml \
|
https://synapse:8008/
|
Where CONTAINER_ID is the Docker ID of the running Synapse container.
You will need to get the access token for this user. This can be done by accessing the following file with a database editor:
cd moodle-docker/synapse_data/homeserver.db
|
Look for the table access_tokens and the field token. You will need this token later on.
Site URLs
Once the following steps are complete the sites can be accessed at the following URLs:
Option #2: Andrew's environment setup
- Clone Andrew's helper repository:
git clone https://github.com/andrewnicols/moodle-synapse
|
cd moodle-synapse
|
- Run the docker-compose up command:
- Wait for about 10 seconds for the first run to complete
- Run the setup script:
- Copy the command it outputs
- Change into your Moodle directory
- Paste in the command, for EXAMPLE:
cd path/to/moodle
|
sed -i '/^require_once.*lib.*setup.php.*$/i require_once("/Users/nicols/git/moodlehq/synapse/moodle-config.php");' config.php
|
cd -
|
- If you have not done so already, edit your /etc/hosts file to add:
127.0.0.1 element.container.docker.internal element
|
127.0.0.1 synapse.container.docker.internal synapse
|
127.0.0.1 keycloak.container.docker.internal keycloak
|
- Follow the instructions at https://github.com/andrewnicols/moodle-synapse#trusting to trust the root CA that is used for this.
Moodle setup
Now that you have your environment setup, you will have access to several important resources (element, synapse, keycloak, etc). Let's configure Moodle.
- Login to Moodle as admin
- Navigate to Site admin > Development > Experimental settings and enable 'Enable communication subsystem'
- Navigate to Site admin > Plugins > Communication > Manage communication providers and ensure 'Matrix' is enabled.
- Navigate to Site admin > Plugins > Communication > Matrix
- Add the home server url (e.g. https://synapse:8008).
- Add the access token (available from the environment setup)
- Add the refresh token if available, otherwise use the access token
- Add the element server url (e.g. https://element:8081)
- Save your changes
- Navigate to Site admin > HTTP Security
- Add 8008 and 8443 to the allowed ports
Test scenario
- Navigate to the create a new course form
- Add all the required information to the form
- Add a course image
- Scroll down to the Communication section
- Set the Communication service to 'Matrix'
- Set Room name to 'Test room'
- Save changes.
- Run the queued adhoc tasks by running cron from the command line php admin/cli/cron.php
- Go to your newly created Matrix room using the link/icon in the bottom right corner.
- Log in using the user created during setup (if using Andrew's tooling that is the following):
- username: `moodlebot`
- password: `password`
- CONFIRM the avatar image for the room was set that same as the course image
- Navigate back to your course edit page.
- Change the course image to a different picture.
- Save changes.
- Run cron from the command line (see code snippet above).
- Go back to your Matrix room.
- CONFIRM that you see a new entry 'Admin changed the room avatar to ...'
- Go back to your course edit page.
- Click 'Save and display' (no changes made).
- Run cron from the command line (see code snippet above).
- Go back to your Matrix room.
- CONFIRM that there is no new entry about the room avatar being updated.
- Go back to your course edit page.
- Remove the course image.
- Save changes.
- Run cron from the command line (see code snippet above).
- Go back to your Matrix room.
- CONFIRM that you see a new entry 'Admin User removed the room avatar'