Moodle Development Environment

Develop moodle

The following setup can be used to setup a moodle development environment, with rootless podman:

# D-MATH link podman-compose
ln -s /usr/bin/podman-compose ~/bin/docker-compose

# D-MATH clone moodle-docker repo
git clone https://github.com/moodlehq/moodle-docker.git
cd moodle-docker

# D-MATH set variables
export MOODLE_DOCKER_DB_PORT=15432
export MOODLE_DOCKER_APP_VERSION=18080
export MOODLE_DOCKER_SELENIUM_VNC_PORT=15900
export MOODLE_DOCKER_WEB_PORT=18000

# Change ./moodle to your /path/to/moodle if you already have it checked out
export MOODLE_DOCKER_WWWROOT=./moodle

# D-MATH add custom configuration
cat <<EOF > local.yml
services:
  webserver:
    volumes:
      - "${MOODLE_DOCKER_WWWROOT}/../moodledata:/var/www/moodledata"
  db:
    environment:
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - "${MOODLE_DOCKER_WWWROOT}/../database:/var/lib/postgresql/data"
EOF

# Choose a db server (Currently supported: pgsql, mariadb, mysql, mssql, oracle)
export MOODLE_DOCKER_DB=pgsql

# D-MATH creating files with group access for moodle code
umask 007

# Get Moodle code, you could select another version branch (skip this if you already got the code)
git clone -b MOODLE_404_STABLE git://git.moodle.org/moodle.git $MOODLE_DOCKER_WWWROOT

# D-MATH add folder for moodle data
mkdir moodledata
mkdir database

# D-MATH setgid for automatic setting group permission
chmod 2770 moodle
chmod 2770 moodledata
chmod 2770 database

# Ensure customized config.php for the Docker containers is in place
cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php

# D-MATH set the permission to 33 inside the container for moodle code
podman unshare chown 33 -R moodle
podman unshare chown 33 -R moodledata
podman unshare chown 999 -R database

# Start up containers, choose docker.io to download the images
bin/moodle-docker-compose up -d

# Shut down and destroy containers
#bin/moodle-docker-compose down

Above we set the webserver port to 18000 so this means you now need connect to http://localhost:18000 in your browser to see the application.

Volume Permissions

If you have added new files from outside the container, you need to re-apply the correct permissions. Let’s say you have added files inside the moodle folder, then you need to run the following command:

# set the permission to 33 
podman unshare chown 33 -R moodle

Visual Studio Code

To prevent the above Volume Permission problem, you can connect your locally installed Visual Studio Code to the running container:

  • Open Visual Studio Code
  • Hit F1
  • Search for Attach to Running Container
  • Choose the webserver container
  • Now open the folder /var/www/html

If you need to run some commands in the container:

  • After being connected to the container
  • Hit Ctrl+`

Posted on
in General Information,Linux Tags: ,,

PROTECT YOUR BRAINWORK.

An IT Security Initiative
https://itsecurity.ethz.ch

Trending

Categories

Recent Posts