#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 byq
. - Stop the LXC container, you can use command
sudo lxc-stop --name LMSprototype
. - Destroy it permanently, use
sudo lxc-destroy --name LMSprototype
.
#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/html/moodle
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
##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 php-mongodb php7.0-mcrypt nodejs npm postfix libapache2-mod-php7.0 php-mbstring
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
cd
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
Fetch Learning Locker
cd /var/www/html/
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
nano /var/www/html/learninglocker/app/config/database.php
'driver' => 'mongodb',
'host' => 'localhost',
'port' => 27017,
'username' => 'learnlockuser',
'password' => 'learnlockpass',
'database' => 'learninglocker'
Run Install
cd /var/www/html/learninglocker/
composer require jenssegers/mongodb --ignore-platform-reqs
#Errors
//////////////////////////////
sudo apt-get install curl nano apache2 php7.0 php-mongodb php7.0-mcrypt git nodejs npm mysql-server postfix
sudo apt-get install curl nano apache2 php7.0 php-mongodb php7.0-mcrypt git mysql-server postfix
https://groups.google.com/forum/#!msg/learning-locker/TPbdtmfCxhM/3623QRwWDAAJ
http://askubuntu.com/questions/756181/installing-php-5-6-on-xenial-16-04
/////////////////
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 git-core nano
//////////////////
Discussion: https://groups.google.com/forum/#!msg/learning-locker/TPbdtmfCxhM/3623QRwWDAAJ
Downgrading to php5: http://askubuntu.com/questions/756181/installing-php-5-6-on-xenial-16-04
//////////////////
##Getting tin can prototypes
Now that we are done with setting up a container, we can start working on our setup. You can get readymade TinCan API prototypes at github
Download(git clone) them inside LMSprototype container and make sure to update submodules.
cd /home/ubuntu
mkdir Documents
cd Documents
mkdir LMSprototype
cd LMSprototype
git clone https://github.com/RusticiSoftware/TinCan_Prototypes.git
git submodule update --init --recursive
Hi! Do you know if mariadb is compatible with learning locker?