Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions ct/moodle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func)

# Copyright (c) 2021-2025 community-scripts ORG
# Author: EEJoshua
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://moodle.org/

APP="Moodle"
var_tags="${var_tags:-lms;php}"
var_cpu="${var_cpu:-2}"
var_ram="${var_ram:-4096}"
var_disk="${var_disk:-8}"
var_os="${var_os:-debian}"
var_version="${var_version:-12}"
var_unprivileged="${var_unprivileged:-1}"

header_info "$APP"
variables
color
catch_errors

function update_script() {
header_info
check_container_storage
check_container_resources
if [[ ! -f /var/www/moodle/version.php ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi

msg_info "Preparing repository"
$STD git config --system --add safe.directory /var/www/moodle || true

BRANCH="$(runuser -u www-data -- git -C /var/www/moodle rev-parse --abbrev-ref HEAD 2>/dev/null || echo 'MOODLE_500_STABLE')"
msg_info "Updating $APP (${BRANCH})"
$STD runuser -u www-data -- git -C /var/www/moodle fetch --all --prune
$STD runuser -u www-data -- git -C /var/www/moodle checkout -B "${BRANCH}" "origin/${BRANCH}"
$STD runuser -u www-data -- git -C /var/www/moodle reset --hard "origin/${BRANCH}"
Comment on lines +30 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use git

$STD runuser -u www-data -- /usr/bin/php /var/www/moodle/admin/cli/maintenance.php --enable
$STD runuser -u www-data -- /usr/bin/php /var/www/moodle/admin/cli/upgrade.php --non-interactive
$STD runuser -u www-data -- /usr/bin/php /var/www/moodle/admin/cli/purge_caches.php
$STD runuser -u www-data -- /usr/bin/php /var/www/moodle/admin/cli/maintenance.php --disable
msg_ok "Update Successful"
exit
}

start
build_container

description

msg_ok "Completed Successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:80${CL}"
echo -e "${INFO}${YW} Database and Admin credentials are saved in ~/moodle.creds${CL} inside the LXC"
39 changes: 39 additions & 0 deletions frontend/public/json/moodle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "Moodle",
"slug": "moodle",
"categories": [
11
],
"date_created": "2025-08-18",
"type": "ct",
"updateable": true,
"privileged": false,
"interface_port": 80,
"documentation": "https://docs.moodle.org/500/en/Main_page",
"website": "https://moodle.org/",
"logo": "https://moodle.org/theme/image.php/moodleorg/core/1720531200/moodle-logo",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"logo": "https://moodle.org/theme/image.php/moodleorg/core/1720531200/moodle-logo",
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/moodle.webp",

"description": "Moodle is the world’s most popular open-source learning management system (LMS). The community edition of Moodle allows educators to create flexible, customizable online learning platforms with extensive plugin support, user management, and activity tracking.",
"install_methods": [
{
"type": "default",
"script": "ct/moodle.sh",
"resources": {
"cpu": 2,
"ram": 4096,
"hdd": 8,
"os": "debian",
"version": "12"
}
}
],
"default_credentials": {
"username": null,
"password": null
},
"notes": [
{ "type": "info", "text": "Database and Admin credentials are saved in ~/moodle.creds" },
{ "type": "warning", "text": "Moodle requires PHP settings: max_input_vars >= 5000 and memory_limit >= 256M. These are applied automatically." },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{ "type": "warning", "text": "Moodle requires PHP settings: max_input_vars >= 5000 and memory_limit >= 256M. These are applied automatically." },

Not needed

{ "type": "info", "text": "Default data directory: /var/moodledata (writeable by www-data)." },
{ "type": "info", "text": "Supports MariaDB as the database backend (configured by the script)." }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{ "type": "info", "text": "Supports MariaDB as the database backend (configured by the script)." }

Not needed

]
}
156 changes: 156 additions & 0 deletions install/moodle-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#!/usr/bin/env bash

# Copyright (c) 2021-2025 community-scripts ORG
# Author: EEJoshua
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://docs.moodle.org/500/en/Git_for_Administrators

source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
color
verb_ip6
catch_errors
setting_up_container
network_check
update_os

msg_info "Install PHP (Apache) + required modules"
$STD apt-get install -y git
PHP_VERSION="8.2"
PHP_APACHE="YES"
PHP_FPM="NO"
PHP_MODULE="bcmath,curl,gd,intl,mbstring,opcache,readline,xml,zip,mysql,soap,ldap"
PHP_MEMORY_LIMIT="256M"
export PHP_VERSION PHP_APACHE PHP_FPM PHP_MODULE PHP_MEMORY_LIMIT
setup_php
msg_ok "PHP ready"
Comment on lines +16 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg_info "Install PHP (Apache) + required modules"
$STD apt-get install -y git
PHP_VERSION="8.2"
PHP_APACHE="YES"
PHP_FPM="NO"
PHP_MODULE="bcmath,curl,gd,intl,mbstring,opcache,readline,xml,zip,mysql,soap,ldap"
PHP_MEMORY_LIMIT="256M"
export PHP_VERSION PHP_APACHE PHP_FPM PHP_MODULE PHP_MEMORY_LIMIT
setup_php
msg_ok "PHP ready"
PHP_VERSION="8.2" PHP_APACHE="YES" PHP_MODULE="mysql,soap,ldap" PHP_MEMORY_LIMIT="256M" setup_php


msg_info "Install MariaDB"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg_info "Install MariaDB"

MARIADB_VERSION="latest"
export MARIADB_VERSION
Comment on lines +28 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MARIADB_VERSION="latest"
export MARIADB_VERSION

setup_mariadb
msg_ok "MariaDB ready"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg_ok "MariaDB ready"


msg_info "Create Moodle database"
DB_NAME="moodle"
DB_USER="moodleuser"
DB_PASS="$(openssl rand -base64 24 | tr -dc 'A-Za-z0-9' | head -c24)"
$STD mariadb -u root -e "CREATE DATABASE \`${DB_NAME}\` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
$STD mariadb -u root -e "CREATE USER '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASS}';"
$STD mariadb -u root -e "GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON \`${DB_NAME}\`.* TO '${DB_USER}'@'localhost'; FLUSH PRIVILEGES;"
{
echo "Moodle DB Credentials"
echo "DB Name: ${DB_NAME}"
echo "DB User: ${DB_USER}"
echo "DB Pass: ${DB_PASS}"
} >>~/"moodle.creds"
msg_ok "Database ready"

msg_ok "Selecting Moodle branch"
REMOTE_BRANCHES="$(git ls-remote --heads https://github.com/moodle/moodle.git 'MOODLE_*_STABLE' | awk -F'refs/heads/' '{print $2}' | sort -V)"
echo "Available stable branches:"
echo "${REMOTE_BRANCHES}"
echo -n "Enter branch to install [default MOODLE_500_STABLE]: "
read -r MOODLE_BRANCH
MOODLE_BRANCH="${MOODLE_BRANCH:-MOODLE_500_STABLE}"
if ! echo "${REMOTE_BRANCHES}" | grep -qx "${MOODLE_BRANCH}"; then
msg_error "Branch ${MOODLE_BRANCH} not found among remotes"
exit 1
fi
msg_ok "Selected ${MOODLE_BRANCH}"

msg_info "Cloning Moodle (shallow)"
install -d -m 0755 /var/www
$STD rm -rf /var/www/moodle
$STD git clone --depth 1 --branch "${MOODLE_BRANCH}" https://github.com/moodle/moodle.git /var/www/moodle
msg_ok "Cloned Moodle ${MOODLE_BRANCH}"
Comment on lines +48 to +65
Copy link
Member

@tremor021 tremor021 Aug 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg_ok "Selecting Moodle branch"
REMOTE_BRANCHES="$(git ls-remote --heads https://github.com/moodle/moodle.git 'MOODLE_*_STABLE' | awk -F'refs/heads/' '{print $2}' | sort -V)"
echo "Available stable branches:"
echo "${REMOTE_BRANCHES}"
echo -n "Enter branch to install [default MOODLE_500_STABLE]: "
read -r MOODLE_BRANCH
MOODLE_BRANCH="${MOODLE_BRANCH:-MOODLE_500_STABLE}"
if ! echo "${REMOTE_BRANCHES}" | grep -qx "${MOODLE_BRANCH}"; then
msg_error "Branch ${MOODLE_BRANCH} not found among remotes"
exit 1
fi
msg_ok "Selected ${MOODLE_BRANCH}"
msg_info "Cloning Moodle (shallow)"
install -d -m 0755 /var/www
$STD rm -rf /var/www/moodle
$STD git clone --depth 1 --branch "${MOODLE_BRANCH}" https://github.com/moodle/moodle.git /var/www/moodle
msg_ok "Cloned Moodle ${MOODLE_BRANCH}"

Dont use git clone, use fetch_and_deploy_gh_release function


msg_info "Setting permissions and data directory"
install -d -m 0770 -o www-data -g www-data /var/moodledata
Comment on lines +48 to +68
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so much effort? Just use function "fetch_and_deploy_gh_release "moodle"....

$STD chown -R www-data:www-data /var/www/moodle
$STD find /var/www/moodle -type d -exec chmod 02775 {} \;
$STD find /var/www/moodle -type f -exec chmod 0644 {} \;
msg_ok "Permissions set"

msg_info "Configuring Apache"
cat >/etc/apache2/sites-available/moodle.conf <<'EOF'
<VirtualHost *:80>
ServerName _
DocumentRoot /var/www/moodle
<Directory /var/www/moodle>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/moodle_error.log
CustomLog ${APACHE_LOG_DIR}/moodle_access.log combined
</VirtualHost>
EOF
$STD a2enmod rewrite
$STD a2dissite 000-default.conf
$STD a2ensite moodle.conf
$STD systemctl reload apache2
msg_ok "Apache configured"

msg_info "Apply PHP tunables"
PHPVER="$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')" 2>/dev/null || true
[[ -z "$PHPVER" ]] && PHPVER="$(ls -1d /etc/php/* 2>/dev/null | awk -F'/' '{print $4}' | head -n1)"
for sapi in apache2 cli; do
install -d -m 0755 "/etc/php/${PHPVER}/${sapi}/conf.d"
{
echo "max_input_vars=5000"
echo "memory_limit=256M"
} >"/etc/php/${PHPVER}/${sapi}/conf.d/99-moodle.ini"
done
$STD systemctl reload apache2
msg_ok "PHP tuned"

msg_info "Run Moodle CLI installer"
IPV4="$(hostname -I | awk '{print $1}')"
WWWROOT="http://${IPV4}"
DEFAULT_ADMIN_EMAIL="admin@example.com"
ADMIN_EMAIL="${MOODLE_ADMIN_EMAIL:-$DEFAULT_ADMIN_EMAIL}"
ADMIN_USER="admin"
ADMIN_PASS="$(openssl rand -base64 24 | tr -dc 'A-Za-z0-9' | head -c20)"

msg_info "Running non-interactive Moodle CLI installer (MariaDB driver)"
$STD runuser -u www-data -- /usr/bin/php /var/www/moodle/admin/cli/install.php \
--chmod=2775 \
--lang=en \
--wwwroot="${WWWROOT}" \
--dataroot="/var/moodledata" \
--dbtype="mariadb" \
--dbhost="localhost" \
--dbname="${DB_NAME}" \
--dbuser="${DB_USER}" \
--dbpass="${DB_PASS}" \
--dbport="" \
--fullname="Moodle Site" \
--shortname="Moodle" \
--summary="Self-hosted Moodle (${MOODLE_BRANCH})" \
--adminuser="${ADMIN_USER}" \
--adminpass="${ADMIN_PASS}" \
--adminemail="${ADMIN_EMAIL}" \
--agree-license \
--non-interactive
{
echo ""
echo "Moodle Admin Credentials"
echo "User: ${ADMIN_USER}"
echo "Pass: ${ADMIN_PASS}"
echo "Email: ${ADMIN_EMAIL}"
echo "URL : ${WWWROOT}"
echo "Branch: ${MOODLE_BRANCH}"
} >>~/"moodle.creds"
msg_ok "CLI installer completed"

msg_info "Enabling cron"
echo '* * * * * www-data /usr/bin/php -f /var/www/moodle/admin/cli/cron.php >/dev/null 2>&1' >/etc/cron.d/moodle
$STD chmod 0644 /etc/cron.d/moodle
msg_ok "Cron enabled"

motd_ssh
customize

msg_info "Cleaning up"
$STD apt-get -y autoremove
$STD apt-get -y autoclean
msg_ok "Cleaned"
Loading