Moodle on Pi
I recently volunteered to explore some open source education software for my Mom (a former high school teacher and current home school educator) called Moodle. Implemented in PHP, Moodle runs on the "LAMP" stack (Linux Apache MySQL PHP). I wanted to create a sandbox environment to play around in with the tool, and I immediately thought of my Raspberry Pi!
The Raspberry Pi technically meets the hardware requirements for hosting Moodle, although it is not likely to scale very high. Still, it makes a perfect platform for experimenting with Moodle at home.
Unfortunately, a Google search revealed that no one had deployed Moodle on the Raspberry Pi yet... (Or at least shared with the world if they did!) Sounds like a hole that should be filled!
My first steps were to get the LAMP stack installed and situated on the Raspberry Pi.
Note: Even if you are uninterested in Moodle, having LAMP on your Pi is very useful for other things.
First, I recommend you update your
apt-get repositories and upgrade your firmware if possible.
sudo apt-get update sudo apt-get upgrade
That will put you in a good place for the rest of the software you will install.
Apache is a web server that is capable of serving static and dynamic files from your Pi over HTTP. Installing it is relatively simple:
sudo apt-get install apache2
That should be all that is needed. Once that completes successfully you should have Apache installed on your Pi. To test this, run:
sudo service apache2 restart
Then browse to:
http://<IP Address of Rasspberry Pi>/
Note: If you need help setting a static IP for your Raspberry Pi that is accessible to other computers on your WIFI network, you can refer to my other blog on the subject to get you started.
Note: Apache is a complex and powerful tool. This blog is describing how to setup your Pi as a LAMP server for the purposing of in home sandboxing only. Using your Pi in a production environment is not recommended without considerably more thought about configuration.
You should see an Apache page that says "It Works!" meaning you succeeded!
MySQL is the data store part of the LAMP stack. Like Apache, the installation of MySQL is relatively straightforward.
sudo apt-get install mysql-server mysql-client
During the installation, it will prompt you to set a
root password. Please do so and make a note of it.
Once the installation is complete you can verify it succeeded by running:
mysql -u root -p
It will prompt you for the
root password. If you then are given a
mysql> prompt, the installation has succeeded! Type
exit; to leave the prompt.
On to the next step!
PHP is the engine that runs the code that Moodle is implemented in. Moodle requires PHP itself, and a number of additional integration points.
sudo apt-get install php5 sudo apt-get install php5-mysql sudo apt-get install libapache2-mod-php5
Executing these will install PHP and the integration points for MySQL and Apache.
Through trial and error I discovered the Moodle also needs the following PHP modules:
sudo apt-get install php5-curl sudo apt-get install php5-gd
To verify the successful completion of PHP, execute this command:
If you see the command usage printed for PHP then you have at least a warm fuzzy that PHP is working!
At this point we have a full LAMP stack on our Pi, capable of running running any PHP web application.
Note: If that is as far as your interest goes, then you are all set! Happy coding! However, if you want to play with Moodle itself, then continue reading!
To install Moodle, we need to get either a prepackaged distribution or the source code itself. Given the nature of PHP, I opted to just pull all the source code.
mkdir /var/www/moodle cd /var/www/moodle git clone -b MOODLE_26_STABLE git://git.moodle.org/moodle.git .
Note: In order to serve up the Moodle, Apache needs it to be in a configured document root. I just put Moodle directly in Apache's default directory. I have not done enough LAMP work to know if this is common practice or not. But for purposes of creating a sandbox, this is more than fine.
Moodle needs several things setup in order to run. First of all, it needs a database setup in MySQL. Run:
mysql -u root -p
Once more, and enter the root password to log into the MySQL terminal. You will first want to create a empty database for Moodle.
CREATE DATABSE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Then create a database user with access to the moodle database:
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO [email protected] IDENTIFIED BY 'moodlepassword';
moodlepassword with values of your choosing.
With your database properly set up, the second thing you need to do is create a cache directory for Moodle to user.
sudo mkdir /moodledata sudo chown pi:pi /moodledata
That is all the set up you need! Now you can proceed with the actual Moodle install.
Moodle provides a web installer (truthfully... its more of a "configurator" instead of an installer) but I opted for the CLI version instead.
cd /var/www/moodle/admin/cli sudo php install.php
The install script first asks for a number of pieces of information. Some of these are straight forward (language to use, database user name and password, etc.), but some are less than intuitive. The ones that tripped me up:
- Web Address - They want you to specify the exact path that you will use to access Moodle. If you deployed Moodle to apache in its own directory this should be:
http://<IP ADDRESS>/moodle. Where
is the static IP of your Raspberry Pi.
- Data Directory - The cache directory you created above. It can be really particular about the permissions for this directory, hence why I created a directory at the root level.
- Full Site Name / Short Name - Both of these values are for GUI display only. They are simply the values that should go in the banners of your Moodle instance. (A little documentation from Moodle in the installer would have been nice I might add!)
Note: If you need to terminate the installer prematurely, be warned that it will not restart easily. You need to delete the
/var/www/moodle/config.php file that was created first. Try to avoid this if possible!
Once you have been prompted for all the fields, the installer will setup the database.
Note: This can take a long long time. I promise, your Raspberry Pi is not hung. It took mine over 3 hours to complete this phase!
If that installer completes successfully you should be done! Congratulations!
http://<IP ADDRESS>/moodle and you should be greeted by the Moodle home page!
I am still playing around with Moodle, but a few quick tips to get you started:
- Log in as the
adminuser (the installer lets you select admin user name and password).
- Set your email in your Profile page. Moodle does not seem to want you to continue until you set this.
As admin you will be able to create a course, modify system settings, and so forth.
Questions? Comments? Email me at: [email protected]!