How To Install Moodle On A VPS Running Ubuntu 12.04 And LAMP
Moodle is an open source Course Management System (CMS) that lets you create online learning sites. The name stands for Modular Object-Oriented Dynamic Learning Environment and it has numerous features that allow for an efficient online learning experience that can scale from a small number of students to hundreds of thousands.
Some of these features include assignment submission, online quizzes, wiki, grading, instant messages, discussion boards, and others. But since it’s a modular software, it can be extended via plugins to add extra functionality.
Moodle typically runs on LAMP (Linux, Apache, MySQL and PHP) but can also be used with other webservers, primarily IIS. And although not fully tested, it should work on Lighttpd and Nginx as well. For a database it is best to be run with MySQL or PostgreSQL since most of the online documentation focuses on them. However, you can also use Oracle and MSSQL. Whichever one you use though, you will need the appropriate PHP extension installed. As for the PHP, it requires version 5.3.2 or greater.
In this tutorial we will look at how to install Moodle on an Ubuntu 12.04 environment that has the most common web server configuration installed on it: LAMP. For more information on how to set this up, feel free to read this article. Henceforth this tutorial will assume you have the same installation.
Before we proceed with the installation of Moodle, let’s just take care a couple of PHP extensions that need to be installed for Moodle to run: the cURL and GD extensions. If you don’t already have them installed, please follow these steps: For the first one, run the following commands:
sudo apt-get update sudo apt-get install php5-curl
For the second one, since you already updated the repositories with the apt-get update command, it's enough to use the following command:
sudo apt-get install php5-gd
Then restart Apache for the changes to take effect:
sudo service apache2 restart
To install Moodle, you’ll first need to download its codebase onto your VPS. There are 2 ways you can do this, either you download the archive and unpack it or you clone the git repository. We will proceed with the first choice as it doesn’t require you to install Git.
First, get the url to the tar file of the latest Moodle stable release from the moodle.org website. Be careful because the Moodle website automatically generates a download link from a sourceforge.net mirror. So it won’t work if you simply right click and copy the link URL from the Moodle website. What you do is copy that link and add another segment to the url like so:
Your Moodle link: http://download.moodle.org/
Your proper download link: http://download.moodle.org/
Then navigate to your webserver’s root directory and download it:
Make sure you replace the link in the wget command with the one you found and modified. Next, unpack the archive you downloaded:
tar xzvf moodle-latest-25.tgz
You should now get a folder called moodle that contains all the necessary files.
Next up, we need to make sure our Moodle files are secure and not writable by the public. So let’s make the user root the owner of all the files and make sure it is the only one that can write them. Run the following commands from your web server’s document root (/var/www just next to the moodle folder where the Moodle files are located):
chown -R root moodle chmod -R 0755 moodle
Then let’s create the moodledata folder (a directory Moodle will use for its temporary operations so it needs to be able to write in it). An important thing about this folder is that it shouldn’t be accessible from the web, so make sure you put it outside of the server’s web root. Let’s just create it in the home directory (~):
And make it writable by the VPS:
chmod 0777 /moodledata
Now, let’s create an empty database for Moodle to use. In your MySQL terminal, you can run the following commands to create the database that we will here call "moodle":
create database moodle;
This command will create your database. Be sure you make note of the database name, user and password so you can later specify them for Moodle to connect. There are some great resources to check if you want to learn more about using MySQL from the command line or to switch from MySQL to MariaDB.
Next, let’s go to the browser and point it to the folder where the Moodle files are. This will bring up the web installer. In our case it will be: http://www.example.com/moodle.
Here you should see the installer wizard with the first page on which you have to choose the language. On the next screen, specify the location of the moodledata folder you created earlier. In our case it’s /moodledata. Following this, you have to choose the database driver you’d like to use - in our case it’s MySQL. Then fill in the connection information to the one you created earlier.
Now you should get to a Configuration Complete page that if you followed all the steps above should tell you that the installation script could not write the config.php file. It will direct you to copy the necessary lines into a new file and place it accordingly, so let’s do just that.
Navigate to the root directory of the Moodle install (/var/www/moodle for us) and create a new file called config.php:
cd /var/www/moodle nano config.php
Then paste in the code generated by the Moodle installer. Save the file, exit and proceed by clicking the Next button in the installer. Confirm the copyright notice and proceed to the page which checks the VPS for everything you need for Moodle to be installed. You must make sure that you don't have any notices in red. If you do, take care of the problems before going forward.
If all is in order, you can continue. At the end of the long page displaying all the things that get installed, press again continue and you’ll be directed to the page where you have to set your main administration account and some general site settings. And that’s it, with the next page you will finally land on the front page of your new Moodle site.