How to install and configure Moodle LMS with AWS Lightsail and Ubuntu 18.04
How to install and configure Moodle LMS with AWS Lightsail and Ubuntu 18.04
This article shows you how to install and configure a Moodle LMS instance on Amazon Lightsail. It contains steps to complete launch AWS Lightsail, install Moodle and configure your first course.
In this article we will do the following:
- Launch AWS Lightsail with Ubuntu 18.04 onboard
- Install Required Software
- Install Moodle LMS
STEP 1: Launch and configure your instance with Amazon Lightsail and Ubuntu 18.04.
There is no need to explain in detail how to launch the AWS LightSail instance because there is a complete guide on how to do this, which can be found at the end of this step.
!IMPORTANT NOTE You need to choose “OS Only” and “Ubuntu 18.04” like on the screen below instead of the option you’ll see in the guide.
We will install all required software including PHP 7 by ourselves. That’s why we need just the latest version of the operating system and nothing more.
This step is very important because the latest Moodle version is not compatible with PHP 5.
Link to guide:
STEP 2: Install Required Software
2.1: Install Apache/MySQL/PHP
sudo apt-get install git-core
Installing php 7.2 with extra modules
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
Installing Apache and extra modules
sudo apt-get install apache2 php7.2 libapache2-mod-php7.2 sudo apt-get install graphviz aspell ghostscript clamav php7.2-pspell php7.2-curl php7.2-gd php7.2-intl php7.2-mysql php7.2-xml php7.2-xmlrpc php7.2-ldap php7.2-zip php7.2-soap php7.2-mbstring
Restarting apache web-server
sudo service apache2 restart
2.2: Setup MySQL Server
Before you start reading this section, please be aware that there is an alternative Option 2.2 at the bottom, where we show how to install MariaDB instead of MySQL
sudo apt-get install mysql-client mysql-server
Changing mysql config file
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
This command shall open mysqld.cnf in the nano editor, which is installed by default in Ubuntu 18.04. You can use any other editor i.e vim, but in this tutorial, we are using nano.
Add the following lines in your config file.
default_storage_engine = innodb innodb_file_per_table = 1 innodb_file_format = Barracuda
To save the file press CRT + O and then ENTER. Then CTR + X to exit nano.
In the end, my file looks like this:
Now restart MySQL:
sudo service mysql restart
Now we secure our installation
After this command, you shall go throw a few steps where you can reset your password. In the end, you shall see – “All done!” notification.
Step 2.2 [ALTERNATIVE] MariaDB as an alternative to MySQL
Nowadays MariaDB became a very popular open-source solution for database servers. Here you may find the steps how to install it instead of MySQL
Installing MariaDB server and client.
sudo apt-get install mariadb-server mariadb-client
After this, we run a command to set our root password and secure the MariaDB server.
During this command, there will be a chance to set your root password and there will be few prompts, you may type “Y” to all of them
Now we need to open the MariaDB config file and put there some lines:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Now please add the following lines of code just below [mysqld] section.
default_storage_engine = innodb innodb_file_per_table = 1 innodb_file_format = Barracuda innodb_large_prefix = 1
Now, restarting MariaDB
sudo service mariadb restart
Step 2.3 Create Database and User
Connect to MySQL. At this stage, you have to enter your password.
sudo mysql -u root -p
Create a database, user and grant required permissions:
CREATE DATABASE moodledb DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'YourPasswordHere!'; GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodledb.* TO [email protected] IDENTIFIED BY 'YourPasswordHere!'; quit;
!IMPORTANT: You shall use utf8mb4_unicode_ci encoding ( not utf8_unicode_ci ) otherwise you’ll get a yellow notification warning during the installation and some of Moodle functions will not work properly
STEP 3: Install Moodle LMS
In this tutorial, we will install Moodle into www root folder. In many cases, you might prefer to put your local git repository outside the webroot to stage your upgrades efficiently. However, in this example, we will use the webroot folder.
Step 3.1 Take Moodle from Git
cd /var/www/html/ sudo git clone git://git.moodle.org/moodle.git cd moodle sudo git branch --track MOODLE_36_STABLE origin/MOODLE_36_STABLE sudo git checkout MOODLE_36_STABLE
At the time this tutorial has been created, the latest Moodle version is 3.6. This is why we use MOODLE_36_STABLE. However, you can get a list of branches available by using a command:
sudo git branch -a
The latest brach will look like MOODLE_XX_STABLE, where XX shall be the highest number.
Now we will create moodledata folder where all our files and data shall be located in. Then we grant the rights to moodle and moodledata folders.
sudo mkdir /var/moodledata sudo chmod -R 777 /var/moodledata sudo chmod -R 777 /var/www/html/moodle
We grant full permission to moodle folder to run the installer, we will change it later.
Step 3.2 Installation via command line
Installation from the command line is quite easy if you know what to do. First, run the following command.
sudo /usr/bin/php /var/www/html/moodle/admin/cli/install.php
You should get a look like the following:
Follow the prompts and put the values you need.
If you never installed Moodle, then it might be better to you Step 3.2 Alternative – installation via a browser
Step 3.2 [ALTERNATIVE] Installation via browser
Open now the following link in the browser:
You can find INSTANCEIP in your Networking Tab for the LightSail Instance you have created before
Make sure you have attached the Static IP address. If you don’t have it yet, you may click the “Create static IP” button and follow the required steps. Without static IP you’ll get new IP each time you reboot the instance.
Once IP has been changed you have to login via SSH again.
So, go to http://INSTANCEIP/moodle and follow the required steps.
Make sure you enter correct path to your moodledata folder. In our example, it’s /var/moodledata
If you have got the message like this:
That means you forgot to grant full permission to your folders. Ensure you ran the following commands in the past:
sudo chmod -R 777 /var/moodledata sudo chmod -R 777 /var/www/html/moodle
Finally, there should be a confirmation box like this:
“Server checks” should show all green points except “site is not https” yellow point, which can be fixed later by adding an SSL certificate to your instance
Then follow the prompts and enter your username, password, and site name.
Your new instance will look like this:
Now, we have to revert back permissions for the moodle folder.
sudo chmod -R 0755 /var/www/html/moodle
The last important step is a cron configuration. Without it, your system won’t work correctly.
Add the following line and save it.
*/1 * * * * /usr/bin/php /var/www/html/moodle/admin/cli/cron.php >/dev/null
This line will run cron.php script every minute.
How to remove a default Apache2 page?
You need to run a2dissite function and restart apache2 then
sudo a2dissite 000-default.conf sudo systemctl restart apache2
Your Moodle installation is completed now. You can start managing your brand new instance, apply your custom settings, create courses and learning materials.
So you don't need to hurry it take time, hope it may help you, still facing an issue? Ping me back