Chamilo Pi: Installing Chamilo LMS on a Raspberry Pi B+

Raspberry Pi model B+

We wanted to try out installing Chamilo LMS 1.9.10 (still in development at the time of writing) on a Raspberry Pi B+ and see if, to some extent, it might be enough to provide for a little institution’s learning management system.

Installing Raspbian

First of all, installing Raspbian is one way to install an operating system on your Raspberry Pi. You can find the corresponding instructions on the Raspberry website here (you can choose either of the proposed options, but I chose a pre-installed Raspbian image).

Installing the required software stack

sudo apt-get update; sudo apt-get upgrade; sudo apt-get install nginx-full mysql-server php5-fpm php5-mysql php5-gd php5-curl php5-intl git

Downloading Chamilo

The easiest (although slowest) way, for development installations, to download Chamilo is to download it from Github*:

sudo -s
cd /var/www/
git clone https://github.com/chamilo/chamilo-lms.git chamilo
cd chamilo
git checkout 1.9.x

* Note that we added a patch in Chamilo LMS 1.9.10 to install on the basis of an IP addresses

Optimizing PHP

This is something I did *after* the load testing, but you might as well do it from the start. Because PHP 5.5 (and superior) comes with the Zend Optimizer+, and because it is famous for saving a lot of CPU by pre-interpreting PHP scripts, it is a good match for the Raspberry Pi which has low processing power and about 400MB of available memory.

You can find information on how to compile PHP 5.6 on your Raspberry Pi here: https://nicolas.steinmetz.fr/blog/ as given by @nsteinmetz

Compiling should take about 23 hours. Launch the apt-get source –compile php5 command from GNU Screen, so that you can disconnect and leave it to run, yet take it back later. To measure the total time it took (even if not watching it full-time), prefix the command with “time” to give you a report of the time taken when it finishes.

After that, you should prefer php5-mysqlnd to php5-mysql (so “apt-get install php5-mysqlnd”).

Configuring Nginx, PHP-FPM, MySQL and Chamilo

Once you’ve got everything installed, you’ll need to configure the distinct applications.

Nginx

The first service you should configure is Nginx (the web server).

sudo -s

cd /etc/nginx/sites-available/

vim default

server {
 listen 80;
 # If you want to respond to any URL, don't define a server_name
 # server_name my.chamilo19.net your.chamilo19.net;
 access_log /var/log/nginx/chamilo-access.log;
 error_log /var/log/nginx/chamilo-error.log notice;
 root /var/www/chamilo;
 index index.php;
 location ~ \.php$ {
   client_max_body_size 200m;
   include /etc/nginx/fastcgi_params;
   expires 5m;
   fastcgi_pass unix:/var/run/php5-fpm.sock;
   fastcgi_index index.php;
   fastcgi_param SCRIPT_FILENAME /var/www/chamilo$fastcgi_script_name;
   try_files $uri $uri/ @rewrite;
 }
}

Let’s wait before reloading the configuration, because we also need to setup PHP-FPM and MySQL.

PHP-FPM

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites. It was first included in PHP version 5.3.3 and reached production grade as of 5.4.

Configuring FPM is essential to get PHP running behind Nginx. There’s nothing that requires a change in php.ini. Everything can be done in the corresponding “pool” of FPM. The excerpt below is only showing the lines you should modify.

cd /etc/php5/fpm/pool.d/
vim www.conf
pm.max_children = 32
pm.start_servers = 4
pm.min_spare_servers = 4
pm.max_spare_servers = 8
php_admin_value[short_open_tag] = off
php_admin_value[session.cookie_httponly] = on
php_admin_value[upload_max_filesize] = 200M
php_admin_value[post_max_size] = 200M
php_admin_value[allow_url_fopen] = on
php_admin_value[date.timezone] = Europe/Brussels

The last setting (date.timezone) is very important to configure, as Chamilo will protest if you don’t. Set it to your timezone.

Enabling the Zend Optimizer has to be done manually by editing the opcache.ini file:

