How to effortlessly install Moodle locally using DDEV

How to effortlessly install Moodle locally using DDEV image

Posted by Uros on 09 Feb 2023 in Moodle,Development

In today's digital age, utilizing robust learning management systems like Moodle has become increasingly essential for educational institutions and corporate training. However, setting up such a platform can be a daunting task, especially if you're looking to install it locally for development or testing purposes. Fortunately, with DDEV, a Docker-based PHP development environment, you can have Moodle up and running in no time. This comprehensive guide will walk you through every step of the process, from Docker and DDEV installation to Moodle setup.

Understanding Docker and DDEV:

Before we delve into the installation process, it's important to understand what Docker and DDEV are and the roles they play in this setup.

Docker is an open-source platform designed to automate the deployment, scaling, and management of applications within software containers. These containers, which are lightweight and standalone, allow developers to package an application with all the parts it needs, including libraries and other dependencies, and ship it out as one package. This ensures that the application will run on any other machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

On the other hand, DDEV is a development environment built on Docker. It simplifies the process of setting up and managing PHP-based projects, making it an ideal tool for working with Moodle, a popular PHP-based learning management system. DDEV provides a consistent and reliable environment for your applications, eliminating the common "but it works on my machine" problem.

Prerequisites: Docker Installation:

Before you can install DDEV, you need to have Docker on your system. The process varies depending on your operating system.

For Windows users, if you're working inside the Windows Subsystem for Linux (WSL2), you can install Docker Engine inside of it. Alternatively, you can install Docker Desktop, which works with both traditional Windows and WSL2. Docker Desktop provides an easy-to-use graphical interface and enables Docker functionalities directly from your Windows desktop.

For Linux users, Docker installation depends on your specific distribution. It's generally best to use your native package repository (apt for Debian-based distributions like Ubuntu, and yum for RPM-based distributions like Fedora). Post-installation steps include adding your Linux user to the docker group and configuring the Docker daemon to start at boot.

For macOS users, you can install either Colima or Docker Desktop. Colima is a project that bundles a container management tool called Lima with a Docker (Linux) backend. It's designed to provide a seamless Docker experience on macOS.

DDEV Installation:

Once you have a Docker provider installed, you're ready to install DDEV. The installation process differs slightly based on your operating system.

For Windows, you can install DDEV using WSL2 with Docker inside, using WSL2 with Docker Desktop, or by installing directly on traditional Windows with an installer. While the latter option may seem more straightforward, using WSL2 is highly recommended due to its performance benefits and the common experience of working with Ubuntu and Bash.

For Linux, DDEV provides Debian and RPM packages that work with apt and yum repositories, making the installation process relatively straightforward. You can also use a locally-trusted certificate with mkcert for modern browsers that require valid certificates.

For macOS, Homebrew is the easiest and most reliable way to install and upgrade DDEV. Homebrew is a package manager for macOS that simplifies the installation of software on Apple's operating system.

Moodle Installation on DDEV:

After setting up Docker and DDEV, you're now ready to install Moodle. The process is straightforward and can be accomplished with a series of command-line instructions.

Configure DDEV for your new project using the command:

ddev config --composer-root=public --create-docroot --docroot=public --webserver-type=apache-fpm --database=mariadb:10.6

Start DDEV by running:

ddev start

Create a new Moodle project with the command:

ddev composer create moodle/moodle -y

Install Moodle with the command:

ddev exec 'php public/admin/cli/install.php --non-interactive --agree-license --wwwroot=$DDEV_PRIMARY_URL --dbtype=mariadb --dbhost=db --dbname=db --dbuser=db --dbpass=db --fullname="DDEV Moodle Demo" --shortname=Demo --adminpass=password'

Launch Moodle by running:

ddev launch /login

Log into your Moodle account using the username 'admin' and the password 'password'.

By following these steps, you'll have a local Moodle environment ready for development or testing.

Conclusion:

Setting up Moodle locally using DDEV is a straightforward process that can significantly streamline your workflow. Not only does it save you time, but it also provides a consistent and reliable environment for your Moodle development and testing. By following the steps outlined in this comprehensive guide, you'll have a local Moodle environment ready for development in no time. So, why wait? Experience the ease and convenience of local Moodle development with DDEV today.