Moodle is a virtual learning environment used by tens of thousands of schools across the world. Using Moodle, you can create a fully online course, or use it to supplment a traditionally-taught classroom course. Best of all, Moodle is free, and you can install it on Ubuntu 14.04 Trusty Tahr Installing Moodle on Ubuntu is a bit of work, but once it is finished, you’ll have a robust e-learning server application.
It’s quite possible to install Moodle on a machine running either the desktop or the server version of Ubuntu. This makes an excellent environment for testing and experimentation, since you can tweak and experiment to your heart’s desire without rendering your production site inoperable. Given that Moodle is free, if you have a bit of Linux knowledge, you can use Moodle in lieu of far more expensive alternatives.
First, install Ubuntu into your machine of choice. Once Ubuntu is installed and updated, you will need to install five pieces of software: the Apache web server, the MySQL database server version 5.5, PHP version 5, the MySQL module for PHP, and finally the Moodle software itself.
First, install the Apache web server. To install Apache, go to a Terminal window or a command prompt and type this command:
sudo apt-get install apache2
(Technically, you’ll be installing Apache 2, the latest version.)
Enter your password to authenticate, follow the default prompts, and apt will download and install the Apache web server for you.
Apache should now be working. To test it from the web server itself, go to a web browser and visit the address http://127.0.0.1 . Alternatively, you could test it from another computer on the same subnet. For instance, if you installed Apache on a computer with an IP address of 192.168.1.100, you could test it by going to another computer on the same subnet and visiting http://192.168.100 from the web browser.
Regardless, if Apache is working properly, you should see a web page with only two words on it:
Apache is now operational.
The next step to install Moodle is to install the MySQL database server. Return to the Terminal and type this command:
sudo apt-get install mysql-server-5.5
(As of this writing, MySQL Server version 5.5 is the latest version available in the Ubuntu repositories, though future versions of Ubuntu may receive the newer versions of MySQL.)
Enter your password to authenticate, and apt will download the MySQL files and install them for you. It’s a big set of files, so depending on the speed of your Internet connection, it might take a while to download. After the files are downloaded and are installing, the installer will ask you for a password for MySQL’s root user. Just like the root user in Linux, the root user in MySQL has absolute control over all databases, tables, permissions, and users. For obvious security reasons, you’ll want to create an extremely strong password (a mixture of uppercase, lowercase, numbers, and punctuation, the longer the better) for your MySQL root user.
(Note that in the password dialog box, you can’t get the <OK> field selected, you can use the tab key to jump from the text input line to the <OK> field.)
Next, you’ll want to run the mysql_secure_installation script to tighten up security on your new MySQL server. Run this command from the prompt:
First, the mysql_secure_installation script will ask you to enter the current password for the MySQL root user. After you do that, it will ask if you want to change the root password. Since you already set a root password, you can hit “n” (unless you want to change it again for some reason).
Next, the script will ask if you want to remove the anonymous user. The anonymous user, like anonymous access in FTP, lets someone log into MySQL without having a proper user account. For security reasons, it’s always best to remove the anonymous user, so hit “y” to continue.
After that, the script will ask if you want to prevent the MySQL root user from logging in remotely to the MySQL server. Always hit “y” to forbid root remote access, since if an attacker guesses your root password, he can destroy your databases or steal the information they contain.
After this, the script will ask if you want to remove the test database. MySQL includes a test database that anyone can access. Again, this is a security hole, so you’ll want to hit “y” to remove the test database.
The script will then ask to reload the privilege tables so the changes take effect. Hit “y”, and the mysql_secure_installation script will conclude and return you to the command line.
MySQL server is now installed on your Ubuntu system.
Now we’ll need to prepare MySQL for use with Moodle. Moodle requires a database and a database user, and full permission for its database user to access its database. To start the MySQL command-line client, use this command:
mysql -u root -p
Enter the password for the MySQL root user, and you’ll find yourself at the MySQL command prompt, which will look like this:
Our next steps are to create a Moodle database, create a user to access that database, and grant our new user all rights to the Moodle database.
(An important note before we continue, though. All commands made from the MySQL prompt must end with a semicolon to denote the end of the statement. Any commands that do not end with a semicolon will not work. With that in mind, let’s first create a database.)
To create a database for Moodle, use this command at the mysql> prompt:
CREATE DATABASE moodle;
The MySQL client will respond with a message that should say “Query OK, 1 row affect (0.00 sec).” This means the command was successful, and a new database named “newdatabase” has been created.
Next, you’ll create a user who will access that database:
CREATE USER moodleuser;
You should get the “Query OK” message again. Once the new user is created, we’ll need to set a password for the user before we can assign any permissions. In this example, we’ll assign a password of “1234″. However, in real life, just as with the root user, you’ll want to assign a much, much stronger password than this. (This database user won’t have full control over the MySQL user as the root user does, but we will give it full control over the database we just created, and a malicious user who guesses the password could cause all kinds of trouble.) To create the password, use this command:
SET PASSWORD FOR moodleuser= PASSWORD(“1234”);
Again you should get the “Query OK” confirmation message. The final step is to assign all privileges on the “moodle” database to the “moodleuser” user. Use this command to assign the permissions:
GRANT ALL PRIVILEGES ON moodle.* TO moodleuser IDENTIFIED BY ‘1234′;
That isn’t a typo – those are single quote marks (‘) instead of the usual double quote marks (“) that were used in the command to set the password. MySQL’s internal syntax, alas, isn’t always consistent. Anyway, if you typed the command correctly, you should get the “Query OK” confirmation again.
Once you are done, use this command to quit the MySQL command-line interface:
The next step to installing Moodle is to install PHP version 5, along with the necessary PHP modules. First, install PHP 5 with this command:
sudo apt-get install php5
After this, you will need to install several different PHP extensions not included with the default PHP 5 implementation on Ubuntu. First, install the MySQL module for PHP:
sudo apt-get install php5-mysql
You must also install the GD library for PHP:
sudo apt-get install php5-gd
The JSON extension is also required:
sudo apt-get install php5-json
The CURL extension:
sudo apt-get install php5-curl
The XMLRPC extension:
sudo apt-get install php5-xmlrpc
And, finally, the INTL extension:
sudo apt-get install php5-intl
After all the plugins have installed, restart Apache so it recognizes the plugins properly:
sudo /etc/init.d/apache2 restart
Finally, download the Moodle software to your Desktop. You can obtain it from this address:
Move the Moodle files over to the /var/www/html directory. (In this command, I’ll assume you unpacked the moodle files to your home directory; you will have to adjust the command if you unpacked them in a different directory.)
sudo cp -r ~/moodle/* /var/www/html
After that, rename the old index.html file in /var/www/html so Apache uses Moodle’s PHP files for the site, not the index.html file:
sudo mv index.html index.html.old
Now that we’ve got our software downloaded, we’ll need to configure it.
You will need to create a location for Moodle to save data files. Traditionally, the location is in /var/moodledata. (Creating the data directory inside the web server directory is an extremely bad idea, due to the resultant security holes.) To create the data directory, use this command:
sudo mkdir /var/moodledata
Use this command to change the owner of the directory to the Apache system user. In Ubuntu, the Apache system user is usually named www-data:
sudo chown www-data /var/moodledata
Then use this command to make the /var/moodledata directory writable to Moodle:
sudo chmod -R 744 /var/moodledata
Now that configuration and setup is complete, we are actually read to begin installing Moodle!
Fire up a web browser and navigate to the Moodle location to launch the web-based installer. If your server’s IP address (for example) is 192.168.1.100, the address would look like this:
This will take you to the Moodle setup page.
First, select the language for your Moodle installation, and then click the Next button.
The installer will then ask for the locations of Moodle’s directories. The defaults will work, especially if you already created the /var/moodledata directory as indicated above. Click the Next button to continue.
Moodle will then ask what kind of database server to use. Since we already set up our MySQL database, select “Improved MySQL” and then hit the Next button.
Then installer will then need you to input the information for the database and database user we created above. Since our MySQL server is on the same machine as Moodle, leave “localhost” for the Database Host field. Enter “moodle” for Database Name, “moodleuser” for Database User, and then ‘1234’ for Database Password. Leave the other fields blank, and then click Next.
Moodle will then generate a config.php file. Copy and paste the data of the config.php file, save it as “config.php”, and then transfer it to your server. Make sure to put it in the directory containing the Moodle installation – in this example, /var/www. Once the config.php is in place, make sure to mark it as executable with this command, otherwise the installation will halt:
sudo chmod 744 /var/www/html/config.php
Save the config.php file, and then go back to the web browser and click the Next button.
Moodle will then ask if you agree to the terms of service. If you do, click the Continue button.
The installer will then run a system check to make sure your server has all the necessary software to support Moodle. If not (it’s common to forget one of the PHP extensions), the installation will pause to allow you to install the missing software. Once you have, click Reload. If all the checks are passed, you can click the Continue button to continue.
The Moodle installer will then start building the database tables it requires in the database we created earlier. The Moodle database is large and complex, and building the database may take a considerable amount of time, so be patient. As the installer successfully builds database tables, they will scroll down in the browser window. Once the database construction is complete, the Continue button will appear at the very bottom of the page. Click on it to continue.
Moodle will then display a form for you to set up an administrator account for your new site. Enter an appropriate username and a strong password, along with any other required fields. Once you have finished, click on the Update Profile button at the bottom of the page.
The install will then ask you to pick a full site name and a short name for the site. Select suitable names, and then click the Save Changes button.
Congratulations! Your Moodle installation is now complete, and you can begin adding courses and other materials. For additional documentation, the Moodle site contains many useful resources:
The Ubuntu Beginner’s Guide
The Ubuntu Desktop Beginner’s Guide
The Linux Command Line Beginner’s Guide