Step-by-step Install Guide for Ubuntu using apt-get

Jump to: navigation, search

Note: You are currently viewing documentation for Moodle 2.0. Up-to-date documentation for the latest stable version is available here: Step-by-step Install Guide for Ubuntu using apt-get.

  • Ubuntu provides an integrated Moodle package consistent with other Ubuntu/Debian packages. While the Ubuntu/Debian package may not install the latest cutting-edge development version of Moodle, it is more likely to work well in an Ubuntu system.
  • The Ubuntu/Debian package can be installed using a Package Manager (such as Synaptic Package Manager, Adept Package Manager, or KPackageKit), but installation usually is more transparent and successful when the package is installed (using the apt-get tool) from a command-line interface.

Installation from the command-line interface

  • The command-line interface is the default in an Ubuntu server without a desktop, and it is possible, but not recommended, to run Moodle on a standalone server without a desktop. Of course, an Ubuntu or Kubuntu desktop is easily added to a server (using one of the commands: sudo apt-get install ubuntu-desktop or the command sudo apt-get install kubuntu-desktop). From the Ubuntu desktop the command-line interface is reached using Terminal; from a Kubuntu desktop it is reached using Konsole.

Prepare your server

  • Moodle is meant to be run on a server. It requires Apache2, the PHP scripting language, and a database (either MySQL or postgreSQL). While many users feel postgreSQL is a better database, MySQL is more widely used and is easier for first time users (since there are many integrated packages that use it). A LAMP server (Linux, Apache2, MySQL, PHP) can easily be installed from the command-line interface:
sudo tasksel install lamp-server

When installing the LAMP server, note the MySQL root password carefully. This will be required during Moodle installation.

  • Moodle must know where the server is located. (You must also have a way for other users to reach it.) The FQDN (Fully Qualified Domain Name) refers to the location of the server on which the Moodle database is located. In general, there are two options: localhost (meaning the database will be located on the same computer on which Moodle will be installed) or a URL. (Of course, the URL could still refer to the same computer).

Don't worry, whichever option you choose can be changed later. For initial installation, it is easiest to use localhost as the FQDN (and also wherever it is available as an installation option).

Moodle installation

Install the Moodle package from the command-line interface and follow the prompts:

sudo apt-get install moodle
  • Database server software for Moodle: mysql-server -> follow remainder of instructions. Assuming the database is hosted on the same computer as the one Moodle is being installed upon, accept localhost for the options when prompted.
  • Edit Moodle configuration options (if needed):
sudo nano /etc/moodle/config.php
  • Edit Moodle apache2 configuration file (if needed):
sudo nano /etc/moodle/apache.conf
  • Finish installation through a web browser. (A server without a desktop will not have a web browser. Now you see why it is better to have an Ubuntu or Kubuntu desktop installed on top of the server). I recommend the unattended installation.

Set up a virtual server

The whole point of Moodle is that users can access it over a network. The easiest way is to set up a URL for your server so that users can reach Moodle using the URL. Several steps are necessary.

  • If you have a router on your network, forward incoming traffic on ports 80 and 443 (http and https) from the router to the (static) LAN IP address of the server hosting Moodle.
  • The firewall on the Moodle server should allow all incoming traffic on ports 80 and 443.
  • A URL for your Moodle site should have been established with a DNS name server on the Internet. It is possible to use a Dynamic DNS server, as well. An example URL is
  • A virtual host file in /etc/apache2/sites-available must be created for Moodle.
cd /etc/apache2/sites-available
sudo cp default moodlevirtualhost
It should be edited (sudo nano /etc/apache2/sites-available/moodlevirtualhost) to look like
<VirtualHost *:80>
DocumentRoot /usr/share/moodle/
#RewriteEngine On
#RewriteOptions inherit

Notes: The Rewrite options are listed here only for forward compatibility with Apache rewrite rules. They are only used for multi-site installations and can, in general, remain commented out (with the #).

  • The virtual host file should be linked to /etc/apache2/sites-enabled and apache2 restarted (sudo etc/init.d/apache2 restart).
sudo ln -s /etc/apache2/sites-available/moodlevirtualhost /etc/apache2/sites-enabled
  • Edit the /etc/moodle/config.php file (sudo nano /etc/moodle/config.php) so that the FQDN (in this case the URL) is correctly noted.
$CFG->wwwroot = '';
  • Login to the Moodle server:

Add a custom theme to Moodle

  • Find free Moodle themes here.
  • Download one. Extract the zip file (by clicking on the filename in Dolphin, for example).
  • Copy the extracted folder to /usr/share/moodle/theme
  • From Moodle, install the new theme:
Moodle -> Appearance -> Themes -> Theme Selector

Random unreviewed comments

(These comments have not been reviewed for accuracy).

Configuration changes

Allow access to your Moodle from other computers

This moodle install will only work from the localhost. To make it accessible from other hosts you must edit the file /etc/apache2/conf.d/moodle. Type

sudo nano /etc/apache2/conf.d/moodle

(This is actually a soft link from /etc/moodle/apache.conf). This fires up the 'nano' text editor which is command line text editor and the sudo gives you the write access you need.

About 10 lines down you see the following line

#allow from all

The # indicates it is commented out, so remove the # and use CTRL+O to save the file.

Now restart apache by typing

sudo /etc/init.d/apache2 restart

in the terminal. You should now be able to access the moodle from other hosts by doing http://<address of your moodle host>/moodle


(These comments may be inaccurate). The installation is actually rather better thought out than many installations. For example the apache2 conf file is nicely done.

These are the file locations for a default install from apt-get

  • moodle site is at /usr/share/moodle
  • moodle data folder is at /var/lib/data
  • config.php is a soft link in the /usr/share/moodle folder and actually sits in /etc/moodle

The file permissions for the site and data folder are:

  • user = root, group = root for the site folder,
  • user = www-data and group = www-data for the data folder.

See also