Create a gist now

Instantly share code, notes, and snippets.

Embed
Setting Up TinCan API with Moodle LMS and Learning Locker LRS in Ubuntu 16.04

#Setting Up TinCan API with Moodle LMS and Learning Locker LRS

#Part 1: Virtual Container

Before we get our hands dirty with the entire setup, it is necessary to ensure we do not mess with the existing installation. Setting up and configuring a local server is tricky and may sometimes break your existing configuration rendering other programs which rely on it useless. So we will use LXC to create a virtual container, where we will do all good stuff. You can read the official LXC documentation here or a brief introduction about LXC here or get started right away with the commands below.

sudo apt-get install lxc lxd-client
sudo lxc-create -t download -n LMSprototype

//It will prompt you to choose a distribution. At the time of making this tutorial, the stable version is Ubuntu Xenial, so I will opt for the same
Distribution: ubuntu
Release: xenial
Architecture: amd64

//Check the existance of container
sudo lxc-ls --fancy

//Launch the LXC container in background
sudo lxc-start -d -n LMSprototype

//Login to LXC container and set password for 'ubuntu' user 
sudo lxc-attach -n LMSprototype
passwd ubuntu
//It will prompt you for a password, choose your desired password

//Login back as ubuntu and enter the password chosen earlier
exit
sudo lxc-console -n LMSprototype
LMSprototype login: ubuntu
Password:

Note: To

  • Exit the LXC console, you can use command Ctrl+a followed by q.
  • Stop the LXC container, you can use command sudo lxc-stop --name LMSprototype.
  • Destroy it permanently, use sudo lxc-destroy --name LMSprototype.
  • Migrate container to another host, refer this tutorial.

#Part 2: Moodle

##Setting up Moodle

Refer the docs at moodle official website to get an overview of the installation process or click here to get the installation steps for Ubuntu 16.04 if you are using Ubuntu just like me. Since we are installing at a local system just for prototyping, we will be taking the simplistic approach and won't be bothering with the requirements needed to setup a production environment.

Note: Since users have reported that Learninglocker gives error with PHP7 [ref], we will be opting for PHP5 to avoid those errors. If you already have PHP7 installed, you can downgrade to PHP5 by following this tutorial.

If you have logged out of the LXC container, login back by typing sudo lxc-console -n LMSprototype.

//Update packages
sudo apt-get update

//Install php, mysql and essential packages
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install vim apache2 mysql-client mysql-server php5.6 libapache2-mod-php5.6 graphviz aspell php5.6-pspell php5.6-curl php5.6-gd php5.6-intl php5.6-mysql php5.6-xml php5.6-xmlrpc php5.6-ldap php5.6-zip git nano
//When prompted, set a root password for mysql

//Restart apache server to load modules correctly
sudo service apache2 restart

//Download  moodle
cd /opt
sudo git clone git://git.moodle.org/moodle.git
cd moodle

//Choose which branch to track (As of writing this tutorial, MOODLE_32 is the most recent stable branch)
sudo git branch -a
sudo git branch --track MOODLE_32_STABLE origin/MOODLE_32_STABLE
sudo git checkout MOODLE_32_STABLE

//Copy local repository and set proper privileges
sudo cp -R /opt/moodle /var/www/
sudo mkdir /var/moodledata
sudo chown -R www-data /var/moodledata
sudo chmod -R 777 /var/moodledata
sudo chmod -R 0755 /var/www/moodle

##Setting Up MySQL server

First we need to change the default storage engine to innodb and change the default file format to Barracuda, this is a new setting compared to previous versions. You also need to set innodb_file_per_table in order for Barracuda to work properly.

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

//Scroll down to the [mysqld] section and under Basic Settings add the following lines under the last statement.
default_storage_engine = innodb
innodb_file_per_table = 1
innodb_file_format = Barracuda

//Restart MySQL server for changes to take effect
sudo service mysql restart

Now we need to create the Moodle database and the Moodle MySQL User with the correct permissions

mysql -u root -p

//Inside MySQL shell
CREATE DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
create user 'moodleuser'@'localhost' IDENTIFIED BY 'moodlepass';
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO moodleuser@localhost IDENTIFIED BY 'moodlepass';
quit;

##Installing Moodle

//Set ownership of moodle path to web user
sudo chown www-data /var/www/moodle

//Install moodle
cd /var/www/moodle/admin/cli
sudo -u www-data /usr/bin/php install.php

Command Line installation steps for reference

abhi9bakshi@pavilion:/var/www/html/moodle/admin/cli$ sudo -u www-data /usr/bin/php install.php
                                 .-..-.       
   _____                         | || |       
  /____/-.---_  .---.  .---.  .-.| || | .---. 
  | |  _   _  |/  _  \/  _  \/  _  || |/  __ \
  * | | | | | || |_| || |_| || |_| || || |___/
    |_| |_| |_|\_____/\_____/\_____||_|\_____)