vim /etc/php5/fpm/conf.d/05-opcache.ini
; configuration for php ZendOpcache module
; priority=05
zend_extension=opcache.so
opcache.enable=On
opcache.memory_consumption=24
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=3900
opcache.revalidate_freq=120
opcache.fast_shutdown=1
; Special optimization: do not used cwd to cache files as on this install there's only one php app
opcache.use_cwd=0

MySQL

There are only a few things that you can change to MySQL’s config to make it more efficient in the Chamilo + Raspberry Pi context. Here are the only lines you should modify in the /etc/mysql/my.cnf file:

vim /etc/mysql/my.cnf

key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
max_connections = 40
query_cache_limit = 16M
query_cache_size = 16M

In particular, we *reduce* the max_connections setting to 40 (instead of the default 100) because otherwise MySQL will use too much memory for FPM to be able to run its PHP processes efficiently.

Chamilo

Once you got all this setup, you’ll need to restart all these services…

service mysql restart; service php5-fpm restart; service nginx restart

and then install Chamilo following the normal installation procedure (this requires enabling a MySQL user for your Chamilo – preferably not root directly). Use your Raspberry’s IP address to connect through your browser and be prompted by the installation procedure.

Once you’ve done that, you’ll have to edit the configuration file to get the name resolution right, even if you change IPs or domain names in the future. Find the “root_web” line, and replace it as follows (in this example, replace 192.168.178.24 by the IP of your Raspberry, or leave it if already configured correctly):

