Installing Moodle on a Debian-based LAMP server

1. Get the Moodle code

1.a Install 

Install the Moodle package from the command-line interface and follow the prompts:
sudo apt-get install moodle

1.b Either by downloading the tar-archive

The Moodle download site[6] runs a script which fetches archives from the mirrors of sourceforge.net[7]. The logic is that moodle-X.Y.Z.tgz means the point release X.Y.Z and moodle-latest-XY.tgz stands for the version X.Y.latest+ of branches still supported. See the examples below:
# 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-2.0.10.tgz
# wget http://download.moodle.org/download.php/direct/stable21/moodle-2.1.10.tgz
# wget http://download.moodle.org/download.php/direct/stable22/moodle-latest-22.tgz
# wget http://download.moodle.org/download.php/direct/stable23/moodle-latest-23.tgz
# wget http://download.moodle.org/download.php/direct/stable24/moodle-latest-24.tgz
; or for 2.5dev
# wget http://download.moodle.org/download.php/direct/moodle/moodle-latest.tgz
Untar the archive to /var/www/, the Apache DocumentRoot. This will create a subdirectory moodle.
# tar xzvf moodle-whatever.tgz -C /var/www

1.b Or, get the code via Git

Git allows numerous ways of organizing your local repository. The example below shows the bare minimum to ‘clone’ a branch from the Moodle Git server. The BRANCH_TAG in this command could be something like MOODLE_19_STABLE to mean 1.9.latest+ or MOODLE_2210 meaning a the point release 2.2.10.
; install Git if you haven't done it already
# apt-get install git
; change the working directory to DocumentRoot
# cd /var/www
; clone the Moodle branch
# git clone -b BRANCH_TAG git://git.moodle.org/moodle.git
; or get the latest (developer) repository 
# git clone  git://git.moodle.org/moodle.git

2. Setup the moodledata directory

For file uploads Moodle needs a writable directory outside the Apache DocumentRoot.
# mkdir /var/moodledata
# chown www-data /var/moodledata

3. Create a database and a user

# mysql -u root -p
Enter password: [MySQL root 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
Make sure that the database access works:
# mysql -u dbuser -p
Enter password: [dbpass]
mysql> use dbname;
...
Database changed

4. Initialize Moodle

Before calling the installation script, make the moodle directory writable to the web server. This is necessary to allow the installer to create the configuration file config.php.
# chown www-data /var/www/moodle
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
The installation procedure is self-explanatory. Important parameters to remember are:
Web address:
Moodle Directory:
Data Directory:
Type:
Database host:
Database name:
Database user:
Database password:
Table prefix:
The correct one from the table above
/var/www/moodle
/var/moodledata
mysql in old versions or Improved MySQL (native mysqli) in newer versions
localhost
dbname
dbuser
dbpassword
mdl_ (the default, you are free to change)
A config.php file will be created and populated with the parameters above. You should get a confirmation message.
Then it will cycle through the copyright message and some initial parameters then continue to create a whole lot of database objects. Finally coming to the Site settings and then e-mail and password for the user 'admin'.
Note: If you have MySQL 5.5 or above, Moodle 1.6 will break. The problem is that new MySQL 5.5 has a different syntax for CREATE TABLE. Instead of TYPE=MyISAM (or InnoDB) it requires ENGINE=MyISAM. http://dev.mysql.com/doc/refman/5.5/en/myisam-storage-engine.html. Change the offending CREATE TABLE in Moodle 1.6!
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

5. Setting up cron

The script cron.php in Moodle has to be called regularly for it to finish pending tasks like sending copies of forum posts. You could add a line to the roots crontab.
# crontab -e
*/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
For details see http://docs.moodle.org/en/Cron_with_Unix_or_Linux.

6. 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;
 
If your get error 404, type sudo ln -s /usr/share/phpmyadmin /var/www
 
to uninstall phpmyadmin, apt-get install phpmyadmin
 
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/

 

7. Upgrading Moodle

  • Copy the Moodle software directory as a backup:
    sudo cp -r /var/www/moodle /var/www/moodle_bak
  • Copy the Moodle data directory as a backup:
sudo cp -r /var/moodle /var/moodle_bak
  • Copy the local Moodle configuration directory as a backup:
sudo cp -r /etc/moodle /etc/moodle_bak
  • Dump your MySQL database content:
mysqldump -u username -p -C -Q -e --create-options moodle > moodle-backup-2013-04-01.sql

Comments

Popular posts from this blog

How to Install ‘IPFire’ Free Firewall Linux Distribution

Working with Columns on the Joomla Frontpage