Moodle 3.2+ (Build: 20161208) command line installation program
-------------------------------------------------------------------------------
== Choose a language ==
en - English (en)
? - Available language packs
type value, press Enter to use default value (en)
: en
-------------------------------------------------------------------------------
== Data directories permission ==
type value, press Enter to use default value (2777)
: 
-------------------------------------------------------------------------------
== Web address ==
type value
: http://localhost/moodle
-------------------------------------------------------------------------------
== Data directory ==
type value, press Enter to use default value (/var/www/html/moodledata)
: /var/moodledata
-------------------------------------------------------------------------------
== Choose database driver ==
 mysqli 
 mariadb 
type value, press Enter to use default value (mysqli)
: mysqli
-------------------------------------------------------------------------------
== Database host ==
type value, press Enter to use default value (localhost)
: 
-------------------------------------------------------------------------------
== Database name ==
type value, press Enter to use default value (moodle)
: 
-------------------------------------------------------------------------------
== Tables prefix ==
type value, press Enter to use default value (mdl_)
: 
-------------------------------------------------------------------------------
== Database port ==
type value, press Enter to use default value ()
: 3306
-------------------------------------------------------------------------------
== Database user ==
type value, press Enter to use default value (root)
: moodleuser
-------------------------------------------------------------------------------
== Database password ==
type value
: moodlepass
-------------------------------------------------------------------------------
== Full site name ==
type value
: LMSprototype
-------------------------------------------------------------------------------
== Short name for site (eg single word) ==
type value
: LMS
-------------------------------------------------------------------------------
== Admin account username ==
type value, press Enter to use default value (admin)
: admin
-------------------------------------------------------------------------------
== New admin user password ==
type value
: admin123
-------------------------------------------------------------------------------
== New admin user email address ==
type value, press Enter to use default value ()
: 
-------------------------------------------------------------------------------
== Upgrade key (leave empty to not set it) ==
type value
: 
-------------------------------------------------------------------------------
== Copyright notice ==
Moodle  - Modular Object-Oriented Dynamic Learning Environment
Copyright (C) 1999 onwards Martin Dougiamas (http://moodle.com)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the Moodle License information page for full details:
http://docs.moodle.org/dev/License

Have you read these conditions and understood them?
type y (means yes) or n (means no)
: y
-------------------------------------------------------------------------------
== Setting up database ==
-->System
.
.
.
++ Success ++
Installation completed successfully.

Change ownership of moodle path back to root user

sudo chown -R root /var/www/moodle

Add an alias for moodle in apache configuration

//Open the 000-default.conf file
sudo nano /etc/apache2/sites-enabled/000-default.conf

//Add the following line below 'DocumentRoot /var/www/html'
Alias /moodle "/var/www/moodle/"

//Restart apache server
sudo service apache2 restart

Get the IP address of your LXC container by typing folowing command inside LXC shell

ifconfig eth0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1

Paste the same address inside your moodle config file

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

//Replace the line
$CFG->wwwroot   = 'http://localhost/moodle';
//with the IP address obtained by the previous command, e.g.
$CFG->wwwroot   = 'http://10.0.3.15/moodle';

Test working moodle installation by visiting that address e.g.10.0.3.15/moodle in your preferred web browser. Create an account at moodle.org for getting full experience of moodle without any restrictions.

#Part 3: Learning Locker

There is a detailed guide to installing learning locker here and also a step-by-step guide for installing in Ubuntu here. However, both of them are a bit dated and give a fair bit of errors on newer Ubuntu distributions. You can refer them for the documentation as to what we are doing. Brief steps are listed below.

##Installing MongoDB

If you have logged out of the LXC container, login back by typing sudo lxc-console -n LMSprototype. Then, enter the following commands to install MongoDB

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo service mongod start

##Installing Learning Locker

sudo apt-get install curl nano apache2 php5.6 php5.6-mongo php5.6-mcrypt git nodejs npm mysql-server postfix

The Postfix configuration will ask you to choose the mail server type. Choose Internet Site, then you can use the default “mail name” that appears

Verify whether all services are running before proceeding

sudo service apache2 status
sudo service mongod status
sudo service mysql status
sudo service postfix status

Enable mcrypt

sudo phpenmod mcrypt

Install bower

sudo npm install -g bower
//If the above command gives error, try 'npm install -g bower'

Install composer

sudo apt-get install composer
export PATH="~/.config/composer/vendor/bin:$PATH"

Fetch Learning Locker

cd /var/www/
sudo git clone https://github.com/LearningLocker/learninglocker.git

Create collection and user in MongoDB

mongo
use learninglocker
db.createUser( { user: "learnlockuser", pwd: "learnlockpass", roles: [ "readWrite" ] } );
exit
sudo service mongod restart

Put mongoDB credentials in learning locker

sudo nano /var/www/learninglocker/app/config/database.php
 'driver'   => 'mongodb',
        'host'     => 'localhost',
        'port'     => 27017,
        'username' => 'learnlockuser',
        'password' => 'learnlockpass',
        'database' => 'learninglocker'

Download dependencies and migrate database

cd /var/www/learninglocker/
sudo composer install
sudo php artisan migrate

Generate APP_KEY

cd /var/www/learninglocker/
sudo php artisan key:generate

Change the ownership of everything within learninglocker

cd /var/www/learninglocker
sudo chown -R www-data:www-data *

Add an alias for learninglocker in apache configuration [ref]

//Open the 000-default.conf file
sudo nano /etc/apache2/sites-enabled/000-default.conf

//Add the following lines below 'DocumentRoot /var/www/html'
Alias /learninglocker "/var/www/learninglocker/public/"
<Directory "/var/www/learninglocker/public/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Add corresponding code to .htaccess file

sudo nano /var/www/learninglocker/public/.htaccess

//Add the following line below 'RewriteEngine On'
RewriteBase /learninglocker

Enable some modules and restart Apache server

sudo a2enmod rewrite negotiation php5.6
sudo service apache2 restart

Get the IP address of your LXC container by typing folowing command inside LXC shell

ifconfig eth0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1

Test working learninglocker installation by visiting that address e.g.10.0.3.15/learninglocker in your preferred web browser.

Upon successful registration, the first thing you need to do is to verify newly created user. On the left menu, go to “Users”. You’ll see a list with just one user, the admin you just created. On the status column, click on the “verified” button to manually verify this user.

After that, create a new LRS by clicking on the LRS button in left pane, and then on Create an LRS. Name the LRS TinCan test. Once created, go to Manage clients and copy the username and password of the first client to be used later.

#Part 4: Tin Can API

##Getting tin can prototypes

You can get readymade TinCan API prototypes at github. Download them inside LMSprototype container and make sure to update submodules.

cd /var/www/html/
sudo git clone https://github.com/RusticiSoftware/TinCan_Prototypes.git
cd TinCan_Prototypes
sudo git submodule update --init --recursive

##Installing tincan plugins for moodle

Now login back to moodle by visiting your address, e.g. 10.0.3.215/moodle. Click on Site Administration -> Plugins -> Install Plugins -> Install Plugins from Moodle Plugins directory.

After successfully logging in, search for the plugin tincan in the plugins directory and then install the following two plugins:

  1. xAPI Launch Link
  • Go to plugin page
  • From the right pane, choose moodle version as 3.1
  • Download the plugin as zip
  1. Tin Can Learner Stream
  • Go to plugin page
  • From the right pane, choose moodle version as 2.5
  • Download the plugin as zip

Now, go back to your moodle site, click on Site Administration -> Plugins -> Install Plugins and drop the downloaded zip files one by one to install them.

Note: If you face '[Error]Write access check' problem, change ownership of moodle root by typing

sudo chown -R www-data:www-data /var/www/moodle/

Dont forget to set the ownership back to root user by typing

sudo chown -R root /var/www/moodle

##Configuring moodle tincan api to communicate with learninglocker

Refer the following [video] for details on configuring Tin Can Launch Link and Tin Can Learner Stream

For my setup, the settings are as follows:

Endpoint: http://10.0.3.215/learninglocker/data/xAPI/  //Replace 10.0.3.215 with your IP
LRS integration: LearningLocker
Basic Login: e9ab800b8de14d0f2336bf0c5def40b25c9b2c3f  //Copied from LRS earlier
Basic Password: bd5d4958622ebf68f2ec96887ae9a753ca59960c //Copied from LRS earlier
Duration: 9000
Custom account homePage : 
Identify by email: Yes

##Creating a new course in Moodle

  1. In moodle dashboard, go to Site Administration -> Courses -> Manage Courses and Categories -> Create New Course

  2. Name the course Golf for both full and short name, leave other settings to default and click on Save and Return.

  3. Now, click on Site Home from the left pane, then click on the cog symbol in the top right corner and choose Turn editing on.

  4. Now an option becomes visible on the site home, Add an activity or resource. Click on that and choose Tin Can Launch Link

  5. Configure the launch link settings as follows:

Launch link name: Golf Course
Description: Golf Course
Launch URL: http://10.0.3.215/TinCan_Prototypes/GolfExample_TCAPI/index.html  //Replace 10.0.3.215 with your IP
Activity ID: https://id.tincanapi.com/activity/tincan-prototypes/golf-example

Leave all other settings to default and click on Save and display. Now if you visit Site Home, you will see a link to Golf Course with Tin Can Logo. Launch that course to record statements to LRS.

##Fetching activity streams from Learning Locker to Moodle

Go to Site Home. In the left panel, click on Add a block and choose Tin Can Learner Stream. If it is configured properly, you will see streams being fetched from the LRS to Moodle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment