Note: You are currently viewing documentation for Moodle 2.2. Up-to-date documentation for the latest stable version is available here: Installing Moodle on Debian based distributions.

Installing Moodle on Debian based distributions

From MoodleDocs
Revision as of 10:58, 1 June 2012 by Visvanath Ratnaweera (talk | contribs) (Cosmetics in the final sections.)

Introduction

Scope

  • This article documents how to install Moodle on Debian GNU/Linux and on distributions based on Debian, specifically Debian 6.0 “Squeeze” and Ubuntu Server 10.4 LTS “Lucid Lynx”. The instructions here should also be valid for many other Debian and Ubuntu derivatives.
  • These instructions are generic for all the currently maintained versions of Moodle, from 1.9 to 2.2. They have also been tested for the discontinued versions 1.6 to 1.8.

    Update: 30. Apr 2012: Quick check with Ubuntu Server 12.04 LTS 32 bit: Moodle 1.6 is broken, because it asks for MyISAM but MySQL has moved to InnoDB. From Moodle 1.7 onwards installed flawlessly.

  • A 'stand alone' setup which does not need a network and two levels of networking, 'LAN only' and 'Internet', are presented here. They are set in table form as in table below.
    stand alone LAN only Internet
    You install Moodle on your Debian based computer so that it will only be accessible within that computer. This setup is ideal for testing Moodle and developing courses without going online.

    Of course during the installation and upgrades you must go online.

    We safely assume that your computer runs a graphical interface like Gnome, KDE, XFCE, etc.

    The Moodle computer will be connected to a private network, a LAN or a VPN, and allow access to other computers in that network.

    With this setup a whole team can develop courses in collaboration and also give access to students, as long as all are within the private network.

    Here too the machine must have Internet access during installation and upgrades.

    A server which is accessible from the Internet. The machine either has a public IP address or accessible through port­forwarding. Ideally, it also has a DNS name.
    Table 1. The three levels of networking discussed
  • Please note that server maintenance including upgrading, backup, benchmarking, tuning, hardening, etc. are not part of this documentation.

Disclaimer

  • The public Internet has become a rough terrain. You should not leave a machine connected to it, unless you understand a whole lot about security. This article covers just the 'default setup', without any special security precautions. Be warned!
  • There is no substitute for thinking. For most part the commands here are self-explanatory. If you are in doubt, invest on building some background knowledge. These instructions are not 'Mantras' which you can cut and paste in to your command line and execute! If you do that, in the best case you will get an error message. The worst case could be much worse. Please, be warned!

Typography and conventions

Command line dialogs are set in mono typeface as in this example:

; Get the local time
$ date
Son Feb 30 09:50:00 CET 2012

The first line is of course a comment. In the second line you have typed 'date'. The third line is the response from the computer. Things you type are set in boldface - the response in regular type.

Sometimes parts of those commands are unique to your setup. They are set in slanted type. In the example below 'username' stands for an existing (Unix) username in your system.

$ last username
username    pts/0        172.18.222.53    Thu Feb  31 22:49 - 03:01  (04:11)
...

The command interpreter indicates its readiness by printing the command prompt, or in short the prompt. The standard prompt for a non-privileged user is the $ sign - the hash (#) indicates the superuser. Caveat: Don't type the prompt!

Other interpreters have other prompts. For example the MySQL command-line tool uses 'mysql>'

mysql>  SELECT now();
+---------------------+
| NOW()               |
+---------------------+
| 2012-02-31 09:50:00 |

Commands with superuser privileges

All the commands in this page are executed with superuser privileges. In Debian you login as the Unix superuser 'root' and all the commands you enter automatically have the maximum privileges.

Debian GNU/Linux 6.0 deb604 tty1
deb60 login: root
Password: XXXXXX 
(message of the day)
root@deb604: ~#

The convention in Ubuntu is to be logged in as a non-privileged user and prepend every command with 'sudo' (do as superuser) to give it full privileges. For example:

Ubuntu 10.04.3 LTS ub1004 tty1
ub1004 login: username
Password: XXXXXX
$ reboot
reboot: must be superuser.
$ sudo reboot
[sudo] password for username: XXXXXX
... The system is going down for reboot NOW!

Adding sudo to every command in a long list of commands becomes tedious. Therefore in this article we assume that the non-privileged user has taken over a privileged shell by executing sudo with the option -i. From then on there is no need for the 'sudo'.

$ sudo -i
[sudo] password for username: XXXXXX
# reboot                   ; you don't need sudo anymore!

Version history:

  • V 0.1 2012-02-10 (ratna) First draft, the OS and structure
  • V 0.2 2012-02-11 (ratna) Apache, more on type, table structure for network configs
  • V 0.3 2012-02-14 (ratna) MySQL, tar, CVS
  • V 0.4 2012-02-25 (ratna) Ubuntu 10.04, MySQL, Moodle 1.6.9, 1.9.16 finished
  • V 0.5 2012-03-01 (ratna) Basic LAMP ready. ToDo lighttpd, phpMyAdmin, PostgreSQL
  • V 0.6 2012-04-10 (ratna) phpMyAdmin, basic git
  • V 0.7 2012-04-15 (ratna) lighttpd, PostgreSQL removed
  • V 0.8 2012-04-30 (ratna) Ubuntu 12.04 LTS tested
  • V 0.9 2012-05-21 (ratna) Intro broken into subsections

Install Linux

Install the system software

There are numerous ways of installing Linux. Usually one boots the computer initially from an external system, like a CD-ROM or USB memory stick, and then install the OS into an internal drive. This guide summarizes the steps during installation from a CD-ROM or an USB memory stick. For more details refer to the documentation of your distribution.

Important:

  • Do a minimal installation: i.e. no server components yet
  • If for a server, do not install a GUI. For a server, you are strongly recommended to get a server distribution, they don't have a graphical interface (GUI). In the case of Debian, the basic installation installs no GUI - and in the case of Ubuntu, the Server edition installs no GUI by default.
Debian 6.0 Ubuntu Server 10.04 LTS
  1. Boot from CD-1, in the Installer boot menu select 'Install' (not 'Graphical Install')
  2. Language for the installation process. It will also be the default language for the installed system.
  3. Location
  4. default locale, most likely en_US.UTF-8
  5. Keymap
  6. (Needs some time to detect hardware, load modules, try to configure the network via DHCP) Hostname
  7. Domain name. If proper server with DNS, enter your domain.
  8. Set a root password
  9. Set an account for a for a non-privileged user
  10. Partition disks: Guided or manual
  11. Finish partitioning, write the changes to disk.
  12. (Takes time to copy software)
  13. Configure the network mirror. Choose one closest to you. If your network has a HTTP-Proxy enter next or leave empty.
  14. Checking repositories, configuring apt, scanning the mirror...
  15. Important: In the final "Software selection", accept the default 'Standard system utilities" - don't tick anything else. This is the minimal installation mentioned above.
  16. Install Grub, in the boot sector: Yes
  17. Installation complete. Continue to reboot the new system.
  18. Boots through Grub
  19. Login as root
  20. Edit /etc/apt/sources.list to comment the line 'deb cddom: Official ...CD Binary .../ squeeze main'. Otherwise software update wants to read the CD all the time.
  1. Boot the machine from a bootable CD or memory stick
  2. Select the language of the boot screen
  3. The boot screen appears, select 'Install Ubuntu Server'
  4. Choose the language for the installation process (this will also be the default language of the final system)
  5. Choose the country where the machine is located
  6. Origin of the keyboard
  7. Keyboard layout
  8. Enter the host a name. We'll call it simply hostname
  9. Select the time zone where the computer is located
  10. Partition disks. The simplest variation would be 'Guided - user entire disk'
  11. Choose the correct disk, confirm writing the partition table to the disk
  12. "Installing the base system ..." (takes a couple of minutes)
  13. You are supposed to create a non-privileged user. Set a password - and don't forget those!
  14. Encrypting home partition: No
  15. HTTP-Proxy: Very likely to be none (empty). Your network administrator should tell you otherwise
  16. How do you want to manage upgrades? You are free, 'Install security updates automatically' won't be bad idea
  17. Software selection: In the list 'Software selection', select only 'OpenSSH server' - nothing else! (This is the 'minimal' installation mentioned above.)
  18. Further software will be copied..., 'Install the GRUB boot loader to the master boot record?' Yes
  19. Install finishes. Before rebooting requests you to remove the install media!

Table 2. Dialog during the installation of Linux

Configure network

stand alone LAN only Internet
You only need the 'localhost'. Therefore the /etc/network/interfaces file will be:
auto lo
iface lo inet loopback

The /etc/hosts file will define the localhost and a hostname

127.0.0.1        localhost
127.0.1.1        hostname
In a LAN you need an IP address, most likely a private address. Your /etc/network/interfaces will be accordingly:
auto lo
iface lo inet loopback

auto interface
iface interface inet static
  address the.ip.address
  netmask your.net.mask

and your /etc/hosts will define:

127.0.0.1          localhost
the.ip.address    hostname 
If the computer is in the Internet, it will also have a 'gateway' and access to a domain name server. See to that your server name is properly resolved in the Internet. (ping yourserver.your.domain should show you the right IP-address, etc.) You must contact your hoster or the network administrators for further details.
auto lo
iface lo inet loopback

auto interface
iface interface inet static
  address the.ip.address
  netmask your.net.mask
  gateway your.gateway

and your /etc/hosts will contain your domain name:

127.0.0.1        localhost
the.ip.address  hostname.your.domain  hostname

Table 3. Network configurations

Update the system software

# apt-get update           ; updates the package list
# apt-get upgrade          ; upgrade the outdated packages

Install Apache

# apt-get install apache2          ; the 'meta package' apache2 fetches a whole lot
                                   ; of packages like ...
... apachd2-mpm-worker apache2-utils apache2-bin apache2-common ...
...

Once successfully completed the installation script starts the server daemon. Check it by calling the test page as described in the table below. You should get the "It works" page.

stand alone LAN only Internet
Visit the URL http://localhost/ in a browser in your computer from another computer in the LAN visit http://the.ip.address/ in a browser from any computer in the Internet visit the site http://the.dns.name/

Table 4. Testing Apache installation By Default Apache display the contents of /var/www/, which Apache calls the 'DocumentRoot'. This and all other configuration parameters of Apache are to be found under /etc/apache2/. See the relevant documentation in http://httpd.apache.org/docs/.

If you want to restart the web server in the future, you can do so by restarting the boot script:

# /etc/init.d/apache2 restart

Install MySQL

# apt-get install mysql-server
mysql-client-5.1 mysql-common mysql-server mysql-server-5.1 mysql-server-core-5.1
...
New password for the MySQL "root" user:
[       ]    ; don't forget it!
Setting up mysql-server ...

Test the success by logging in with the MySQL client:

# mysql -u root -p
Enter password: XXXXXX
...
mysql>                    ; you should be able to login successfully

Install PHP

PHP Core

# apt-get install php5
... apache2-mpm-prefork libapache2-mod-php5 php5-common
...
The following packages will be REMOVED:
 apache2-mpm-worker
...
# /etc/init.d/apache2 restart   ; restart the web server for it to register the changes

Test the success by requesting phpinfo. For that you have to create a file in the webroot containing just a single call to phpinfo() and visit it in the browser:

# editor /var/www/moodle/phpinfo.php   ; editor any text editor: nano, vi, ...
; add the single line below, save and exit.
<?php phpinfo(); ?> 
stand alone LAN only Internet
Visit http://localhost/moodle/phpinfo.php in the same computer. Visit http://the.ip.address/moodle/phpinfo.php from any computer in the LAN. Visit http://dnsname.of.server/moodle/phpinfo.php from any computer in the Internet.

Table 5. Checking phpinfo Keep in mind to delete this file once the installation is over. It gives too much information to potential intruders! Later the Moodle administrator has access to this information by visiting http://your.server/moodle/admin/phpinfo.php. # rm /var/www/moodle/phpinfo.php  ; phpinfo() gives away information to intruders!

PHP Modules

; All versions of Moodle need the following two modules
# apt-get install php5-gd php5-mysql 
; Since version 2.0 Moodle needs the following additional modules 
# apt-get install php5-curl php5-xmlrpc php5-intl

You need to restart Apache for it to register the new modules:

# /etc/init.d/apache2 restart

If you need to change configuration of the PHP modules for Apache2, the configuration file is /etc/php5/apache2/php.ini.

PHP CLI

# apt-get install php5-cli             ; possibly only Ubuntu requires this, in Debian comes with the core

You can check the version of the PHP interpreter with:

# /usr/bin/php -v
PHP 5.3.3-7+squeeze8 with Suhosin-Patch (cli) ...

Notice that the configuration file for the PHP CLI is /etc/php5/cli/php.ini.

Install Moodle

Get the code

By downloading the tar-archive

; Get the archive you need:
# wget http://download.moodle.org/download.php/direct/stable16/moodle-1.6.9.tgz
# wget http://download.moodle.org/download.php/direct/stable17/moodle-1.7.7.tgz
# wget http://download.moodle.org/download.php/direct/stable18/moodle-1.8.14.tgz
# wget http://download.moodle.org/download.php/direct/stable19/moodle-latest-19.tgz
# wget http://download.moodle.org/download.php/direct/stable20/moodle-latest-20.tgz
# wget http://download.moodle.org/download.php/direct/stable21/moodle-latest-21.tgz
# wget http://download.moodle.org/download.php/direct/stable22/moodle-latest-22.tgz
# wget http://download.moodle.org/download.php/direct/moodle/moodle-latest.tgz ; development version

The URLs above are taken from the official download site http://download.moodle.org/. Refer that page for more details.

; Untar the archive to /var/www/moodle
# tar xzvf moodle-whatever.tgz -C /var/www 

Download via CVS

# apt-get install cvs         ; 'course you need a CVS client
# cd /var/www
# cvs -d:pserver:anonymous@SERVER.cvs.moodle.org:/cvsroot/moodle login
CVS password:                 ; no password, just press Enter
; Select one of these:
# cvs -z3 -d:pserver:anonymous@SERVER.cvs.moodle.org:/cvsroot/moodle co -P -r MOODLE_169 moodle
# cvs -z3 -d:pserver:anonymous@SERVER.cvs.moodle.org:/cvsroot/moodle co -P -r MOODLE_17 moodle
# cvs -z3 -d:pserver:anonymous@SERVER.cvs.moodle.org:/cvsroot/moodle co -P -r MOODLE_18 moodle
# cvs -z3 -d:pserver:anonymous@SERVER.cvs.moodle.org:/cvsroot/moodle co -P -r MOODLE_19 moodle
# cvs -z3 -d:pserver:anonymous@SERVER.cvs.moodle.org:/cvsroot/moodle co -P -r MOODLE_20 moodle
# cvs -z3 -d:pserver:anonymous@SERVER.cvs.moodle.org:/cvsroot/moodle co -P -r MOODLE_21 moodle
# cvs -z3 -d:pserver:anonymous@SERVER.cvs.moodle.org:/cvsroot/moodle co -P -r MOODLE_22 moodle

For details see: https://docs.moodle.org/en/CVS_for_Administrators

Download via Git

# cd /var/www
# git clone git://git.moodle.org/moodle.git
; will pull the latest (unstable) to a subdirectory 'moodle', takes couple of minutes!

For details, see <a href="https://docs.moodle.org/en/Git_for_Administrators">Git for Administrators</a>.

Setup the moodledata directory

# mkdir /var/moodledata         ; This has to be above the Apache Document Root /var/www
# chown www-data /var/moodledata  ; Apache server needs write permissions to moodledata

Create a database and a user

# mysql -p
Enter password:
mysql> CREATE DATABASE dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
query OK, 1 row affected (0.03 sec)
mysql> GRANT ALL PRIVILEGES ON dbname.* TO 'dbuser'@'localhost' IDENTIFIED BY 'dbpass';
Query OK, 0 rows affected (0.00 sec)
mysql> exit

Check the correctness by accessing the new database as dbuser:

# mysql -u dbuser -p
Enter password: [dbpass]
mysql> use dbname;
...
Database changed

Run the installation script

Before starting the installation script, make the moodle directory writable to the web server. This is needed for the configuration file config.php to be created.

# chown www-data /var/www/moodle

Initiate through the browser

stand alone LAN only Internet
Visit http://localhost/moodle from a browser within the computer From any computer in the LAN, call http://the.ip.address/moodle/ From any computer in the Internet, call http://dnsname.of.server/moodle/

Table 6. Initiate through the browser

Alternatively run the PHP CLI script

# php /var/www/moodle/admin/cli/install.php

The installation procedure is self-explanatory. Important parameters to remember note are:

Web address: http://localhost/moodle or http://the.ip.address/moodle or http://dnsname.of.server/moodle
Moodle Directory: /var/www/moodle
Data Directory: /var/moodledata
Type: Improved MySQL (native mysqli)
Database host: localhost
Database name: dbname
Database user: dbuser
Database password: dbpassword

These parameters get written to config.php, as in this example:

$CFG->dbtype    = 'mysqli';           // 'pgsql', 'mysqli', 'mssql' or 'oci'
$CFG->dblibrary = 'native';           // 'native' only at the moment
$CFG->dbhost    = 'localhost';        // eg 'localhost' or 'db.isp.com' or IP
$CFG->dbname    = 'dbname';           // database name, eg moodle
$CFG->dbuser    = 'dbuser';           // your database username
$CFG->dbpass    = 'dbpasssword';      // your database password
...
$CFG->wwwroot   = 'http://localhost/moodle'; // or http://the.ip.address/moodle or http://dnsname.of.server/moodle
$CFG->dataroot  = '/var/moodledata';

Congratulations! Now you are the owner of a shiny Moodle site! Don't foget to secure the moodle directory and config.php though:

# chown root /var/www/moodle
# chown root:root /var/www/moodle/config.php
# chmod 644 /var/www/moodle/config.php

Setup cron

The script cron.ini has to be run regularly for Moodle to finish pending tasks like sending forum posts as mail. You could add a line to the roots crontab.

# crontab -e
; add a single line similar to the following, save and exit.
*/15 * * * *        /usr/bin/php /var/www/moodle/admin/cron.php      ; for Moodle 1.x
*/15 * * * *        /usr/bin/php /var/www/moodle/admin/cli/cron.php  ; for Moodle 2.x

See https://docs.moodle.org/en/Cron_with_Unix_or_Linux for details.

Optionally, install phpMyAdmin

# apt-get install phpmyadmin
dbconfig-common javascript-common libjs-mootools libmcrypt4 php5-mcrypt ...
...
Web server to reconfigure automatically:
  [*] apache2              ; select Apache
  [ ] lighttpd
Configure database with dbconfig-common? Yes
Enter MySQL root password;
stand alone LAN only Internet
w3m http://localhost/phpmyadmin/ From any computer in the LAN, call http://the.ip.address/phpmyadmin/ From any computer in the Internet, call http://dnsname.of.server/phpmyadmin/

Table 7. Call phpMySQL

Appendix

External links