vim /var/www/chamilo/main/inc/conf/configuration.php
// URL to the root of your Chamilo installation, e.g.: http://www.mychamilo.com/
$_configuration['root_web'] = 'http://192.168.178.24/';
if (!empty($_SERVER['HTTP_HOST'])) {
    $_configuration['root_web'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
}

This will allow any domain to be used to load Chamilo, but will force it into HTTP mode. If you want to use HTTPs (which we recommend), you’ll have to make the necessary changes to this tutorial, which is limited to HTTP.

Starting up Chamilo

Now you can load Chamilo into your web browser (by pointing it to your Raspberry).

The first things you’ll need to configure (by going to the administration panel and selecting “Platform settings”), for increased efficiency, are:

  • disable the “hot courses” block (it requires a lot of processing for the voting starts)
  • disable the display of “online users” (for the three types)
  • disable all unnecessary languages (preferably keeping only one)

This should considerably alleviate your installation.

This is it! You have a ChamiPi running! Congrats!

I have added information on load testing below, so you know what to expect.

Load testing

Apache Benchmark is available as the apache2-utils package on your computer, and is to be used like this:

ab -n 200 -c 10 http://192.168.178.24/

This will request 200 pages by simulating 10 different computers queuing simultaneously for an answer from the server.

I have been varying the tests slightly, without much difference, but I finally kept these numbers as a more-or-less-realistic estimation of what I want to test.

In short, using PHP 5.4 with no optimization allowed the Raspberry to treat 1.17 requests per second (so it took a while) for the Chamilo homepage.

With different optimizations as described above, I managed to get an average of 1.80 requests per second (a 50% increase in speed from PHP 5.4).

Conclusion

The energy consumption and size of the Raspberry Pi makes it interesting for remote schools scenarios where energy is scarce and security is an issue (a Raspberry Pi device can easily remain hidden from anyone’s sight). However, the speed of 1.8 request per second is too low to make it a fast system for a typical “classroom” scenario where more than 10 computers might be connected to it.

If used in this context, I would recommend no more than 10 computers at the same time, and some patience (although people in areas without Internet are generally quite patient) to use the system. If these criteria are respected, there should be no big issue using Chamilo LMS.

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on TumblrEmail this to someone
Posted in:

15 Comments

  1. We will soon be testing the same with a Raspberry Pi 2, which features a much faster quad-core CPU, and 1GB RAM (instead of only 512MB).

    Stay tuned!

  2. Hello.
    I’ve tried this using Raspbian Jessie Minimal on a Raspberry Pi 2, but there seems to be a problem installing nginx.

    Have you tried this installtion method on a Raspberry Pi 2? Is this tutorial Wheezie or Jessie? You said on 20 March, 2015, that “We will soon be testing the same with a Raspberry Pi 2…”

    Thank you

  3. 7,75 requests/second
    Completed 100 requests
    Completed 200 requests
    Finished 200 requests

    Server Software: nginx/1.6.2
    Server Hostname: 192.168.1.13
    Server Port: 80

    Document Path: /
    Document Length: 25197 bytes

    Concurrency Level: 10
    Time taken for tests: 25.790 seconds
    Complete requests: 200
    Failed requests: 0
    Total transferred: 5118200 bytes
    HTML transferred: 5039400 bytes
    Requests per second: 7.75 [#/sec] (mean)
    Time per request: 1289.517 [ms] (mean)
    Time per request: 128.952 [ms] (mean, across all concurrent requests)
    Transfer rate: 193.80 [Kbytes/sec] received

    Connection Times (ms)
    min mean[+/-sd] median max
    Connect: 0 0 0.3 0 3
    Processing: 620 1272 292.8 1283 2237
    Waiting: 613 1252 288.2 1261 2209
    Total: 620 1272 292.8 1283 2239

    Percentage of the requests served within a certain time (ms)
    50% 1283
    66% 1404
    75% 1503
    80% 1554
    90% 1638
    95% 1682
    98% 1810
    99% 1861
    100% 2239 (longest request)

    • Not really. This is specific to the Raspberry Pi B+. There are other guides to install Chamilo on Digital Ocean. I suggest you use these ones instead, or read the installation guide that comes in the documentation/ folder of any Chamilo zip package.

      • when the process of chamilo installation on step 2 : Requirements, i have prompted with this messages :

        /var/www/chamilo/app/ Writable
        /var/www/chamilo/main/default_course_document/images/ Writable
        /var/www/chamilo/main/lang/ Writable
        (Only required by the sub-languages feature)
        /var/www/chamilo/vendor/ Readable
        /var/www/chamilo/web/ Writable
        A test course has been created successfully No
        Permissions for new directories 0777
        Permissions for new files 0666

        how to solve : A test course has been created successfully NO??? what i’m doing wrong??? please help and guide me… thanks.

        • To create a test course, Chamilo creates one then tries to connect through HTTP to check if the course homepage is responding. If not, it considers the course creation has failed.

          This requires the server (the Raspberry in this case) to know that itself should respond to the URL you’ve selected to install your Chamilo portal. For example, if it’s an IP address that you use, it is likely that the Raspberry will have the same and understand that. However, if you have defined a domain on your computer and use it to connect to the Raspberry, but the Raspberry is not aware that it answers to that domain, it won’t be able to check that the course is responding (it will try and load the domain but that won’t match anything that translates through DNS).

          To fix it, just add the domain name in the /etc/hosts file of your Raspberry and you should be able to validate the course creation.

  4. Wow… with the Raspberri Pi 3 coming out now, and again pumping up the RAM en processing power, we’re really getting to the point where this can manage a real (15 pupils or more) classroom at a feasible speed! Last thing I heard, was that the WiFi is even faster than the ethernet plug (because the Wifi isn’t sitting on the USB-hub). So you just put it in the WiFi domain, and we’re up and running…

  5. Great post. I have a Raspberry 3 and am currently delivering static web pages via a router in an internet-less classroom. Looking forward to getting Chamilo up and running
    Some classes have over 60 students so we will see what the Pi can do.

      • Just set up a standard LAMP server ( finding the nginx install a little tricky). I have a sdcard only for boot and are running off a Maxell 8GB drive. The results for a Pi 3 running Jessie Lite was 14 Requests per second.
        Given the initial result of 1.8 requests per second might be enough for about 10 computers that seems encouraging. I will back up the image and try again with some tweaking.

Leave a Reply

Your email address will not be published. Required fields are marked *