AWS Public Sector Blog

Accelerate remote learning in minutes using Moodle on AWS

The United Nations Educational, Scientific and Cultural Organization (UNESCO) estimated in 2019 that over 12 million people took part of some kind of online learning. Last year, education institutions quickly implemented online learning tools in response to social distance measures adopted worldwide during the COVID-19 pandemic.

One of the most popular tools in the education sector is Moodle with 253 million users from 241 countries. Moodle is an online learning, open source platform designed to create customized learning environments through a simple interface, with drag and drop features. Whether there is a need for 10 or 10 million students to access online content, the cloud helps create a safe, scalable environment.

To accelerate the adoption on Moodle, in this post I walk through the process to deploy Moodle on AWS in four steps. The time to complete this tutorial is about 45 minutes and doesn’t require any previous experience on AWS, and can be run within the AWS free tier.


The architecture for the solution to deploy consists of an Amazon Elastic Compute Cloud (Amazon EC2) instance and a MySQL database running on Amazon Relational Database Service (Amazon RDS), both resources deployed inside a Virtual Private Cloud (VPC), plus three Amazon Simple Storage Service (Amazon S3) buckets.

The four steps to complete this tutorial are:

  1. Deploy AWS resources
  2. Get security credentials
  3. Prepare database for Moodle
  4. Configure storage on Moodle

1. Deployment of AWS resources

AWS CloudFormation provides a visual designer. See the template provided for this tutorial, visualized in CloudFormation template designer in Figure 1:

Moodle deployment template

Figure 1

First, subscribe to Bitnami’s Moodle AMI on the AWS Marketplace by either selecting the link or Continue to Subscribe button.

Moodle Certified by Bitnami in the AWS Marketplace

Figure 2

Proceed to accept terms and conditions for Bitnami’s Moodle AMI by selecting Accept Terms.

A confirmation message appears and after a few minutes, you receive an email confirmation.

Go to the AWS console and open the service list located on the upper left corner of the screen. Notice you can now access any of the more than 175 services available on categories such as machine learning, analytics, databases and more. Enter EC2 in the search bar and click on EC2.

Select Key pairs located on the left side of the screen and then proceed to create a key pair using the option Create key pair located on the upper right corner of the console.

Write a representative name such as “moodle-keypair” and select the key pair based on the operating systems that you are using: PEM for Linux and MacOS, or PPK for Windows.

Select Create key pair under EC2

Figure 3

Next, launch the CloudFormation. To do this, open the list of services and select CloudFormation and then select the option Create stack with new resources (standard), located on the upper right corner of the screen.

select CloudFormation and then select the option Create stack with new resources (standard), located on the upper right corner of the screen

Figure 4

Since the template has already been prepared for you, select Upload a template file and use Select file to locate the provided MoodleQuickStart.json file.

Upload a template file and select file AWS Console

Figure 5

Provide some data for your stack:

  • Name of the stack: Identifier of the CloudFormation stack; for example: “Moodle-quickstart”
  • DBUsername, DBPassword: User and password that is created on the RDS instance for you
  • KeypairName: Name of the keypair that you created previously
  • MoodleVolumeSize: Size of the storage volume where Moodle will be running
  • UserPrefix: Identifier that is added to the name of resources such as buckets; must be unique

On the following screen, use the default configuration and select Next so you can move on to the confirmation screen where you can review all the configurations selected. To launch the deployment, acknowledge the message about AWS Identity and Access Management (IAM) capabilities that informs you the template is allowed to create IAM resources (such as IAM users and roles). Select Create Stack.

Create stack AWS IAM

Figure 6

By default, when you launch the template, you are taken to the CloudFormation “Events” where you can see the resources deployment. You can also move to the “Resources” tab where you can see the resources being created.

CloudFormation Events Moodle quickstart

Figure 7

The deployment of the stack finishes approximately 10 minutes later. Now enter “moodlewebs” on the resource search bar to find the EC2 instance created from the Moodle AMI.

CloudFormation Resources Moodle quickstart

Figure 8

Select the instance identifier labeled as physical ID and you are directed to the EC2 console where you can see the properties of the Moodle web server. Copy the public Public DNS (IPv4) and paste it in a new browser tab.

Your Moodle website is now up and running. At this point, Moodle is using a local database installed inside the web server. We can change this later.

Moodle home new site setup

Figure 9

2. Obtain access credentials

We need to acquire two credentials:

  • Admin credentials for Moodle
  • An IAM user (access key and secret key) with Amazon S3 permissions to allow Moodle to store and retrieve files from our buckets

To recover the Admin credentials for Moodle, connect into the web server, close the tab with the Moodle website and go back to the Amazon EC2 console. Select Actions then Connect. The instructions are displayed on how to connect using the key pair previously created.

EC2 connect

Figure 10

Check out the step-by-step guide on how to connect to an EC2 instance if you are running Linux/MacOS or Windows. Instead of using the “ec2-user” or the “root” user, use “bitnami.” Once you get into the terminal, you see a message similar to the following:


Figure 11

Lastly, run the following command:

sudo cat /home/bitnami/bitnami_credentials

The username and password is shown:

Moodle SSH credentials

