,

How to Install Moodle on Windows WSL

This tutorial explains how to install Moodle, an open-source learning management system, on Windows 10 WSL (Windows Subsystem for Linux) 2 with Ubuntu OS. The steps cover enabling WSL in Windows, installing Ubuntu, Apache, MariaDB, PHP and configuring Moodle. The guide also mentions the release of WSL 2, which improves system performance and compatibility over…

This brief tutorial shows students and new users how to install Moodle with Apache on Windows 10 WSL (Windows Subsystem for Linux) 2 with Ubuntu OS.

Moodle is an open-source, mobile-friendly learning management system (LMS) used to create and deliver educational courses and training materials. While it was initially designed to run on Linux servers, it is now possible to run Moodle on Windows using the Windows Subsystem for Linux (WSL).

WSL allows you to run a full Linux environment on your Windows machine, which means you can run Moodle on Windows without needing a separate server. This can be useful for students or educators who don’t have access to a dedicated Linux server or who prefer to run Moodle on their local machine for testing purposes.

Additionally, WSL 2, the latest version of WSL, offers significant performance improvements over the original version, making it even more attractive for running Linux applications like Moodle on Windows.

If you have a machine that meets the requirements above to run WSL 2, continue below.

To get started with running Moodle on Windows with WSL, follow the steps below:

Enable WSL in Windows

To enable WSL in Windows, you will need to open the PowerShell terminal as an administrator. Click on Start, then begin typing PowerShell.

Next, right-click the Windows PowerShell app and choose to run as administrator.

When the console opens, run the commands below:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

After installing, you should get a success message similar to the lines below:

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

WSL 2 requires Windows 10 Virtual Machine Platform to be enabled. This is not Hyper-V. To eallow the VM toplatform feature in Windows, run the commands below from the same PowerShell administrator’s console.

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

If you’re using Windows 10 version lower than 2004, then use the commands below:

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart

When you’re done running the commands above, restart your computer for all the configuration changes to apply. If you don’t restart, the below command might not be recognized.

After restarting your computer, log back in and launch PowerShell as administrator. Then, run the commands below to configure WSL 2 as the default version of WSL.

wsl --set-default-version 2

Install Ubuntu on Windows 10

Now that WSL 2 is installed and ready to be used, open the link below to download and install a copy of Ubuntu 20.04 from the Windows store.

Get Ubuntu 20.04 LTS – Microsoft Store

Ubuntu 20.04 LTS on Windows allows you to use Ubuntu Terminal and run Ubuntu command line utilities, including bash, ssh, git, apt, and many more.

Click the Get button and install. After installing Ubuntu, you’ll want the option to launch Ubuntu from the Windows WSL environment.

After launching, Ubuntu should install and prompt you to create your account.

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: richard
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: 10.0.2.15
  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

That should do it!

Some troubleshooting commands to run when you run into the issues above. These run below and try to relaunch the Ubuntu image.

wsl --set-default-version 1
bcdedit /set hypervisorlaunchtype auto start

Now that the Windows 10 WSL environment is ready, continue to install Apache, MariaDB, and PHP and configure Moodle.

Install Apache HTTP Server

Apache is the most popular open-source web server powering most websites online. Since Moodle needs it, use the commands below to install it on Ubuntu.

To install Apache on Ubuntu, run the commands below:

sudo apt update
sudo apt install apache2

After installing Apache2, the commands below can be used to stop, start and restart Apache2 services.

sudo service apache2 stop
sudo service apache2 start
sudo service apache2 restart

To validate that Apache is installed and functioning, open your web browser and browse to the server’s hostname or IP address.

You should get a test page if everything works.

http://localhost

Install MariaDB Database Server

For this tutorial, we’re going to be installing MariaDB. Moodle needs a database server to store its content.

MariaDB is a truly open-source database server you can run with your projects. It is fast, secure, and the default server for almost all Linux.

To install MariaDB, run the commands below:

sudo apt install mariadb-server mariadb-client

