This article shows you how to install and configure a Moodle LMS instance on Amazon Lightsail. It contains steps to complete launch AWS Lightsail, install Moodle and configure your first course.

In this tutorial we will do the following:

  1. Launch AWS Lightsail with Ubuntu 18.04 onboard
  2. Install Required Software
  3. Install Moodle LMS

STEP 1: Launch and configure your instance with Amazon Lightsail and Ubuntu 18.04.

There is no need to explain in details how to launch AWS LightSail instance, becouse there is a complete guide how to do this, which can be found in the end of this step.

!IMPORTANT NOTE You need to choose “OS Only” and “Ubuntu 18.04” like on the screen below instead of the option you’ll see in the guide.

We will install all required software including PHP 7 by ourselves. That’s why we need just latest version of operational system and nothing more.
This step is very important becouse latest Moodle version is not compatible with PHP 5.

Link to guide:

STEP 2: Install Required Software

2.1: Install Apache/MySQL/PHP

Git installation

sudo apt-get install git-core 

Installing php 7.2 with extra modules

sudo add-apt-repository ppa:ondrej/php 
sudo apt-get update

Installing Apache and extra modules

sudo apt-get install apache2 php7.2 libapache2-mod-php7.2
sudo apt-get install graphviz aspell ghostscript clamav php7.2-pspell php7.2-curl php7.2-gd php7.2-intl php7.2-mysql php7.2-xml php7.2-xmlrpc php7.2-ldap php7.2-zip php7.2-soap php7.2-mbstring

Restarting apache web-server

sudo service apache2 restart

2.2: Setup MySQL Server

Before you start reading this section, please be aware that there is an alternative Option 2.2 at the bottom, where we show how to install MariaDB instead of MySQL

sudo apt-get install mysql-client mysql-server

Changing mysql config file

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

This command shall open mysqld.cnf in nano editor, which is installed by default in Ubuntu 18.04. You can use any other editor i.e vim, but in this tutorial we are using nano.

Add the following lines in your config file.

default_storage_engine = innodb
innodb_file_per_table = 1
innodb_file_format = Barracuda

To save the file press CRT + O and then ENTER. Then CTR + X to exit nano.

In the end my file look like:

Now restart MySQL:

sudo service mysql restart 

Now we secure our installation

sudo mysql_secure_installation

After this command you shall went throw few steps where you can reset your password. At the end you shall see – “All done!” notification.

Step 2.2 [ALTERNATIVE] MariaDB as an alternative to MySQL

Nowadays MariaDB became a very popular open-source solution for database servers. Here you may find the steps how to install it instead of MySQL

Installing MariaDB server and client.

sudo apt-get install mariadb-server mariadb-client 

After this we run a command to set our root password and secure MariaDB server.

sudo mysql_secure_installation

During this command there will a chance to set your root password and there will be few promts, you may type “Y” to all of them

Now we need to open MariaDB config file and put there some lines:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Now please add the following lines of code just below [mysqld] section.

default_storage_engine = innodb
innodb_file_per_table = 1
innodb_file_format = Barracuda
innodb_large_prefix = 1

Now, restarting MariaDB

sudo service mariadb restart´╗┐

Step 2.3 Create Database and User

Connect to MySQL. At this stage you have to enter your password.

sudo mysql -u root -p 

Create database, user and grant required permissions:

CREATE DATABASE moodledb DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 
CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'YourPasswordHere!';

!IMPORTANT: You shall use utf8mb4_unicode_ci encoding ( not utf8_unicode_ci ) otherwise you’ll got yellow notification warning during the installation and some of Moodle functions will not work properly

STEP 3: Install Moodle LMS

In this tutorial we will install Moodle into www root folder. In many cases you might prefer to put your local git repository outside the webroot 
to stage your upgrades efficiently. However in this example we will use webroot folder.

Step 3.1 Take Moodle from Git

cd /var/www/html/
sudo git clone git://
cd moodle
sudo git branch --track MOODLE_36_STABLE origin/MOODLE_36_STABLE
sudo git checkout MOODLE_36_STABLE

At the time this tutorial have been created, the latest Moodle version is 3.6. This is why we use MOODLE_36_STABLE. However you can get a list of branches available by using a command:

sudo git branch -a 

The latest brach will look like MOODLE_XX_STABLE, where XX shall be the highest number.

Now we will create moodledata folder where all our files and data shall be located in. Then we grant the rights to moodle and moodledata folders.

sudo mkdir /var/moodledata
sudo chmod -R 777 /var/moodledata
sudo chmod -R 777 /var/www/html/moodle

We grant full permission to moodle folder to run installer, we will change it later.

Step 3.2 Installation via command line

Installation from commandline is quite easy if you know what to do. First run the following command.

sudo /usr/bin/php /var/www/html/moodle/admin/cli/install.php

You should get a look like the following:

Follow the promts and put the values you need.

If you never installed Moodle, then it might be better to you Step 3.2 Alternative – installation via browser

Step 3.2 [ALTERNATIVE] Installation via browser

Open now the following link in browser:


You can find INSTANCEIP in your Networking Tab for the LightSail Instance you have created before

Make sure you have attached Static IP address. If you don’t have it yet, you may click “Create static IP” button and follow required steps. Without static IP you’ll get new IP each time you reboot the instance.

Once IP has been changed you have to logic via SSH again.

So, go to http://INSTANCEIP/moodle and follow required steps.

Make sure you enter corrent path to your moodledata folder. In our example it’s /var/moodledata

If you have got the message like this:

That means you forgot to grant full permission to your folders. Ensure you runned the following commands in the past:

sudo chmod -R 777 /var/moodledata
sudo chmod -R 777 /var/www/html/moodle

Finally there should be a confirmation box like this:

“Server checks” should show all green points except “site is not https” yellow point, which can be fixed later by adding SSL certificate to your instance

Then follow the prompts and enter your username, password and site name.

Your new instance will look like:

Now, we have to revert back permissions for the moodle folder.

sudo chmod -R 0755 /var/www/html/moodle

The last one important step is cron configuration. Without it your system won’t work correctly.

crontab -e

Add the following line and save it.

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

This line will run cron.php script every minute.

Next steps

You Moodle installation is completed now. You can start managing your brand new instance, apply your custom settings, create courses and learning materials.

If you can’t choose Free Open-Source LMS see also – Top 10 Free Open-Source LMS

Leave a comment