SUBSCRIBE

How To Install Moodle™ On Amazon — AWS Guide, Part Three

How To Install Moodle On Amazon — 2019 AWS Guide
AI in Education Leaderboard Post Page
Ai In Education Square Post Page

--- Advertisement ---

«Hello, Moodle™!» — The World.

View Part One here: Pre-start Inventory, the AWS Console, Launching a Linux Ubuntu (EC2) instance

Part Two: Terminal-AWS Connection using SSH, Setting Up LAMP

The final intro

Note from the future: It is recommended that you always install the latest stable version of Moodle™. Go here to verify the latest stable release, and the compatible versions of the required technologies.

At this point, you should be able to handily connect to the tiny piece of AWS cloud that is entirely yours using PuTTY anytime you want.

Your instance has all the supporting systems, known in the business as LAMP: Linux (Ubuntu Server), Apache HTTP Server, MySQL and PHP, all updated to their latest versions and connected through libraries or “mods.” The LAMP set up will help you support any kind of web application, even mobile apps.

For now, it’s finally time to launch Moodle™.

In case you get stuck, feel free to look up any errors online. Also, remember the basic Linux shell commands that might help get back on track quickly:

  • sudo apt-get update at the start of a new session
  • sudo apt-get service apache2 restart after installing any new program or after a major modification in the system
  • pwd, cd and ls -l for orientation and navigating the file structure
  • New! cp current_file new_file will create copies of files. Useful method to create backups of system files you need to edit, in case something goes horribly wrong

Uploading the Moodle™ files to your AWS EC2 instance

Get the latest “tarball” (moodlepackage.tgz) by copying the link in the blue “Download tgz” button from the latest official or stable update of Moodle™.

The ‘wget’ way (might not always work)

From the terminal, type wget and one of the addresses above.

If everything went smoothly, you are ready to ‘Exploxe’ the file. See next sectionl.

For Linux and Mac users

From your terminal, before logged into the instance, the following command should work.

scp -i key.pem moodlepackage.tgz ubuntu@ec2-some-random-numbers.server-location-maybe.compute.amazonaws.com:/home/ubuntu