After installing MariaDB, the commands below can be used to stop, start, and restart MariaDB services.

sudo service mysql stop
sudo service mysql start
sudo service mysql restart

Next, run the commands below to secure the database server with a root password if you were not prompted to do so during the installation.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat 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 and validate that MariaDB is installed and working, log in to the database console using the commands below:

sudo mysql -u root -p

Type the root password when prompted.

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)]>

The server was successfully installed if you see a similar screen.

Install PHP and Related Modules

PHP is a general-purpose scripting language that glues all the above components together. Moodle is a PHP application and requires PHP and related modules to function.

To install PHP and recommended modules, run the commands below.

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

That should get PHP installed with recommended PHP modules that you can run with many PHP-based applications.

To validate that PHP is installed, run the commands below:

php -v

You should see an output like the one below:

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 with a test PHP script and display the installed version and related modules that are enabled or disabled.

To do that, run the commands below to create a PHP test file called phpinfo.php

sudo nano /var/www/html/phpinfo.php

Then, type the content below and save the file.

<?php phpinfo( ); ?>

Save the file.

Open your browser and browse to your server hostname followed by phpinfo.php

Restart Apache, then type the address and browse the file.

http://example.com/phpinfo.php

You should see the PHP default test page.

At this stage, all required components that Moodle needs are installed above. Continue below to download and configure Moodle settings.

Create Moodle Database

When all the servers are installed above, it’s time to begin setting up Moodle environment. First, run the steps below to create a blank database for Moodle.

Login to the MariaDB database console using the commands below:

sudo mysql -u root -p

Then, create a database called moodle

CREATE DATABASE moodle;

Next, create a database user called moodleuser and set a password

CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'new_password_here';

Then, grant the user full access to the database.

GRANT ALL ON moodle.* TO 'moodleuser'@'localhost' WITH GRANT OPTION;

Finally, save your changes and exit.

FLUSH PRIVILEGES;
EXIT;

Download Moodle

At this point, Moodle is ready to be downloaded and installed. Use the commands below to download the latest version of Moodle. At the time of this writing, the latest version is 39.

To view Moodle releases, see this page.

sudo apt install git curl

After installing git and curl above, change into the Apache root directory and download Moodle packages from GitHub. Always replace the branch number with the latest branch.

cd /var/www/
sudo git clone -b MOODLE_39_STABLE git://git.moodle.org/moodle.git moodle

Then, run the commands below to set the correct permissions for Moodle to function.

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

Below is where you configure the Apache VirtualHost file for the Moodle site you’re creating. This file defines how client requests are handled and processed.

Run the commands below to create a new VirtualHost file called moodle. conf in the /etc/apache2/sites-available/ directory.

sudo nano /etc/apache2/sites-available/moodle.conf

Below is a perfect configuration setting for most Moodle sites on the Apache server. This configuration should work great.

Copy the content below and save it into the file created above.

<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 and exit.

After saving the file above, run the commands below to enable the new site, then restart the Apache server.

sudo a2ensite moodle.conf
sudo a2enmod rewrite
sudo service apache2 restart

At this stage, Moodle is ready and can be launched by going to the server’s IP or hostname.

http://example.com

Moodle installation wizard should open, and you can follow.

Choose the installation language and continue.

Confirm Moodle directory structure. Moodle directory: The full path to the directory containing the Moodle code.

Data directory: A directory where Moodle will store all file content users upload.

Moodle supports several types of database servers. Please get in touch with the server administrator if you do not know which type to use.

Type in the database name, username, and password to connect to the database created above.

Validate other checks and requirements and continue with the installation wizard.

You should configure your main administrator account on this page, which will completely control the site. Ensure you give it a secure username and password and a valid email address. You can create more admin accounts later on.

After that, Moodle should be installed and ready to use.

Conclusion:

This post showed you how to install Moodle in Windows WSL. If you find any error above, please use the comment form below to report.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *


Exit mobile version