Tutorial

How To Install Moodle On A VPS Running Ubuntu 12.04 And LAMP

Published on August 22, 2013
How To Install Moodle On A VPS Running Ubuntu 12.04 And LAMP

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

About Moodle

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.

Requirements

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

Installation

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/download.php/stable25/moodle-latest-25.tgz

Your proper download link: http://download.moodle.org/download.php/direct/stable25/moodle-latest-25.tgz

Then navigate to your webserver’s root directory and download it:

cd /var/www
wget http://download.moodle.org/download.php/direct/stable25/moodle-latest-25.tgz

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 (~):

mkdir /moodledata

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.

Article Submitted by: Danny

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the author(s)

Category:
Tutorial

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
10 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

You’re also going to need to run the following to get all the remaining prerequisites for Moodle.

sudo apt-get install php5-xmlrpc php5-intl

Hello guys,

I followed the instructions and everything worked out here with Moodle. Thank you. But when installing Joomla on this same instance LAMP JOOMLA not find the temporary directory of PHP. Some know how to solve a this?

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
December 3, 2013

@saraiva: Please paste the exact error that you get.

Hello @Kamal Nasser

One of the types of errors that appear this is:

Falha ao copiar JInstaller: :Install: Falha ao copiar o arquivo /var/www/site/tmp/install_529e34fe77389/install_529e34fe794a8/pt-BR.com_contact.ini para /var/www/site/language/pt-BR/pt-BR.com_contact.ini Pacote Atualizar: Houve um erro durante a instalação da extensão: site_pt-BR.zip

My PHP: http://192.241.182.84/info.php

I realize that the performace of this server also impaired, is very slow. Thanks for the help.

In addition, “apt-get install php5-json” is required in ubuntu version13.10

furthermore, If you want to use mariadb you need to upgrade php with the following command

sudo apt-get install php5-curl php5-xmlrpc php5-gd php5-intl libapache2-mod-php5 libapache2-mod-ruby libapache2-mod-python php5 php5-common php5-dev php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-mysql php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl libapache2-mod-php5

I am very much new to this. I created a droplet with LAMP stack enabled, then downloaded moodle, extracted it and created a database.

When I use my web browser to start the installer http:/xxx.xxx.xxx.xxx/moodle, it says access is denied.

I am exactly doing what is written in the article.

Got it finally…

the correct directory in Ubuntu 14 is /var/www/html/

This comment has been deleted

    Got it finally The correct directory to install in Ubuntu 14 is /var/www/html/

    Join the Tech Talk
    Success! Thank you! Please check your email for further details.

    Please complete your information!

    Become a contributor for community

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    DigitalOcean Documentation

    Full documentation for every DigitalOcean product.

    Resources for startups and SMBs

    The Wave has everything you need to know about building a business, from raising funding to marketing your product.

    Get our newsletter

    Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

    New accounts only. By submitting your email you agree to our Privacy Policy

    The developer cloud

    Scale up as you grow — whether you're running one virtual machine or ten thousand.

    Get started for free

    Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

    *This promotional offer applies to new accounts only.