Visit Part Two to get your PEM key (key.pem) and the Address of Your Instance (ec2-some-random-numbers.server-location-maybe.compute.amazonaws.com, “Public DNS (IPv4)” in the console.

For Windows

Install FileZilla and use it to connect to your instance.

On the main menu, go to Edit Settings…

On the Select page navigation tree at the left, go to ConnectionSFTP, then on the Public Key Authentication view, click on Add key file… to upload the PEM key.

Once you see it listed on the Private keys list, click OK .

Go to FileSite Manager… (or Ctrl + S) and fill out the following fields.

On the General tab:

  • Protocol: SFTP – SSH File Transfer Protocol
  • Host: Address of Your Instance or “IPv4 Public IP”
  • Logon Type: Normal
  • Username: ubuntu

Leave all else unchanged. Click Connect .

How To Install Moodle™ On Amazon — AWS Guide, Part Three
If the process went right, you will see a window like this one and a “successful” status on top of the directories.

Successfully connected, you now have two parallel views. On your right it’s the EC2 instance (Remote site). Make sure you are in /home/ubuntu .

On your right, your home computer (Local site). Find the Moodle™ tarball on your files and just drag it onto the /home/ubuntu remote window. The process could take a few minutes depending on your bandwidth.

How To Install Moodle™ On Amazon — AWS Guide, Part Three
Moodle™ tarball successfully transferred through SFTP into the EC2 Ubuntu Server.

When you see the Moodle™ tarball on the Remote file directory, it means FileZilla has done its job. You can close it. (Closing the program will close the connection.)

‘Explode,’ serve, build Moodle™

From tarball to Moodle™ directory

Log to your EC2 instance from the terminal. You can use ls -l to verify the Moodle™ tarball is installed.

“Explode” is to a tarball what unpack or uncompress is to a ZIP file.

So go ahead and “explode” the Moodle™ tarball to create the Moodle™ file directory in the system:

tar -xvf moodlepackage.tgz

Telling Apache to serve Moodle™ per user request

Find a file named 000-default.conf . It should be on the /etc/apache2/sites-available directory, which you can access using cd . You will be editing the CONF file, which among other things indicates to the Apache server the location of the files that the Moodle™ application needs to work for the user. So it’s not a bad idea to make a backup. To modify it, you can use the “GNU nano” editor which is available straight from the terminal.

Here’s how the instructions from the previous paragraph should look like:

cd ..
cd ..
cd /etc/apache2/sites-available/
cp 000-default.conf 000-default.conf.backup
sudo nano 000-default.conf

The input of which should take you to the nano editor:

How To Install Moodle™ On Amazon — AWS Guide, Part Three

Replace the line starting with DocumentRoot with the following:

 DocumentRoot /home/ubuntu/moodle

Save the edit (Ctrl + O) and exit nano (Ctrl + X).

You have successfully told Apache where to find the Moodle™ files. When a user enters the address on their browser, Apache gets it and understands the action as a request to serve them the Moodle™ application.

Feel free to restart Apache at this point.

You must also indicate Apache which files users can access from the web. Do so by navigating to the /etc/apache2/ file to find apache2.conf . By including the Moodle™ directory and removing access to anything not needed by users, you protect the rest of the system.

Apache’s potentially fascinating security model exceeds the scope of this guide. For now, replace the only instance of /var/www/ in the document for /home/ubuntu/moodle .

Assuming we started from a random directory, it all should look like something like this:

cd
cd /etc/apache2
sudo nano apache2.conf

Inside the nano editor, the replacement should look like this:

How To Install Moodle™ On Amazon — AWS Guide, Part Three

Save the edit (Ctrl + O) and exit nano (Ctrl + X). Restart the Apache server.

Prepare the database

This step creates an empty database and creates an editing role. You will provide the credentials of the role to the Moodle™ application, so it can build the database and add the data.

Enter the MySQL editing environment with high-level admin permissions by typing on the terminal:

sudo mysql -uroot -pPassword@123

Create a database for Moodle™. You can choose a database name, username and user password of your choosing. Here we will use:

  • Database name: moodleDB
  • Username: moodleuser
  • Password: Password@1234

Proceed by typing:

create database moodleDB;
grant all on moodleDB.* to moodleuser@`localhost` identified by "Password@1234";
flush privileges;
exit
How To Install Moodle™ On Amazon — AWS Guide, Part Three
Creation of empty database and Moodle™ editing role; and “flushing” (reload MySQL) before exiting the MySQL environment.

The moodledata folder

On the /home/ubuntu/ directory, create a folder:

mkdir moodledata
sudo chmod 777 moodledata -R
sudo crontab -e

A final Apache restart would not hurt.

Apart from creating the moodledata folder, it gives all types of Linux users full reading, writing and execution access of everything inside the folder through the chmod 777 command. Finally, the crontab command activates cron, a server utility that runs scheduled tasks automatically.

At last: Install Moodle™

Launch Moodle™ on your browser by entering the Address of Your Instance or the IP on the address bar. It should launch an installation walk-through for Moodle™.

You can more or less follow the screen intuitively, keeping in mind some of the information created during this process:

  • Language: You can edit or add additional languages later on
  • Data directory: The location of the /moodledata folder
  • Database driver: There are many, but you installed MySQL this time so choose “Improved MySQL”
  • Database host: localhost
  • Database name, username and password: Those created during the MySQL setup stage
  • Create a “master admin” role. Keep the username and password safe but within reach. Moodle™ encrypts this data, so if you lose the info at this point, the site becomes unusable.
  • Other fields are better left as they appear, either empty or unmodified.

If all goes well, the installation will be complete when a list of utilities appears with a green “OK” next to each item.

How To Install Moodle™ On Amazon — AWS Guide, Part Three

Success! Your blank state Moodle™ would look something like this:

How To Install Moodle™ On Amazon — AWS Guide, Part Three

More resources and troubleshooting

  • Google ChatGPT is your friend. Look up every error, warning, or just any command you feel curious about.
  • In most cases, thought, Moodle™-related info will take you to the Moodle™ Docs and MoodleDev, so you might as well get acquainted with it.
  • We would love to know your thoughts about this guide. Please let us know of errors, parts unclear or ideas on how to make this better. Upcoming tutorial ideas would also be great and taken to heart.

8 Responses

  1. Hi

    Thanks for your guide.

    I get the following error when trying to access my instane
    http://x.xx.xxx.xx/install.php
    Fatal error: Cannot use ‘object’ as class name as it is reserved in /home/moodle/lib/setuplib.php on line 79

    Any ideas on how to proceed?

  2. Hi

    Thanks for your guide.

    I get the following error when trying to access my instance
    http://x.xx.xxx.xx/install.php
    Fatal error: Cannot use ‘object’ as class name as it is reserved in /home/moodle/lib/setuplib.php on line 79

    Any ideas on how to proceed?

  3. Hi Nicholas,

    Can you confirm the following:
    1. Which version of Moodle are you installing, and which version of PHP and Ubuntu do you have?
    2. Did you not get any errors up until this point?

    Let me know and we can explore some alternatives. Thank you for your message,

  4. Hi Nick, seems it is definitely a compatibility issue between your PHP and Moodle versions.
    Please note that Moodle 4.2 is no longer being supported. The latest version of Moodle should support PHP 8.2.x

    You could also downgrade to PHP 7 to resolve the reserved words issue, but this is not ideal.

  5. Thank you.

    I finally got around to re-trying the install with the latest moodle package and only had the following errors in mysql during install:

    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘identified by “Password@1234”
    flush priveleges
    exit’ at line 2

    currently the instance is serving:

    Forbidden
    You don’t have permission to access this resource.

    Apache/2.4.58 (Ubuntu) Server at 54.206.99.176 Port 80

    Thank you for your help so far. Any further advice appreciated.

    All the best

  6. Hi Nick,

    It appears the syntax has changed slightly. I haven’t used MySQL 8.x, but you may want to try this instead:

    CREATE DATABASE moodleDB;
    CREATE USER ‘moodleuser’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘Password@1234’;
    GRANT ALL PRIVILEGES ON moodleDB.* TO ‘moodleuser’@’localhost’;
    FLUSH PRIVILEGES;
    EXIT;

    Let me know how it goes!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

The Latest

The eLearn Podcast

--- Advertisement ---

Subscribe to our newsletter

Education technology has the power to change lives. 

To get the latest news, information and resources about online learning from around the world by clicking on the button below.