Moodle Installation and Configuration on Amazon EC2 Instance
j

Pralad Bista

August 4, 2020

AWS | CMS | L200

moodle

Moodle is a learning platform designed to provide teachers, educational organizations and learners to design their own learning environments. Moodle uses PHP language to built-in free and open-source learning management system and it is distributed under the General Public License (GNU). New released year 2020 Moodle version is 3.9.

What we can do by using moodle?

  • Workshop activity– is a home work activity for student to assessment and self-assess.
  • Uses of Moodle’s Wiki or Glossary – or use Moodle as a placeholder for Padlet, Google Docs or Office 365 where they can write collaboratively.
  • Feedback,Choice and Blog can use in moodle, Forums can use for focus currently studying topic.
  • Through the Lesson activitylearners can select their own way, and as per previous performance Conditional Activities direct your class to different content.
  • You can create a Quiz, to tech students.
  • Assignment activity provides a space into which students can submit their work for teacher and get feedback from it.
  • By Activity completion teachers can mark who completed the works behalf of students by clicking into the relevant completion boxes.
  • Badges are achievement and showing progress of students.
  • By YouTube repository allows users easily to embed videos from YouTube online site.
  • We can create storage for online text books and share Powerpoints and Weblinks.

For more information about Moodle visit the link: https://docs.moodle.org/39/en/Main_page

  1. What is new in Moodle 3.9
  2. Get Started
  3. Manage your course
  4. Manage you site
  5. Add Activities
  6. Moodle App

Moodle Installation Guide for Installing on Amazon EC2

This installation guide is not using any Amazon AMI for moodle installation. Amazon has their own Machine Images for Moodle but we are installing this Moodle from beginning installing EC2 Instance, LAMP stack and Moodle 3.9. This will help us later to make our own AMI’s for future use.

Installing EC2 Instance from Amazon Consol

For this first step we are assuming that you have valid AWS account. Login in to AWS account and select the region from top of the right corner. Where would you like to install Moodle (Learning Management System). Once you have selected the region follow the steps mentioned below:

Step 1: Create VPC (Virtual Private Cloud)

Create VPC
  • Select VPC from Networking & Content Delivery, you can find default VPCs ignore it
  • Select Your VPCs from left panel, don’t select Launch VPC Wizard from Top of the panel
  • Select Create VPC from top of the panel
  • Name tag: MoodleVPC and IPv4 CIDR block*: 0.0.0/16
  • Select Create button to create new VPC

Step 2: Create Subnet

create subnet
  • Select Subnets from left panel under VPC category, you can find default subnets ignore it
  • Select Create subnet from top of the panel
  • Name tag: MoodleSubnet
  • VPC: which you have created on Step 1 e.g. MoodleVPC
  • Availability Zone: us-east-1a or whatever AZ is available
  • IPv4 CIDR block*: 0.0.0/24
  • Select Create button to create new Subnet

Step 3: Create Internet Gateway

Create VPC
  • Select Internet Gateways from left panel under VPC category, you can find default subnets ignore it
  • Select Create internet gateway from top of the panel
  • Name tag: Moodle-IG
  • Select Create internet gateway button to create new Internet Gateway
  • Select Actions button, Select Attach to VPC and attached to existing VPC e.g.: MoodleVPC

Step 4: Create Route Table

Route Table
  • Select Route Tables from left panel under VPC category, you can find default route table ignore it
  • Select Create route table from top of the panel
  • Name tag: Moodle-RT
  • VPC: which you have created on Step 1 e.g. MoodleVPC
  • Select Moodle-RT just now you have created and Go to Action select Set Main Route Table
  • Click on Routes Tab below
  • Select Edit Routes and Select Add rout
  • Add Destination: 0.0.0.0/0, Target: Internet gateway (Moodle-IG)
edit routes

Step 5: Create Security Group

security group
  • Under Security, select Security Groups from left panel, you can find default security group ignore it
  • Select Create security group from top of the panel
  • Security group name: Moodle-SG, Description : Moodle-SG, VPC: which you have created on Step 1 e.g. MoodleVPC
  • Select Inbound Rules and Add rules, Type: SSH, Source: My IP and Type: HTTP, Source: Anywhere
  • Select Create security group

Step 6: Installing EC2 Instance for Moodle

Under Compute select EC2

