How to install Moodle on Ubuntu 16.04

Moodle is a popular open source web-based learning management system (LMS) that is free for everyone, both to install and to use. With Moodle, you can create and provide educational resources such as courses, readings, and discussion groups for students. Moodle also lets you manage user roles, so students and teachers can have different levels of access to content. Once Moodle is installed on your web server, anyone with access to the site can create and participate in a browser based learning process.

In this tutorial, we will install and configure Moodle on an Ubuntu 16.04 server. You will install and configure all the software required for Moodle, launch with the setup wizard, choose a theme, and create your first course.

Prerequisites

Before starting this tutorial, you need the following:

  • 16.04 1GB Ubuntu server with a minimum of 200MB of disk space for Moodle code and as much as needed to store content. Moodle requires 512MB of RAM, but recommends at least 1GB for best performance.
  • A non-rooted user with Sudo privileges and a firewall that can be configured by following the initial Ubuntu 16.04 initial server setup guide.
  • Install LAMP stack (Apache, MySQL and PHP) by following this tutorial. Be sure to write down the MySQL root password that you set during this process.

Step 1 – Installing Moodle and Dependencies

Moodle relies on several pieces of software, including spellcheck libraries and charting libraries. Moodle is a PHP application and it has several additional PHP library dependencies. Before installing Moodle, let’s install all the pre-release libraries using the package manager. First, make sure you have the latest package list:

sudo apt-get update

Then install the Moodle dependencies:

sudo apt-get install aspell graphviz php7.0-curl php7.0-gd php7.0-intl php7.0-ldap php7.0-mysql php7.0-pspell php7.0-xml php7.0-xmlrpc php7.0-zip

Then restart the Apache web server to load the modules you just installed:

sudo systemctl restart apache2

We are now ready to download and install Moodle itself. We will use curl to download Moodle from the official server.

The following command will go to the Moodle website and get an archive package containing the stable version of Moodle in a file moodle.tgz… The -L flag says curl follow forwarding.

curl -L https://download.moodle.org/download.php/direct/stable32/moodle-latest-32.tgz > moodle.tgz

Now we can unpack the file tar with the program and place the resulting files in the root directory of web documents:

sudo tar -xvzf moodle.tgz -C /var/www/html

Make sure the directory moodle located in the web root directory of your server:

ls /var/www/html

You should see the directory moodle in the list:

Output

index.html  moodle

Now let’s look at the files in the directory moodle:

ls /var/www/html/moodle

You will see all the Moodle files and directories you just downloaded:

Output

admin           composer.json     grade          message                    README.txt
auth            composer.lock     group          mnet                       report
availability    config-dist.php   Gruntfile.js   mod                        repository
backup          config.php        help_ajax.php  my                         rss
badges          CONTRIBUTING.txt  help.php       notes                      search
behat.yml.dist  COPYING.txt       index.php      npm-shrinkwrap.json        tag
blocks          course            install        package.json               tags.txt
blog            dataformat        install.php    phpunit.xml.dist           theme
brokenfile.php  draftfile.php     INSTALL.txt    pix                        TRADEMARK.txt
cache           enrol             iplookup       plagiarism                 user
calendar        error             lang           pluginfile.php             userpix
cohort          file.php          lib            portfolio                  version.php
comment         files             local          PULL_REQUEST_TEMPLATE.txt  webservice
competency      filter            login          question
completion      githash.php       media          rating

Now we need to create a directory outside the web root for Moodle to store all course-related data, which will be stored on the server, not in the database. It is more secure to create this directory outside of the web root so that it cannot be accessed directly from the browser.

Run the following command:

sudo mkdir /var/moodledata

Then set its property to make sure the user of the web service www-data can access the directory:

sudo chown -R www-data /var/moodledata

Then change the folder permissions so that only the owner has full access rights:

sudo chmod -R 0770 /var/moodledata

Now that you have Moodle on your server, it’s time to set up the database it will use.

Step 2 – Configuring the Database

We need to create a MySQL database where Moodle will store most of its data. We will create a structure that expects the Moodle code, and we will create a user that will use Moodle to connect to the database.

But first, we need to make a few changes to the MySQL configuration file in order for our MySQL installation to be Moodle compatible. Open the MySQL configuration file:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Then add the following highlighted lines in the “Basic Settings” area, which will configure the storage type new databases should be used:

Mysqld configuration

...
[mysqld]
#
# * Basic Settings
#
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
default_storage_engine = innodb
innodb_file_per_table = 1
innodb_file_format = Barracuda
## Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
...

Save this file and then restart the MySQL server to reload the configuration with the new parameters.

sudo systemctl restart mysql

We can now create a Moodle database. In order to do this, you will interact with the MySQL command line interface. Run the following command:

mysql -u root -p

When prompted, enter the root password that you set when installing MySQL.

After logging in, you will see a prompt mysql>… Run the following command to create the database:

CREATE DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Then create a Moodle user, we don’t have to tell the Moodle app that our password is the superuser. Run the following command:

Note: In the next two commands, replace moodler with your username and Moodle moodlerpassword with your chosen password.

create user 'moodler'@'localhost' IDENTIFIED BY 'moodlerpassword';

And give moodler allowing the user to edit the database. This user will have to create tables and change permissions:

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO 'moodler'@'localhost' IDENTIFIED BY 'moodlerpassword';

Now, exit the MySQL CLI:

quit;

This takes care of the database configuration. We can now launch Moodle in a browser and continue with the installation there.

Step 3 – Configuring Moodle in the Browser

To complete the Moodle setup, we will go to the site in a web browser and provide it with some additional configuration details. In order for the web server to save the configuration, you need to temporarily change the permission to the Moodle web root.

Note: Permissions will open this folder to everyone. If you are new to this, just don’t change the resolution. The web interface will provide instructions for you to manually modify the configuration file.

If you change the permissions, it is very important to undo this once you have finished installing. This step is included in this tutorial.

sudo chmod -R 777 /var/www/html/moodle

Now open your browser and go. You will see the following page http://your_server_ip/moodle

Follow these steps to set up Moodle:

  1. Set the language you want to use and click the button Further
  2. On the next screen, set data directory on /var/moodledata and press the button Further
  3. On the page Choose Database Driver, install database driver on Improved MySQL (native Mysqli) … Then press the button Further
  4. On the page database settings, enter the username and password for the MySQL Moodle user you created in step 3. You can leave the rest of the fields as they are. Click Further to continue.
  5. Read the license agreement and confirm that you agree to its terms by clicking the button Proceed.
  6. Browse the page Server Checks for any possible problems. Make sure the message “Your server environment meets all the minimum requirements” exists at the bottom and click Proceed.
  7. Moodle will install several components displaying a “Success” message for each one. Go to the bottom and press Proceed.
  8. After that, you will see a page where you can set up an administrator account for Moodle.
    1. For Username enter whatever you want or accept the defaults.
    2. For Choose an authentication method, leave the default in place.
    3. For getting new password enter the password you want to use.
    4. For getting Email, enter your email address.
    5. Set the rest of the fields to the appropriate values.
    6. Click Update profile
  9. On first page Settings screen, fill Full site name ,short name for the site, set a location, and choose if you want to enable Self Check-In via email. Then press the button Save changes.

Once you have done this, you will be taken to the dashboard of a fresh Moodle installation, you are logged in as administrator

Now that your installation is complete, it is important to restrict access to the Moodle web root again. Go back in your terminal, run the following command:

sudo chmod -R 0755 /var/www/html/moodle

Let’s make one more small change to make Moodle more secure. By default, Moodle creates files in the folder /var/moodledata with world-writeable permissions. Let’s change by changing the default resolution that Moodle uses.

Open the Moodle config file in an editor:

sudo nano /var/www/html/moodle/config.php

Find the following line:

config.php

$CFG->directorypermissions = 0777;

Change it to the following:

config.php

$CFG->directorypermissions = 0770;

Then save the file and exit the editor.

And finally, reset the permissions on the directory itself /var/moodledataas Moodle already created several folders during the installation process:

sudo chmod -R 0770 /var/moodledata

Now that Moodle is set up, let’s make a few tweaks and create a test course to get a theme for the Moodle web interface.

Step 4 – Setting Up Moodle and Creating Your First Course

Now that your site is up and running, one of the first things you want to do is register your Moodle site. This will allow you to subscribe to the Moodle mailing list, which will keep you updated on things like security alerts and new releases.

To register, click the link Site administration in the box on the left and click on registration… Then fill out the web form with the relevant details. You can also publish your Moodle site for others to find.

Next, let’s change the theme for our Moodle site. Please select Site administration, select the tab Appearance and select Theme selector… You will see a page that looks like the image below, showing that you are currently using the theme on default which links to a modern web browser:

Theme screen selection

Click the button Change the topicand you will be taken to a screen that shows you the other available themes. By pressing the button Use theme under a theme name, your Moodle site will use that theme to show all of your site’s content. You can also choose different themes for different devices such as touchpads or phones.

Now that you have your Moodle site, you will want to create your first course. Please select Site home in the navigation menu. You will see an empty list of courses and a button add a new course… Click on this button to display a form that looks like the image below:

Create Course screen

Fill out your course information, including name, short name, description, and any other relevant details. Then scroll down and click Save and display

Your first Moodle course is now ready to go. You can start adding lessons and activities while using the Moodle interface.

But before you start letting people sign up to take your new course, you need to make sure your Moodle installation is ready to go. First, you’ll want to create a TSL / SSL certificate for Apache to encrypt traffic between the server and clients. And to make sure your data is protected, make sure you back up your MySQL database periodically. You must also back up your files on the server, including the folder /var/moodledata/

Output

In this tutorial, you have installed and configured Moodle on an Ubuntu 16.04 server. Moodle is a robust and highly customizable web application. Be sure to consult the Moodle documentation and get in touch with the global community of Moodle users and administrators for ideas on how to make the most of it. Good luck with Moodle!

How to install Moodle on Ubuntu 16.04

Sidebar