This repository provides a complete Docker-based environment for local Moodle development, incorporating essential services such as a web server, database, PHP runtime, and email testing utility. It also includes HTTPS support for enhanced testing of secure features, enabled through the use of mkcert
to generate trusted SSL certificates for localhost.
The setup includes:
- Nginx as the web server, configured to handle both HTTP and HTTPS requests.
- PHP-FPM with essential Moodle extensions for optimal performance.
- MariaDB as the database server, configured with typical Moodle settings.
- Mailhog for capturing outgoing emails, allowing easy testing of email functionality within Moodle.
- mkcert for generating locally trusted SSL certificates, enabling HTTPS support on localhost.
This setup is platform-independent and can be used on macOS, Linux, and Windows systems with minimal configuration changes. Once set up, you will have a complete Moodle environment accessible via both HTTP and HTTPS, suitable for development and testing.
- Docker and Docker Compose
mkcert
for generating trusted SSL certificates for local development
git clone git@github.com:adrian-sarmas/moodle-dev-env.git moodle-dev-env
cd moodle-dev-env
Place the Moodle source code in the moodle
directory. You can download Moodle from moodle.org or use git
to clone a specific version.
cd moodle
# Example to download a specific Moodle version (replace <VERSION> with the desired version)
wget https://download.moodle.org/stable<VERSION>/moodle-latest-<VERSION>.tgz
tar -xzvf moodle-latest-<VERSION>.tgz --strip 1
cd ..
-
Install
mkcert
if not already installed:- macOS:
brew install mkcert && brew install nss
(for Firefox support) - Linux and Windows: Follow instructions from the mkcert GitHub page
- macOS:
-
Generate SSL certificates:
mkcert -install mkcert -key-file ssl/localhost.key -cert-file ssl/localhost.crt localhost
This will create two files:
ssl/localhost.key
- Private keyssl/localhost.crt
- Certificate
If you encounter port conflicts with other local servers, you can modify the exposed ports in docker-compose.yml
. For example, change the HTTP port from 8045:80
to another unused port, like 8080:80
.
In docker-compose.yml
:
ports:
- "8080:80" # HTTP
- "8443:443" # HTTPS
And update nginx.conf
to ensure the server listens on the correct ports if you made any changes.
In moodle/config.php
, set the wwwroot
to use HTTPS and specify the correct port if needed (default is 8443
):
$CFG->wwwroot = 'https://localhost:8443';
Once everything is set up, you can start the Docker containers:
docker-compose up --build
This will spin up the following services:
- MariaDB: MySQL-compatible database for Moodle
- PHP-FPM: PHP environment for running Moodle
- Nginx: Web server configured for both HTTP and HTTPS
- Mailhog: Mail server for capturing outgoing emails (available at http://localhost:8025)
You can now access Moodle:
- HTTP: http://localhost:8045 (or another port if modified)
- HTTPS: https://localhost:8443 (or another port if modified)
- Mailhog: Access Mailhog for viewing email messages sent by Moodle at http://localhost:8025.
- Database: The MariaDB database is accessible at
mariadb
with the credentials configured indocker-compose.yml
.
If your browser shows warnings for the certificate, ensure that mkcert
's root CA is properly installed and trusted.
If you encounter issues with ports, update the ports
section in docker-compose.yml
to use available ports on your system.
This project is licensed under the MIT License. See the LICENSE
file for details.
- This environment is intended for local development only and should not be used in production.
- Make sure to update any sensitive credentials before deploying in a non-local environment.