«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
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 updateat the start of a new session
sudo apt-get service apache2 restartafter installing any new program or after a major modification in the system
ls -lfor orientation and navigating the file structure
cp current_file new_filewill 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 Moodle “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 email@example.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.
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 Connection → SFTP, 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 File → Site 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 .
Successfully connected, you now have two parallel views. On your right it’s the EC2 instance (Remote site). Make sure you are in
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.
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.
Keeping that in mind, 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:
Replace the line starting with
DocumentRoot with the following:
Save the edit (Ctrl + O) and exit nano (Ctrl + X).
You have successfully told Apache where ti 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
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:
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:
Proceed by typing:
create database moodleDB; grant all on moodleDB.* to moodleuser@`localhost` identified by "Password@1234"; flush privileges; exit
/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
- Database driver: There are many, but you installed MySQL this time so choose “Improved MySQL”
- Database host:
- 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.
Success! Your blank state Moodle would look something like this:
More resources and troubleshooting
- Google 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 (docs.moodle.org), 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.