Workshop - Moodle Server Setup



Description: Participants will learn how to setup Moodle by setting up an UbuntuLinux server on a local machine (laptop). This process translates to the setup for a server in your own district. Preferred device: laptop of running UbuntuLinux. Other operating systems are supported on this web site.
external image energizer.png
Image Source: Adapted from http://goo.gl/YTCRv

Facilitator: Miguel Guhlin (Email: mguhlin@gmail.com; Twitter: mguhlin)

Install Checklist
PART 1 -
external image checkbox.png Review videos/materials first
external image checkbox.png Download install software
external image checkbox.png Install server software relevant to your computer's operating system.

PART 2 -
external image checkbox.png Modify the php.ini file.
external image checkbox.png Create necessary folders/directories to house MoodleData and MoodlePHP files
external image checkbox.png Create the database you need to house Moodle content

PART 3 -
external image checkbox.png Create the MySQL user who will have only localhost access to the Moodle.
external image checkbox.png Secure your server
external image checkbox.png Install phpMyAdmin

external image ServerUBUNTU.png

Source: http://cloud.ubuntu.com/wp-content/uploads/2011/10/ServerUBUNTU.png


Step 1 - Install the Software You Need
At the command line/terminal, type the following...be ready to write down/remember any usernames and passwords that you are asked to create through the next two steps.

  • sudo apt-get install tasksel

Per Ubuntu web site, //Tasksel// is a Debian/Ubuntu tool that installs multiple related packages as a co-ordinated "task" onto your system. We will use that to install Apache/MySQL server:

Step 2 - Install Apache/MySQL

  • sudo tasksel install lamp-server

Once this step is complete, you should be able to go to http://localhost and see a message saying something along the lines of "It Works!" etc. You will get some errors if you don't take the next step:

a) Edit the httpd.conf file

  • sudo nano /etc/apache2/httpd.conf
This will create a blank file to which you can paste the following into the body:
  • ServerName localhost

b) Restart the web server with the command below:
  • sudo /etc/init.d/apache2 restart
Note that you can stop the server with this command:
  • sudo /etc/init.d/apache2 stop
...or "start" it by replacing the word "stop" in the command above.

Step 3 - Install PHP and Other Needed Extensions
Below are steps that you will need to take (there might be some slight overlap) to setup PHP and other needed components for Moodle. You will want to take each line one by one (although you can also combine them as you see fit):


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


Replace MySQL with MariaDB


At the command line type:
lsb_release -a - this command will tell you what Debian distro you have. Here's what I saw when I typed it on mine:

  • $ lsb_release -a

  • No LSB modules are available.

  • Distributor ID:Debian

  • Description:Debian GNU/Linux 7.0 (wheezy)

  • Release:7.0

  • Codename:wheezy

Notice that Debian wheezy is what you have...keep that in mind.

cd /etc/apt/sources.list.d - this command will switch you over to the appropriate directory.

sudo leafpad mariadb.list - this command will open the leafpad text editor and create a file called "mariadb.list" which is where we'll put the info we're going to copy from the next step.

Switch to your Internet browser, and go to this web site.
https://downloads.mariadb.org/mariadb/repositories/

You will be asked to make some choices...here's what they look like:
external image Selection_003.png


