Note: You are currently viewing documentation for Moodle 3.11. Up-to-date documentation for the latest stable version of Moodle may be available here: Installation guide for Windows using WSL (Windows Subsystem for Linux).

Installation guide for Windows using WSL (Windows Subsystem for Linux)

From MoodleDocs

WSL or Windows Subsystem for Linux is the easiest way to create a LAMP stack on Windows. It isn't suitable for production but as most production servers use LAMP, installing on WSL is good preparation for a later Linux VPS production server install. WSL allows full access to the Windows desktop while running a Linux kernel, is easy to install and remove and as a separate system, will not change anything under Windows.

Open a Windows command prompt (Win + R, cmd) and enter this command:

wsl --install -d Ubuntu

The Ubuntu window now opens as it finishes installing and you will be prompted for a username and password. Write these down! From the opening screen of Linux also write down your IP address, ethernet (for wired) or Wifi.

You now have a new Ubuntu installation. You can refer now to the Step-by-step Installation Guide for Ubuntu or follow this short guide.
Copy and paste these commands to update Linux and begin installing the LAMP stack. You can accept the default and enter "Y" for these commands.

sudo apt update && sudo apt upgrade
sudo apt install apache2 mysql-client mysql-server php libapache2-mod-php

Secure the root password of your database. Again write it down! Everything else can be accepted at default value.

sudo service mysql restart
sudo mysql_secure_installation

Install the modules required for Moodle.

sudo apt install graphviz aspell ghostscript clamav php7.4-pspell php7.4-curl php7.4-gd php7.4-intl php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-ldap php7.4-zip php7.4-soap php7.4-mbstring

Restart Apache so that the modules are loaded correctly,

sudo service apache2 restart

I get a APR_TCP_DEFER_ACCEPT warning at this step but ignore as Apache is running. You can confirm by going to localhost on your browser and seeing the default Apache2 Ubuntu Default page.You can check the status of mysql and Apache with these two commands. If you have problems, you can always restart.

sudo service apache2 status
sudo service mysql status

Use git to get the latest version of Moodle.

cd /opt
sudo git clone git://
cd moodle
sudo git branch -a
sudo git branch --track MOODLE_311_STABLE origin/MOODLE_311_STABLE
sudo git checkout MOODLE_311_STABLE

Put the Moodle code in the Apache webserver directory (/var/www/html), create the modledata directory, and set its permissions.

sudo cp -R /opt/moodle /var/www/html/
sudo mkdir /var/moodledata
sudo chown -R www-data /var/moodledata
sudo chmod -R 777 /var/moodledata

Set up the database. To use mysql, use the root password you set when securing the database. If you have a problem here, try restarting the mysql service. (sudo service mysql restart)

sudo mysql -u root -p

Remember to change moodledude and passwordformoodledude

mysql> CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
mysql> create user 'moodledude'@'localhost' IDENTIFIED BY 'passwordformoodledude';
mysql> quit;

Edit the php.ini file

 sudo nano /etc/php/7.4/apache2/php.ini

Use CTRL-W to find the max_input_vars, remove the semicolon and change it to equal 5000.

; How many GET/POST/COOKIE input variables may be accepted
max_input_vars = 5000

CTRL-O and CTRL-X saves the file, now restart Apache

sudo service apache2 restart

Now go to (your IP address)/moodle on your browser and finish the install. If yio have forgotten your IP address use the command hostname -I. Database type is mysql, data directory is /var/moodledata and you use the user name and password you changed from moodledude to connect to the database. Save the config file by entering:

  sudo nano /var/www/html/moodle/config.php 

and pasting in the content from the config.php page and save (CTRL-O, CTRL-X)_ Other than a warning on "site not https", all requirements should be met.

Set up cron for housekeeping.

sudo crontab -u www-data -e

Select 1 to use nano. Enter this command, save and exit.

 * * * * * /usr/bin/php  /var/www/html/moodle/admin/cli/cron.php >/dev/null

Plugins can be used to add new features to your Moodle installation. On your new Moodle, go to

Dashboard -> Site administration -> Plugins -> Install plugins

Install a plugin from the Moodle plugins directory. Choose "Moodle Benchmark", "Install now" and your new Moodle site. You will get a message /var/www/html/moodle/report is not writable. On your WSL window, enter this command.

sudo chmod 777 /var/www/html/moodle/report

Go back to Moodle to continue, confirm and continue. Don't forget to reset the permissions back so the directory is again not writable.

sudo chmod 755 /var/www/html/moodle/report

The benchmark report will now be under Site administration -> Reports

WSL is great for learning. If you have mastered these steps, move on to Installing Moodle on a Ubuntu cloud server