Mooship

Automated Moodle deployment on Ubuntu. Chosen GitHub repository: shellharbor/mooship.
deploy-moodle.sh deploys Moodle on an Ubuntu server with a single command. It creates an isolated Docker project (PHP-FPM, nginx, PostgreSQL or MySQL, Redis, cron, certbot), installs Moodle through the CLI, connects the site to the shared nginxproxy reverse proxy, and obtains a Let's Encrypt certificate. Companion scripts schedule full backups and check the health of every site.
Moodle 4.3+ is required. PHP 8.1 and older are prohibited; minimum patches are 8.2.35, 8.3.36, 8.4.27 and 8.5.12, subject to Moodle compatibility. See the enforced runtime security policy. The PHP branch is selected automatically based on the Moodle version. Passwords, database names, and available ports are generated unless supplied explicitly.
For a portable application image, see the standalone Moodle Docker guide and Docker Hub. The updated source builds Moodle 4.5.15/PHP 8.3.36 and matching nginx, with separate PostgreSQL/MySQL and persistent data. Use the matching 1.2.1-moodle4.5.15-php8.3 and 1.2.1-moodle4.5.15-nginx tags. Version 1.2.0 predates the security floor. Compose examples, Kubernetes manifests and installation tests are included. The host installer below is an independent deployment option. Bundled Moodle retains its GPL license.
The Python CLI provides a dependency-free mooship command for verified toolkit installation and the existing deployment, lifecycle, backup/restore and diagnostics scripts. Install the security release with pipx install mooship==1.2.1. Upgrade both the Python CLI and native toolkit; 1.2.0 predates the runtime policy. See release publication for Docker Hub and PyPI setup and verification.
Deployment validates ports and service readiness before publishing a site. For native databases, --db-host HOST selects the container-reachable address (default host.docker.internal with Linux host-gateway mapping). See preflight, native database access, and readiness for requirements and checks.
The mooship/ folder is self-contained. It includes the deployment script, project and proxy templates, management utilities, examples, and an AI assistant skill. Copy the entire folder to a server or place it in a separate Git repository; it does not require files from outside the folder.
Contents
Directory layout
mooship/
├── deploy-moodle.sh # deploy Moodle (help: --help)
├── activate.sh # activate a deactivated project
├── deactivate.sh # stop a project without deleting it
├── remove.sh # remove a project completely
├── list-projects.sh # list projects on the server
├── backup.sh # full backup of the site, database, and SSL
├── schedule-backup.sh # daily backups with retention (systemd timer)
├── restore.sh # restore into an unused directory
├── doctor.sh # read-only health check of all sites
├── lib/ # path validation and archive format
├── tests/ # regression checks
├── moodle/ # project template → /var/www/<slug>
│ ├── docker-compose.yml
│ ├── .config/nginx/_site.conf
│ ├── .config/php/php74.ini … php84.ini, mooship.ini, fpm-pool.conf
│ └── .docker/php/php74 … php84.Dockerfile, .docker/nginx/nginx-1.29.1.Dockerfile
├── nginxproxy/ # shared proxy template → /var/www/nginxproxy
│ └── nginx.conf nginx.Dockerfile site-template.conf
├── examples/ # ready-to-use scenarios and sample files
├── README.md # this file
├── LICENSE # MIT
├── .github/workflows/ # CI checks and the weekly end-to-end deployment
├── .gitignore
├── SKILL.md # portable project guide for AI assistants
└── .claude/skills/deploy-moodle/SKILL.md # optional local Claude Code adapter
- The utilities are independent of the project type.
activate.sh, deactivate.sh, remove.sh, and list-projects.sh work with any project in /var/www deployed by these scripts, including projects other than Moodle.
- There is one
/var/www/nginxproxy for the entire server. All projects share it, including other project types (such as Laravel or static sites) deployed by similar script sets. The proxy is created from the nginxproxy/ template belonging to whichever deployment script runs first. The proxy templates are identical across these sets. An existing proxy is not overwritten.
Architecture
/var/www/
├── nginxproxy/ # shared reverse proxy (80/443), created on the first run
│ ├── docker-compose.yml # the script adds each project's network and SSL volume
│ ├── nginx.conf # http { include /etc/nginx/sites/*.conf; }
│ ├── nginx.Dockerfile # nginx:1.29.1-alpine
│ ├── site-template.conf # site configuration template (SLUG / DOMAIN)
│ ├── dhparam.pem # only with --create-dhparam
│ ├── sites/
│ │ └── <slug>.conf # the project's servers on :80 and :443
│ │ # (<slug>.conf.disabled after deactivate.sh)
│ └── logs/
│ └── <slug>/ # project nginx logs (mounted in <slug>_nginx),
│ # rotated by /etc/logrotate.d/mooship
└── <slug>/ # Moodle project
├── docker-compose.yml # project services (see the table below)
├── .env # ports, passwords, versions; generated by the script
├── .config/
│ ├── nginx/
│ │ ├── _site.conf # project nginx: :80 (ACME, redirect) and :443 (site)
│ │ └── .htpasswd # only with --enable-basic-auth
│ └── php/
│ ├── php74.ini … php84.ini # phpXX.ini for the selected version is mounted
│ ├── mooship.ini # Moodle limits and OPcache, loaded after phpXX.ini
│ └── fpm-pool.conf # PHP-FPM pool size
├── .docker/
│ ├── php/ # php74 … php84.Dockerfile; selected phpXX is built
│ ├── nginx/ # nginx-1.29.1.Dockerfile
│ └── init/postgres/ # empty, unused
├── public_html/ # Moodle code + config.php → /var/www/html in containers
│ └── public/ # Moodle 5.1+ only: nginx document root
└── moodledata/ # Moodle data → /var/www/moodledata
Each project also receives the following Docker resources:
- an external network named
<slug>;
- volumes
<slug>_db (containerized database only), <slug>_ssl_certificates, <slug>_certbot_www, and <slug>_redis_data.
Project services (moodle/docker-compose.yml)
| Service |
Container |
Image |
Purpose |
php |
<slug>_php |
.docker/php/phpXX.Dockerfile (based on php:X.Y-fpm) |
PHP-FPM with Moodle extensions: gd, intl, zip, soap, pgsql/mysqli, redis, apcu, opcache, and others. Runs as www (uid 1000). Limits and OPcache come from .config/php/mooship.ini; the pool size comes from the resource profile in .env. Port 9000 is published only on 127.0.0.1:PHP_PORT |
nginx |
<slug>_nginx |
nginx:1.29.1-alpine |
Project web server. The :80 block serves ACME validation and redirects everything else to HTTPS; :443 serves the site. Runs nginx -s reload every 6 hours to pick up renewed certificates. Ports are not published on the host; traffic arrives only through nginxproxy |
db |
<slug>_db |
postgres:17-alpine or mysql:8.4 |
Database, with memory settings from the resource profile. Port 5432/3306 is published on the host as DB_PORT. This service is omitted with --db-native |
redis |
<slug>_redis |
redis:7-alpine |
Password-protected Redis (--requirepass), host port REDIS_PORT. Stores Moodle sessions (config.php); php starts after it |
certbot |
<slug>_certbot |
certbot/certbot:v5.8.0 |
One-time certificate issuance (docker compose run --rm certbot …) |
certbot_renew |
<slug>_certbot_renew |
certbot/certbot:v5.8.0 |
Runs certbot renew every 12 hours |
cron |
<slug>_cron |
Same image as php |
Runs admin/cli/cron.php every 60 seconds |
permissions |
<slug>_permissions |
alpine:3.24 |
Sets permissions once: public_html to 1000:1000 and 755; moodledata to 1000:1000 and 777 |
After docker compose up -d, the certbot and permissions containers have an Exited status. This is normal.
How it works
Client ──► nginxproxy :80 / :443 ──(Docker network <slug>)──► <slug>_nginx :80 / :443 ──► <slug>_php :9000
- Each project has a separate Docker network named
<slug>. The shared nginxproxy container joins all project networks and routes requests by server_name. It resolves <slug>_nginx per request through Docker's DNS, so a stopped project returns 502 for its own domain without preventing the proxy from starting or reloading for other sites.
- HTTPS uses two TLS connections. nginxproxy accepts traffic on :443, terminates TLS, and proxies it over HTTPS to
<slug>_nginx:443. Plain http:// requests are redirected to HTTPS (301), except ACME challenges.
- Moodle sees real client addresses. nginxproxy appends the client address to
X-Forwarded-For. Project nginx trusts only private (Docker) peers and uses the last entry of that header (real_ip_recursive off), so REMOTE_ADDR is the client address and cannot be forged by sending the header. Moodle logs, IP-based restrictions, and login throttling work without extra Moodle settings.
- The certificate is stored in
<slug>_ssl_certificates. The volume is mounted in project nginx (/etc/letsencrypt) and nginxproxy (/etc/letsencrypt/<slug>).
- Renewed certificates are picked up automatically.
certbot_renew renews the certificate, while project nginx and nginxproxy reload their configuration every 6 hours. This works for nginxproxy created by the current script version.
- Request size limit. The proxy accepts requests up to 2048 MB (
client_max_body_size 2048m in nginxproxy/nginx.conf); project nginx also allows 2048M. PHP determines the actual upload limit: 1024 MB in .config/php/mooship.ini. nginxproxy streams request bodies to the project (proxy_request_buffering off) and, like project nginx, waits up to 300 seconds for a response.
- Project nginx logs are written on the host under
/var/www/nginxproxy/logs/<slug>/: access.<domain>.log, error_warn.<domain>.log, and acme_access.log. /etc/logrotate.d/mooship rotates them daily and keeps 14 compressed files (copytruncate, so nginx needs no signal). Deployment creates this file when logrotate is installed and never overwrites it.
- Container logs are bounded. nginxproxy writes access and error logs to stdout/stderr (
docker logs nginxproxy). Project services and the proxy use the json-file