Under EC2 Dashboard select Launch Instance

  • Choose an Amazon Machine Image (AMI)
    1. Select Amazon Linux 2 AMI (HVM), SSD Volume Type - ami-09d95fab7fff3776c (64-bit x86) / ami-02b5d851009884e20 (64-bit Arm)
  • Choose Instance Type
    1. Select Family: General Purpose, Type: t2.micro / free tier eligible
    2. Click on Next: Configure Instance Details
  • Configure Instance Details
    1. Select Network: which you have created on Step 1 e.g. MoodleVPC
    2. Select Subnet: which you have created on Step 2 e.g. MoodleSubnet
    3. Auto-assign Public IP: Enable (if Disable you have to attached Elastic IP which will cost you)
    4. Click on Add Storage
  • Add Storage
    1. Do not Add Volume Click on Add Tags
  • Add Tags
    1. Click on Add Tag Key: Name and Value: MoodleInstance
    2. Click on Next: Configure Security Group
  • Configure Security Group
    1. Assign Security Group Select: Select on existing security group, which you have created on Step 5 e.g. Moodle-SG
    2. Click on Review and Launch
  • Review Instance Launch
    1. Review and Make sure everything perfect, Click on Launch
  • Select an existing key pair or create a new key pair
    1. Select: Create new key pair
    2. Key pair Name: Moodlekey
    3. Select: Download Key Pair (Do not lose it!! we will need it later for SSH connection to EC2)

Well Done!!

You have created EC2 instance for Moodle. Next step we will install LAMP on top of EC2 instance and Moodle version 3.9 App.

Installing LAMP Stack from CLI

Please note LAMP stands for Linux, Apache, MySQL, and PHP. Using LAMP Stack we can develop high performance web sites. But in this tutorial we are not going to install Linux (OS) because we have installed Linux (OS) through AWS consol which is t2.micro / free tier eligible.

Follow the steps below to connect EC2 instance via SSH (Secure Socket Shell) and later we are going to install Moodle. I am using Linux Centos7 Terminal for this Installation Guide.

Step 1: SSH via CLI (Command Line Interface)

  • Make sure you have .pem file with your hand which is you have downloaded e.g. pem
  • Select your EC2 instance and from bottom panel copy IPv4 Public IP to clipboard e.g. Public IP
  • Go to Terminal and change directory ( cd /Documents/) where you have stored your Key file e.g. pem
  • Give the user read permission only:
    1. Type command > chmod 400 filename (Moodlekey)
  • Connecting to Amazon EC2 instance using above key file
    1. Type command > ssh ec2-user@IPv4 Public IP (which you have copy to clipboard) -i Moodlekey.pem
    2. Type yes
    3. cat /etc/system-release (you should get the display: “Amazon Linux AMI release 2018.03”)
    4. Now you have connected to EC2 instance securely

Step 2: Install a LAMP Web Server with the Amazon Linux AMI

We are installing year 2020 Moodle 3.9 version and requirements are atleast MySQL 5.7, Apache Server 2.4 and PHP 7.2 above.

  • Change privilege to root user> sudo su (if prompt for password then enter it)
  • Update application installed on the system > yum update -y (-y option will not ask you the permission for update, it will update every currently installed package on the system)
  • yum install httpd24 php72 mysql57 mysql57-server php72-mysqlnd -y
  • yum list installed httpd24 mysql57-server php72 php72-mysqlnd (listing installed packages)
lamp web server
  • service httpd status (checks server status: running/stop)
  • service mysqld status (checks server status: running/stop)
  • chkconfig --list httpd (check run levels)
  • service httpd start (start the Apache server)
  • service mysql start (start the MySQL server)
  • chkconfig httpd on (Apache web server to start at each time system re-boot)
  • chkconfig mysqld on (MySQL server to start at each time system re-boot)

At this stage your Apache server is installed, you can check by browsing public ip on browser e.g. copy Public IP from EC2 instance and Paste on MS Edge/Google Chrome, you can view “Amazon Linux AMI Test Page

amazon linux AMI Test Page

/var/www/html is Linux Apache Document root. This test page will not appears if there is any content in /var/www/html.

At this stage PHP, MySQL and Apache Server are installed and running.

Step 3: Configure full UTF-8 support

Edit your MySQL configuration file on Linux directory /etc/my.cnf  or /etc/mysql/my.cnf

  • cd /etc/
  • vim my.cnf

Add the following mentioned lines exactly (case sensitive) to the configuration file: Press i for insert mode

[client]

default-character-set = utf8mb4

 

[mysqld]

innodb_file_format = Barracuda

innodb_file_per_table = 1

innodb_large_prefix = 1

character-set-server = utf8mb4

collation-server = utf8mb4_unicode_ci

skip-character-set-client-handshake

 

[mysql]

default-character-set = utf8mb4

  • After finish adding lines press esc key and :wq enter key for save file.
  • Restart Apache server and MySQL

Step 4: Create a database