You just choose a distro (e.g. Debian), a release (wheezy), a version (e.g. 10 (the 5.5 didn't work for me), and a mirror (e.g. I chose the one with the American flag, osuosl).

Scroll down and you will see more info:


Paste the code below into that leafpad text editor window you started earlier for the mariadb.list file:
<span style="background-color: #f5f5f5; font-family: Monaco,Menlo,Consolas,'Courier New',monospace; font-size: 12px;"><span style="background-color: transparent; color: inherit; font-family: Monaco,Menlo,Consolas,'Courier New',monospace; font-size: 11px;">#</span> MariaDB 10.0 repository list - created 2013-02-17 14:18 UTC
<span style="background-color: transparent; color: inherit; font-family: Monaco,Menlo,Consolas,'Courier New',monospace; font-size: 11px;">#</span> <span style="color: #0088cc; text-decoration: initial;">[[http://mariadb.org/mariadb/repositories/]]</span>
deb <span style="color: #0088cc; text-decoration: initial;">[[http://ftp.osuosl.org/pub/mariadb/repo/10.0/debian]]</span> wheezy main
deb-src <span style="color: #0088cc; text-decoration: initial;">[[http://ftp.osuosl.org/pub/mariadb/repo/10.0/debian]]</span> wheezy main</span>




Exit Leafpad text editor, saving the mariadb.list file. If you type ls -lh you will get a directory listing showing the mariadb.list file:

external image Selection_004.png



type the following at the command line (these instructions will also be on the MariaDB web site)

<span style="background-color: #f5f5f5; color: #333333; font-family: Monaco,Menlo,Consolas,'Courier New',monospace; font-size: 12px;">**sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db**
 
**sudo apt-get update**
 
**sudo apt-get install python-software-properties**
 
<span style="background-color: #ffffff; font-family: 'Trebuchet MS',Trebuchet,Verdana,sans-serif;">To complete the install, type the following:</span>
 
**<span style="background-color: #ffffff; font-family: 'Trebuchet MS',Trebuchet,Verdana,sans-serif;">sudo apt-get install mariadb-server</span>**<span style="background-color: #ffffff; font-family: 'Trebuchet MS',Trebuchet,Verdana,sans-serif;"> - this will install MariaDB server. You will be notified that MySQL will be removed, but...no problem. You will also be asked to type in the root password for your MariaDB just like you did with MySQL.</span></span>


Step 4 - Install AntiVirus
  • sudo apt-get install clamav-base clamav-freshclam clamav

This will install antivirus tools on the server.

Step 5 - Edit the PHP.ini file

  • sudo nano /etc/php5/apache2/php.ini

Note that you can replace the word "nano" with your text editor of choice, such as vim or leafpad or gedit (the latter two can only be used in a GUI environment, while vim and nano can be used at the command line in text-only environment).
You will want to make--at minimum--the following adjustments:

  • display_errors = Off
  • display_startup_errors = Off
  • register_globals = Off
  • post_max_size = 2000M
  • mysql.connect_timeout = -1
  • max_execution_time = 5000
  • max_input_time = 5000
  • memory_limit = 2000M
  • file_uploads = On
  • upload_max_filesize = 2000M

At this point, you will want to restart the server with the following command
sudo /etc/init.d/apache2 restart

and begin the process of copying Moodle to the appropriate location, probably /var/www/moodledirectory
Step 6 - Installing Moodle
To install Moodle, you will need to do some command line magic with MySQL and copying-n-pasting stuff. Below are my rough notes on the subject:

a) Create MySQL database and a MySQL user @ localhost that will be used during Moodle install configuration

  • #mysql -u root -p create database sandbox default character set utf8;

  • grant all privileges on sandbox.* to 'moodleuser'@'localhost' identified by 'yourpassword';

  • flush privileges;

  • quit
Note that "sandbox" , "moodleuser" could be replaced to be anything else. You can create additional users and assign them rights:
  • mysql> CREATE USER 'mguhlin'@'localhost' IDENTIFIED BY 'PASSWORD';

  • mysql> GRANT ALL PRIVILEGES ON *.* TO 'mguhlin'@'localhost' WITH GRANT OPTION;
In the scenario above, a user "mguhlin" is being created.

b) Create Moodledata folder
You will need to create a MoodleData directory. Here's the command to do it:

  • sudo mkdir /var/moodledata
Since I like to put all my Moodle instances' MoodleData folders as subdirectories of MoodleData, I would create new subdirectories in the following way:
  • sudo mkdir /var/moodledata/sandbox
If I needed to assign write access, I would probably do something like the following:
  • sudo chmod -R 777 /var/moodledata
c) Download the Moodle installation file
From the command line, you can download the Moodle installation file. For example:

should enable you to download the Moodle file. Once downloaded, you can unzip the file in this way:
  • unzip moodle-latest-22.zip
By the way, if the wget command pulls up a blank file (not one that is 30-40 megs in size), you may want to get the direct link for the Moodle install file download (click on the regular link and then before it starts to download, copy-n-paste the link for "direct link"). I sometimes use a URL shortener (goo.gl) to get a shorter link to work with if I have to type, rather than copy-n-paste, the link into the Terminal window.

d) Create folder where Moodle PHP files will be stored.
To create the folder where you will store the Moodle PHP files--these are the files you extracted after downloading and unzipping the file from above. You can create the folder with this command:

sudo mkdir /var/www/sandbox

where sandbox is the name of the proposed Moodle instance.

Then copy the contents of your downloaded, unzipped Moodle install file with this command:

  • sudo cp -rv /home/yourusername/moodle/* /var/www/sandbox/
e) Begin the web-based install process
Go to your web browser and type in the URL of the server, or, if on your own computer, type

You should see the start of the Moodle installation. Follow the steps suggested. After you've installed Moodle, you should see everything pop up as normal.
f) Configuring Moodle (View Video Walkthrough)
After the installation of Moodle, you'll be asked to do some configuration of Moodle.
# Session Handling (View Video) - How to Deploy Multiple Moodle Instances on one server with different cookies

  1. Setting Up CRON Jobs (View Video: Part 1 | Part 2) - Read more about what is Cron. Use the Moodle Cron package. The simplest way is to use this little package MoodleCron-Setup.exe, which makes this whole thing very easy by installing a small Windows service. Run it and forget about it! :-)
  2. Managing Courses
    1. Course Default Settings with a quick overview of group settings (View Video)
    2. Course Categories (View Video)
    3. Backing Up and/or Duplicating from Restored Course (View Video)
    4. Restoring Courses (View Video)
Some additional topics:

C. Moodle User Authentication (View Video Walkthrough) - How do users login to Moodle?

D. Adding Modules/Blocks/Themes to Moodle (View Video Walkthrough)# How to Install Blocks/Modules into Moodle

  1. How to Install Themes into Moodle

Step 7 - Cron Job Setup
Your Moodle will need to occasionally run cron jobs. Why is the cron job important?

  • Cron assists some of Moodle's modules to perform tasks on a scheduled basis. For example, the cron process might tell Moodle to check all discussion forums so it can mail out copies of new posts to people who have subscribed to that forum. The primary Moodle script that does all this is located in the admin directory, and is called cron.php. However, it can not tell itself to run, so you need to set up a mechanism where this script is run regularly (eg every five or ten minutes). This provides a "heartbeat" so that the script can perform functions at periods defined by each module.

You can edit the cron job in the following way:
  • env EDITOR=nano crontab -e
Paste in a modified line of instructions for every Moodle instance you have running on the server:
Note that this line of instruction will run the cron job every 10 minutes. There are other ways of accomplishing this task, so be open to the possibilities!

To edit cron jobs, go to /etc/cron.weekly, /etc/cron.hourly, /etc/cron.monthly. For example:

  • cd /etc/cron.weekly

Optional Step A - OPENSSHIf you want to have a secure (SSL) installation of Moodle--which may result in a performane hit--or simply do SSL for your Moodle logins, you will need to take the following step BEFORE (although I did it after as long as you are comfortable moving (mv) files and folders around) your start installing Moodle. Please note that I found this tutorial helpful for moving beyond this point.
  • sudo apt-get install openssh-server unattended-upgrades
These steps are relevant and I encourage you to follow this tutorial in two parts...Be aware that the original info is offline, so this is my Evernote copy of it..Thanks, Evernote!)

Extra Information

Quick Upgrade of a Moodle Instance
  1. Backup Your Moodle Database (View Tutorial)
  2. Backup your config.php file in your Moodle directory in htdocs
  3. Download the latest version of Moodle 2.2.x to your computer.
  4. Copy your old Moodle's themes, mods and blocks--this is a good time to upgrade
    them--into the new Moodle version you've downloaded from Moodle.org
  5. Delete everything else in your Moodle directory in htdocs EXCEPT the config.php
    file.
  6. Copy the contents of the new Moodle 1.9+ into your old directory.
  7. Go to http://localhost/moodlename/admin to complete installation

4 - Migrating to Moodle 2.x from Moodle 1.9.x
  1. Migrating Database from 1.9 to 2.0 readiness
  2. Download the latest version of Moodle 2.x to your computer.
  3. Copy your old Moodle's themes, mods and blocks--this is a good time to upgrade
    them--into the new Moodle version you've downloaded from Moodle.org
  4. Delete everything else in your Moodle directory in htdocs EXCEPT the config.php
    file.
  5. Copy the contents of the new Moodle 2.x into your old directory.
  6. Go to http://localhost/moodlename/admin to complete installation.

Another version of instructions.