Figure 12

The instructions to recover Admin user for Moodle are also available on the site of Bitnami.

Let the terminal open for now, we need it again for the step 3.

To recover the access key and secret access key that allows Moodle to access our Amazon S3 buckets, go back to the AWS console and open the list of services, enter IAM.

AWS IAM Moodle

Figure 13

Select Users and enter repo on the search bar. You find a user already created for you with the right S3 write and read permissions. Select the username.

IAM user repo

Figure 14

This user has no credentials, so you need to create them. Select the security credentials tab and next Create Access key.

IAM sec credentials

Figure 15

You need to temporarily save the credentials for the last step of this tutorial. After you configure them, I recommend you delete them from the temporary storage.

3. Prepare database

To allow Moodle to use RDS as the database engine we need to create the schema and a database user with access to it. To do that, connect using MySQL client installed on the Moodle application server (remember, our database was configured to be accessible only from within our AWS VPC).

Open the list of services and enter RDS and select DB Instances.


Figure 16

Select the instance called moodledbinstance and on the Connectivity & Security tab find a property called Endpoint; write down this value, you use it later.

RDS Moodle

Figure 17

Go to the terminal you left open previously and run the following command, replacing the <RDS_HOSTNAME> with the endpoint copied above. Also replace <RDS_NAME> with the parameter DBUsername specified on the step 1 to launch the CloudFormation stack.

mysql -u <RDS_NAME>-p -h <RDS_HOSTNAME>

When asked, type the database password specified on the step 1 via the parameter DBPassword.

As a result, you get a successful connection and the terminal shows a message like the following: mysql>


Figure 18

On Bitnami’s documentation you can find the proper instructions to prepare Moodle’s database schema. For convenience, I’ve included a short summary. Run the following commands on the MySQL terminal replacing <PASSWORD> for a custom password for the Moodle database user.

create user moodleuser@'%' identified by '<PASSWORD>';
grant all privileges on awsmoodle.* TO moodleuser@'%';
flush privileges;

Since Moodle has already configured the required tables on the local database installed on the application server, we need to migrate them into RDS. Go to your web browser with the Moodle website open and add the following path to the address bar: /admin/tool/dbtransfer/index.php. The full address should look like: where is the IP address of our web server.

Moodle MigrateDB

Figure 18

Type the required values:

  • Type: Improved MySQL
  • Host: Endpoint de RDS
  • Database name: awsmoodle
  • Database user: moodleuser
  • Database password: password defined above when we created the Moodle database user
  • Tables prefix: mdl_
  • Port: 3306
Moodle Migration Successful

Figure 19

Once the table migration is completed, confirm that the tables are actually there. Run the following command on the MySQL terminal:

use awsmoodle;
show tables;

You should see a list of table names with a prefix “mdl_”

Moodle Tables

Figure 20

Run the following command to exit the MySQL terminal:


The last step to configure our database is to specify Moodle to use our RDS database instead of the local server. Edit the config.php file using the following commands:

vi /opt/bitnami/apps/moodle/htdocs/config.php

Once you enter the vi editor, press the letter i to start editing the file. Edit the document as the example bellow:

  • dbhost: replace <RDS_ENDPOINT> with the RDS instance endpoint
  • dbpass: replace <PASS> with the Moodle’s db user password created before

Figure 21

When you finish, press the following combination of keys to save the changes: ESCAPE + : + wq! + ENTER

Finally, run the following command to restart the web server and force Moodle to use the new parameters we configured:

sudo /opt/bitnami/ restart apache

Open again the web browser with Moodle and select the upper left corner option called “Newsite” to navigate to the root of the site.


Figure 22

4. Setup Amazon S3 storage

To allow Moodle to use Amazon S3 as repository, use the plugin Amazon S3 Moodle that comes pre-installed with our Moodle; you only have to enable it. Navigate to the following Moodle options:

Site administration > Plugins > Repositories > Manage repositories

Identify the repository Amazon S3 and select the option Enabled and visible. You are redirected to the configuration page.

Moodle S3 plugin

Figure 23

Copy, and paste the Access key and Secret key generated previously and select Save.

Moodle S3 credentials

Figure 24

To check that the configuration is working, navigate to the course page, create a new course, and add a file.

Moodle S3 Upload

Figure 25

Select file and you find the option Amazon S3 where you visualize all the buckets available under your account.

Moodle S3 filepicker

Figure 26

After selecting a file, you see the pre-visualization based on the file types supported by Moodle. Since you don’t configure any public policy, the buckets on our account are private and via Moodle you control who can see your content. By default, all courses on Moodle are restricted to only authenticated users.

Moodle insert file

Figure 27

What’s next?

If you want to increase the reliability of your Moodle deployment, configure the application server on Amazon EC2 with an Elastic Load Balancing and Amazon EC2 Autoscaling or configure the multi Availability Zone feature of Amazon RDS. Check out this blog post (in Spanish) for a guide on how to deploy some additional services for increased performance such as Amazon ElasticCache and Amazon Elastic File System (Amazon EFS). Please note that charges may be incurred based on your usage or configuration beyond the actions outlined in this post.

Learn more about the cloud for education.