
Deploying Moodle on AWS: the easiest... WAY
Deploying the learning management system that's Moodle to AWS lightsail!
As security measure, I advise you that at the end of today's episode, you shutdown everything!!!
Most school nowadays use e-learning at one point or another, as a matter of fact even where I did my Bachelor Degree (ICT University, no pub though) we were extensively using e-learning as a tool to boost traditional ways of teaching. At the epicenter of it lies what we called Learning Management Systems or LMS for short and today we will be looking at one of them : MOODLE or Modular Object-Oriented Dynamic Learning Environment , which is a popular LMS if not the most popular one and has been translated into over 100 different languages and is accessible in many countries worldwide.[30]

MOODLE Image
Here are just some key points about this particular lms:
- Institutions can add as many Moodle servers as needed without having to pay license fees.
- Moodle has over 50% market share in Europe, Latin America, and Oceania
- Moodle runs without modification on Unix , Linux , FreeBSD , Windows , MacOS and any other systems that support PHP and a database, including web host providers.
- Moodle is Open Source, a Wide Community of Developers, building amazing stuff on top of it or as addons
But let me not bore you with the numbers and let's go straigth to it.
Moodle is a learning platform used to augment and move existing learning environments online, that's it.
Note : The first version of Moodle was released on 20 August 2002 (24 years ago), and it continues to be actively developed
So to deploy our LMS, we will use AWS, more specifically AWS Lightsail, very light both in terms of knowledge required to deploy applications (writeen in the major PL and frameworks out there) and also in terms of pricing (basically you get roughly 2-3 months free before getting charged).

AWS Console Search
So head over to your console and search for "AWS lightsail", the first result is the correct one, pick it!
Wait for the main dashboard to load...

AWS lightsail Dashboard
After that if this is your first time, you won't see any instance, only the "create" button, so we will click on it to create our first instance.

AWS lightsail Create Form
On this page you can set settings such as :
- The location of your instance, just as with any AWS service, some featuresmight not be available on every regions, so always check the documentation .
- The host platform of your application, personally I will always go with Linux/Unix unless you really have something specific to do with a Windows server.
- Finally you get to select a Blueprint, think of it as a pre-packaged environment that's **production ready and adapted to your particular framework (**PHP Stack, Python , JS etc..)

AWS lightsail SSH Key
Next on the list we get to configure : a launch script, which basically is some configurations you will want to setup as soon as your instance launches , like updating and upgrading packages to their latest versions.
Next is something that's not optional, hence really really IMPORTANT!
Without it you won't have access to your server so let's see what exactly it's.
Now now now, what's that ssh key, and why is it so important? Too put it simple SSH is what will enable you to have full control over the Linux server we are creating all that via your local PC and from a terminal .
Now it uses the principle of Public/Private keys, more on it on this Reddit tread . So download the key to your local machine, just for precaution download it twice because that's the only chance you will get to do so.

AWS Lightsail SSH Keys - select region
Now give it a name

AWS Lightsail SSH Keys
Ok now on the next screen you should be prompted to download the key, as I said download it even twice!!

AWS Lightsail SSH Key Created
Okay, now your key pair has been created, and hopefully you have downloaded it, we can move to the next step :).

AWS Lightsail Instance Size
Take the one for 5bucks ಠ⌣ಠ, cheap and perfect for our usecase!
The only thing left now is to give a descriptive name to your instance and leave the rest as it's then click on the create button:

AWS Lightsail Create Instance
Congrats, you just created your first lightsail Instance!!!!!!!!!!!!

AWS Lightsail Instance Starting
Voilà, just by doing that you will get an IP address just like mine (18.175.137.214),

Application Accessible via Public IP Address
Now we can connect to the back office of our application via 2 different but similar methods ◔ᴗ◔**:**
- Via Browser based SSH, directly offer to us by AWS and directly connected to our server, fully working on our machine
- Old School way of doing, that's opening a local terminal and using the downloaded key-pair to connect to the remote server.
We will go with option 1, as it's the most convenient for our usecase, but you are free to explore option 2!
So just click on the button and you should see a new window opening...

Connect Via SSH
And there you have your Linux terminal:

AWS Linux Terminal via Browser
So to install our moodle instance here are the few steps to follow
- Clone Source Code from GitHub
- Do the necessary database configurations
- Connect Database to moodle and launch installation
- Set up Cron Jobs
Before cloning it make sure you are inside the htdocs folder

htdocs Folder
You will see an index.html file, remeber the webpage we saw when visiting the public ip? the content of that page is what is inside index.html. We will place moodle there!
Download Moodle code via github by using the following command to do so :
1
2
3
4
sudo apt-get update && \
sudo git clone git://git.moodle.org/moodle.git && cd moodle && \
sudo git branch --track MOODLE_500_STABLE origin/MOODLE_500_STABLE && \
sudo git checkout MOODLE_500_STABLE && \
The above command will download the moodle code, change directory into the folder moodle then switch to a stable branch of the code (the current latest version is 501, but we will use 500 here).
After installing moodle we need to create a data directory, acording to moodle's documentation, that particular directory shouldn't be accessible via the webserver, so shouldn't be served to users: for that reason, we will move the moodledata to a new folder
/var/moodledata.
opt folder for moodle and var folder for moodle data
Now we got moodle, let's work on the database.
For this article we will have our database directly on the server, but depending on your situation and needs you might want external database, no problem the process is exactly the same and AWS Lightsail proposes database instance too.
So far so good, let's now create a specific user just for moodle and connect it to our application.
Access Your Database Credentials
1
sudo cat /home/bitnami/bitnami_credentialsAnd then take the password you will see, and run the following command to connect to the SQL Shell!
1
mysql -u root -pYou will be prompted to enter the password you got previously, next we will create a dedicated user for the moodle application and give him full access to the database:
1
2
3
4
5
CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON moodle.* TO 'moodleuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Custom User Created
Next we need to move moodle to the
htdocs folder
Moving Moodle To htdocs
After doing that, you can visit
http://<your_ip>/intall.php and you should see a screen like this 
Moodle Installation Page
Congratulations, we just did it!, we install Moodle on AWS Lightsail.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article