Using your chosen database server, create a new empty database. The default encoding must be UTF8. For example, using MySQL:

  • mysql>CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  • show databases; (you can see moodle database just you have created)
database

If you are not familiar with MySQL command, click Here for Basic MySQL commands.

Create a user/password combination with appropriate permissions for the database. For example (MySQL again):

  • mysql>GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP, INDEX, ALTER ON moodle.* TO 'moodleuser'@'localhost' IDENTIFIED BY 'yourpassword';

Please note that you have created database called “moodle”, user “moodleuser” on “localhost” and password is “P@ssword2020” (do not forget to replace IDENTIFIED BY ‘yourpassword’ to P@ssword2020).

Step 5: Create a Directory for Moodledata

Now we are going to Create one Directory called moodledata in /var/www/. Directory should have allowed Write permission for Web Server User or 'Everyone'.

  • sudo su (change root user)
  • cd /var/www/
  • mkdir moodledata
  • chown apache:apache moodledata

Step 6: Download Moodle 3.9

Pull the code from the Git repository

  • cd /var/www/html (you are must be in this directory)
  • yum install git -y
  • git clone -b MOODLE_39_STABLE git://git.moodle.org/moodle.git
gir moodle

Moodle is downloaded to /var/www/html/moodle directory and ready for installation.

Step 7: Installing Moodle Version 3.9 

Run any available browser with and insert Public ip/moodle run Installation e.g. 100.26.22.149/moodle. Moodle will take you to Installation window:

installing moodle

Click Next button

Make sure Confirm paths are correct and directories are available and Click Next button.

confirm paths
database

Select your database type (for this guide/tutorial we have create MySQL database type). Select and Click on Next button.

Moodle configuration complete, then create config.php file and copy/past below code into config.php and save it.

installation
  • vimphp (create new file)
  • Copy and Paste above PHP configuration code
  • Press ESC key and
  • :wq (Save file)
  • service httpd restart (restart Apache server)
installation moodle

Click Continue

Below mentioned PHP extensions are required or recommended for Moodle installation. You might get error next display.

  • The iconvextension is required.
  • The curlextension is required (required for networking and web services).
  • The opensslextension is recommended (required for networking and web services).
  • The tokenizerextension is recommended.
  • The zipextension is required.
  • The simplexmlextension is required.
  • The splextension is required.
  • The pcreextension is required.
  • The domextension is required.
  • The xmlextension is required.
  • The jsonextension is required.
  • The xmlrpcextension is recommended (required for networking and web services).
  • The soapextension is recommended (required for web services).
  • The ctypeextension is required.
  • The mbstringextension is recommended.
  • The gdextension is recommended (required for manipulating images).
  • The intlextension is recommended.
  • php -i (for more information about PHP)
install

If installation is showing error and telling us must be installed then:

  • yum clean all
  • yum install “Packages Name” -y (e.g. yum install php72-gd php72-mbstring)
  • service httpd restart
  • After completed the installation click below “Reload” and Continue.
form
forms

Configure Main Administrator account by filling form above.

Setup your front page and Save changes.

install
front page setting
site registration

Finally you can register your Moodle site or you can skip this time and register later. Skip button is available at the below left corner.

Well Done!!

You have completed installing Moodle and setting up your site. Now you can browse your site by: Your Public IP/moodle in any type of browser. e.g. 3.236.70.9/moodle

Pralad is highly motivated IT professional with experience in system administration and design, deployments, migrations and operations. He has over eight years of experience in the industry. Over the period, he has gained significant amount of knowledge and experience in various industry leading technologies including but not limited to AWS, Microsoft Windows, Linux and VMware.

Pralad Bista

Systems Administrator/Engineer

Get connected with Pralad :

1 Comment

  1. James Steele

    I followed your steps and everything went perfectly well until it was time to log into the Instance using SSH. I’m using macOS Big Sur Terminal. Your login command was slightly different from the one provided in the EC2 console for SSH connection. However, I tried their example and yours and I can’t login. It keeps timing out.

    Using yours: ssh ec2-user@52.41.251.110 -i Moodlekey.pem
    Using theirs: ssh -i “Moodlekey.pem” ec2-user@52.41.251.110

    I’ve checked the ports on Moodle-SG and my IP is set for SSH on port 22. Everything else is fine. I do see one anomaly that has me scratching my head. On the EC2 Instance dashboard I have other servers running. They all have a Public IPv4 DNS and an Elastic IP. But my newly created Moodle Instance does not. these fields are blank. I’m guessing here, but is this the reason I cannot access via SSH?

    I really want to complete this exercise and your advice would be sincerely appreciated. Thank you!

    Reply

Submit a Comment

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

Related Articles