How to Install Moodle on Windows WSL
Moodle is an open-source learning management system (LMS). It helps teachers create and share educational courses online. While Moodle was built to run on Linux servers, you can now run it on Windows using WSL (Windows Subsystem for Linux).
WSL lets you run a full Linux environment on your Windows computer. This means you can run Moodle right on your machine without needing a separate server. This is great for students or teachers who want to test Moodle locally before deploying it on a real server.
WSL 2 is the latest version. It’s much faster than the original WSL. This makes it perfect for running Linux applications like Moodle on Windows.
Enable WSL in Windows
Why: WSL needs to be turned on before you can use it.
What to do: Open PowerShell as an administrator. Click Start, then type PowerShell. Right-click Windows PowerShell and select “Run as administrator.”

Now run this command:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
You should see a success message like this:
Deployment Image Servicing and Management tool
Version: 10.0.19041.844
Image Version: 10.0.19042.844
Enabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.
Enable Virtual Machine Platform
Why: WSL 2 needs the Virtual Machine Platform feature to work.
Run this command from the same PowerShell window:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
If you’re using Windows 10 version 2004 or older, use this command instead:
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
After running these commands, restart your computer. This lets all the changes take effect. If you don’t restart, the next command won’t work.
After restarting, open PowerShell as administrator again. Run this command to set WSL 2 as the default version:
wsl --set-default-version 2
Install Ubuntu on Windows 10
Why: Ubuntu is a Linux operating system. You need it to run Moodle inside WSL.
Open this link to download Ubuntu 20.04 from the Windows Store:
Get Ubuntu 20.04 LTS – Microsoft Store
Ubuntu gives you a Linux terminal and command-line tools like bash, ssh, git, apt, and many more.

Click the Get button and install it. After installing, launch Ubuntu from WSL.
Ubuntu will ask you to create an account. Follow the prompts:
Installing, this may take a few minutes.
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: user
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 4.4.0-19041-Microsoft x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Mon Apr 12 17:57:37 CDT 2021
System load: 0.52 Processes: 7
Usage of /home: unknown Users logged in: 0
Memory usage: 26% IPv4 address for eth0: 192.168.1.100
Swap usage: 0%
1 update can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable
Great! Ubuntu is now installed.
If you run into problems, try these commands:
wsl --set-default-version 1
bcdedit /set hypervisorlaunchtype auto start
Install Apache HTTP Server
Why: Apache is a web server. Moodle needs it to run online.
Run these commands:
sudo apt update
sudo apt install apache2
You can use these commands to control Apache:
sudo service apache2 stop
sudo service apache2 start
sudo service apache2 restart
To check if Apache is working, open your browser and go to:
http://localhost
You should see an Apache test page.

Install MariaDB Database Server
Why: MariaDB is a database. Moodle stores all course content and user data in it.
MariaDB is open-source, fast, and secure. Most Linux systems use it.
Run this command:
sudo apt install mariadb-server mariadb-client
You can use these commands to control MariaDB:
sudo service mysql stop
sudo service mysql start
sudo service mysql restart
Now secure your database by setting a root password. Run this command:
sudo mysql_secure_installation
Answer the questions like this:
Enter current password for root (enter for none): Just press Enter
Set root password? [Y/n]: Y
New password: Enter a password
Re-enter new password: Repeat the password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y
To verify MariaDB is working, log in with this command:
sudo mysql -u root -p
Type your root password when asked. You should see:
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 46
Server version: 10.3.29-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]>
Great! MariaDB is installed.
Install PHP and Related Modules
Why: PHP is a programming language. Moodle is built with PHP and needs it to work.
Run this command to install PHP and all required modules:
sudo apt install php libapache2-mod-php php-imagick php-imap php-json php-ldap php-common php-pgsql php-ssh2 php-sqlite3 php-xml php-soap php-mysql php-gmp php-curl php-intl php7.4-mbstring php-xmlrpc php-gd php-xml php-cli php-zip
To check if PHP is installed correctly, run:
php -v
You should see something like:
PHP 7.4.3 (cli) (built: Oct 6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
You can also test PHP by creating a test file. Run this command:
sudo nano /var/www/html/phpinfo.php
Type this content:
<?php phpinfo( ); ?>
Save the file. Restart Apache, then open your browser and go to:
http://example.com/phpinfo.php
You should see a PHP information page.

Create Moodle Database
Why: Moodle needs its own database to store all course and user information.
Log into MariaDB with this command:
sudo mysql -u root -p
Create a database called moodle:
CREATE DATABASE moodle;
Create a database user called moodleuser:
CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'new_password_here';
Give the user full access to the moodle database:
GRANT ALL ON moodle.* TO 'moodleuser'@'localhost' WITH GRANT OPTION;
Save your changes and exit:
FLUSH PRIVILEGES;
EXIT;
Download Moodle
Why: You need to download the Moodle files from GitHub to install it.
First, install git and curl:
sudo apt install git curl
Go to the Apache directory and download the latest Moodle version:
cd /var/www/
sudo git clone -b MOODLE_39_STABLE git://git.moodle.org/moodle.git moodle
To see the latest Moodle versions, check this link:
Now set the correct permissions so Moodle can work:
sudo mkdir -p /var/www/moodledata
sudo chown -R www-data:www-data /var/www/
sudo chmod -R 755 /var/www/
sudo chown www-data:www-data /var/www/moodledata
Configure Apache
Why: Apache needs to know how to handle Moodle requests. You do this by creating a configuration file.
Create a new Apache configuration file:
sudo nano /etc/apache2/sites-available/moodle.conf
Copy and paste this configuration:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin admin@example.com
DocumentRoot /var/www/moodle
<Directory /var/www/moodle/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save the file. Then enable the new site and restart Apache:
sudo a2ensite moodle.conf
sudo a2enmod rewrite
sudo service apache2 restart
Launch Moodle
What happens: Moodle’s installation wizard opens. It walks you through the final setup steps.
Open your browser and go to:
http://example.com
The Moodle installation wizard should open.
First, choose your language:

Next, confirm the Moodle directories:
- Moodle directory: The folder with Moodle’s code
- Data directory: Where Moodle stores files users upload

Choose your database type. MariaDB is what we installed:

Enter your database details:
- Database name: moodle
- Username: moodleuser
- Password: The password you created

Continue through the installer. Check that everything meets the requirements.
Create your main admin account. This person will control the entire site. Use a strong password and a real email address:

Once done, Moodle is ready to use:

Summary
You’ve now successfully installed Moodle on Windows using WSL. Here’s what you did:
- Enabled WSL 2 on Windows
- Installed Ubuntu Linux on your Windows machine
- Installed Apache web server
- Installed MariaDB database
- Installed PHP and required modules
- Created a Moodle database and user
- Downloaded Moodle from GitHub
- Configured Apache for Moodle
- Ran the Moodle installation wizard
Moodle is now running on your Windows computer. You can use it to create courses, manage students, and deliver online education.
Frequently Asked Questions
What is Moodle and why would I want to install it on Windows WSL?
How do I enable WSL on my Windows 10 machine?
What is WSL 2 and how does it differ from WSL 1?
Do I need to install Ubuntu to use Moodle on WSL?
What should I do if my WSL commands are not recognized after enabling WSL?
Was this guide helpful?
This is a great article. Are there any differences when doing this on Windows 11? If so, please can you upgrade or create a new article for Windows 11.