Note: You are currently viewing documentation for Moodle 3.6. Up-to-date documentation for the latest stable version of Moodle is likely available here: Step-by-step Installation Guide for Ubuntu.

Step-by-step Installation Guide for Ubuntu: Difference between revisions

From MoodleDocs
No edit summary
(87 intermediate revisions by 15 users not shown)
Line 1: Line 1:
== Step 1: Install Ubuntu 12.04LTS==
{{Installing Moodle}}
{{Note|This document is about installing Moodle 3.6 in an Ubuntu 18.04 server with PHP 7.2.}}


<br>Server Edition amd64 Preferred<br>
==Before you begin==
<br>http://www.ubuntu.com/download<br>
It is a good idea to write down the passwords (and usernames) you will need to use for Ubuntu and Moodle:
* The Ubuntu root password
* The MySQL username and password that Moodle will use
* The Moodle main admin username and password
* An additional admin Moodle username and password
== Step 1: Install Ubuntu ==


*If you are reading this after April 2014 then USE Ubuntu Server 14.04LTS amd64
===Why we prefer Ubuntu server over Ubuntu desktop===
* Most IT professionals prefer to use a Command Line Interface (CLI) server, because it is safer and less prone to hacking.
* Amateur users might find it easier to use a graphical (desktop) interface.
* If you will only be using your Moodle server for local, experimental purposes, you might prefer to install the desktop (64 bits preferred) version of Ubuntu.
* If you install a CLI only server and later regret it, you can easily add a graphical desktop:
{{Note| Even though it is not recommended by most experts, you could install a Graphical User Interface (desktop) by issuing the command 'sudo apt install ubuntu-desktop' to [https://help.ubuntu.com/community/ServerGUI install 'Ubuntu desktop']. BUT USE WITH CAUTION: The GUI may not appear as expected, and may prevent user from getting even the CLI. Try it at test machine first.}}
 
===Why we prefer (or don't prefer) Ubuntu 18.04 over Ubuntu 16.04 over Ubuntu 14.04===
* All three are LTS (Long Term Service) releases. <b>amd64 edition preferred.</b> <b>http://www.ubuntu.com/download</b>
* Ubuntu Server 18.04 has all the required packages (comes default with Apache2, [https://docs.moodle.org/dev/Moodle_and_PHP7 PHP 7.2], MySQL 5.7). Ubuntu Server 18.04 has some minor differences from 16.04 and 14.04, mainly PHP. This document has been updated to reflect those changes.
* Moodle 3.0.1 onwards can use [https://docs.moodle.org/dev/Moodle_and_PHP7 PHP 7.0]. Moodle 3.6 requries PHP 7.0.
* But beware that if you are using external authentication or enrollment plug-ins, please note that at the moment of Moodle 3.0.1 release (December 2015) neither MSSQL nor SQLSRV are available under php7. So, [https://docs.moodle.org/dev/Moodle_and_PHP7#Can_I_use_PHP7_yet.3F anybody using SQL*Server as primary database or remote auth/enrol plugin  should not move to PHP 7] at all ! Also, depending of your configuration, some extensions (memcached [https://docs.moodle.org/dev/Moodle_and_PHP7#Manually_installing_Memcached can be installed], redis, mongodb, xmlrpc...) maybe missing or work in progress for your distribution, triple check the exact availability for your OS.
 
===Procedure===
*Ubuntu has a well known issue with its automatic updates filling up the /boot directory until automated updates start to fail and automated removal of old kernel files from /boot is impossible. Because of this you should consider installing Ubuntu with a /boot directory of around 5Gb and putting some automated clean up in place. More info can be found here - [https://help.ubuntu.com/community/RemoveOldKernels]
 
*You can use either VI (lightweight editor) or VIM (heavyweight editor), however, if you wish to use VIM you will need to install it
<pre>sudo apt-get install vim</pre>
 
*VI or VIM Commands<br />
To edit a file press "Insert" Key<br />
To finish editing press "Esc" Key<br />
To write the file press ":w"<br />
To Exit the editor press ":q"<br />
You can also write and quit ":wq"
 
*In Ubuntu, the standard user, the account you created during the install, does not have rights to install/write to many of the directories. In the below tutorial we will be using the term "sudo" which stands for "super user do" before most of the commands.


== Step 2: Install Apache/MySQL/PHP ==
== Step 2: Install Apache/MySQL/PHP ==
{{Note| Moodle 3.0.1 [https://docs.moodle.org/dev/Moodle_3.0.1_release_notes introduced support for PHP 7.0 and we will be using PHP 7.2 in this tutorial]}}
Open up Terminal and install the following;
Open up Terminal and install the following;


<pre>sudo apt-get install apache2 mysql-client mysql-server php5</pre>  
<pre>sudo apt install apache2 mysql-client mysql-server php libapache2-mod-php</pre>  


''''It will prompt you to set the root password for mysql - take note of it, you will need it in step 6.'''
'''Run 'sudo mysql_secure_installation' to set the root password for mysql - please, please my dear friends, WRITE IT DOWN and spare yourself some grief, you will need it in step 6.'''


== Step 3: Install Additional Software ==
== Step 3: Install Additional Software ==


<pre>sudo apt-get install aspell php5-pspell php5-curl php5-gd php5-intl php5-mysql php5-xmlrpc php5-ldap</pre>
<pre>sudo apt install graphviz aspell ghostscript clamav php7.2-pspell php7.2-curl php7.2-gd php7.2-intl php7.2-mysql php7.2-xml php7.2-xmlrpc php7.2-ldap php7.2-zip php7.2-soap php7.2-mbstring</pre>


Restart Apache so that the modules are loaded correctly
Restart Apache so that the modules are loaded correctly
Line 21: Line 55:
<pre>sudo service apache2 restart</pre>
<pre>sudo service apache2 restart</pre>


We will be using Git to install/update the Moodle Core Application
We will be using [[Git]] to install/update the Moodle Core Application


<pre>sudo apt-get install git-core</pre>
<pre>sudo apt install git</pre>


== Step 4: Download Moodle ==
== Step 4: Download Moodle ==
Line 29: Line 63:
Setup your local repository and download Moodle, We will use /opt for this installation.
Setup your local repository and download Moodle, We will use /opt for this installation.


<pre>cd /opt
*[[Git]] is what is called a "version control system". By using [[Git|git]] it will much easier down the road to update the moodle core application. Within Step 5 there is a little more detail on why we put the moodle core application code in the /opt directory.
 
<pre>cd /opt</pre>
 
Download the Moodle Code and Index
 
<pre>sudo git clone git://git.moodle.org/moodle.git</pre>
 
Change directory into the downloaded Moodle folder
 
<pre>cd moodle</pre><br />


sudo git clone git://git.moodle.org/moodle.git
Retrieve a list of each branch available


cd moodle
<pre>sudo git branch -a</pre>


sudo git branch -a
Tell [[Git|git]] which branch to track or use


sudo git branch --track MOODLE_26_STABLE origin/MOODLE_26_STABLE
<pre>sudo git branch --track MOODLE_36_STABLE origin/MOODLE_36_STABLE</pre>


sudo git checkout MOODLE_26_STABLE</pre>
Finally, Check out the Moodle version specified


== Step 5: Copy local repository to /var/www ==
<pre>sudo git checkout MOODLE_36_STABLE</pre>


<pre>sudo cp -R /opt/moodle /var/www/</pre>
== Step 5: Copy local repository to /var/www/html/ ==
<pre>sudo mkdir /var/moodledata</pre>
 
<pre>sudo chown -R www-data /var/moodledata</pre>
<pre>sudo cp -R /opt/moodle /var/www/html/</pre><br />
<pre>sudo chmod -R 777 /var/moodledata</pre>
<pre>sudo mkdir /var/moodledata</pre><br />
<pre>sudo chmod -R 0755 /var/www/moodle</pre>
<pre>sudo chown -R www-data /var/moodledata</pre><br />
<pre>sudo chmod -R 777 /var/moodledata</pre><br />
<pre>sudo chmod -R 0755 /var/www/html/moodle</pre>
<br />
* Explanation:
<br />
Since we setup a local repository in the previous step, you will copy it to your webroot after any updates and making changes. Having your local repository outside of the webroot, like we have in /opt, you will be able to prepare and stage your upgrades in a more efficient manner. For example, you want to make some changes or add some plug-ins, you would download the plugin and copy it to your local moodle repository. After you have added the plug-in and any other changes you might have made you will need to edit the file located in /opt/moodle/.git/info/exclude. Within that file you want to tell [[Git|git]] which files/folders to exclude when it pulls down the updates when you run your next "sudo git pull". An example entry would be the certificate mod located in /opt/moodle/mod/certificate so within the exclude file you want to add "/mod/certificate" below the last comments. You would add additional entries, 1 per line, for each plug-in or file you might have changed. If I were to change the favicon.ico file you would just add "favicon.ico" to the exclude file. Now when you run "sudo git pull" to update moodle to the latest version it will ignore those files and directories and just update the core moodle code. Before copying to your webroot to upgrade you want to make sure and download and copy over the latest versions of the plug-ins you might have added.


== Step 6: Setup MySQL Server ==
== Step 6: Setup MySQL Server ==


First we need to change the default storage engine to innodb
First we need to change the default storage engine to innodb and change the default file format to Barracuda, this is a new setting compared to previous versions. You also need to set innodb_file_per_table in order for Barracuda to work properly. Ref: https://dev.mysql.com/doc/refman/5.6/en/innodb-compression-usage.html


<pre>sudo vi /etc/mysql/my.cnf</pre>
*You should not need to make innodb the default storage engine anymore, the latest version of Moodle will select it automatically during install. It is always a good idea to make it default anyway. You do however need to set the default file format!


Scroll down to the [mysqld] section and under Basic Settings add the following line under the last statement
*If you chose to use VIM instead please substitute vi for vim


<pre>default-storage-engine = innodb</pre>
<pre>sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf</pre>


<pre>:w</pre>
Scroll down to the [mysqld] section and under Basic Settings add the following line under the last statement. if you want to add you have to press the "insert" button on your keyboard. this is usually above the "delete" button. this allows you to add some text.
 
<pre>default_storage_engine = innodb</pre><br />
<pre>innodb_file_per_table = 1</pre><br />
<pre>innodb_file_format = Barracuda</pre>
 
In order to save my.cnf using the editor, press the Esc (Escape) key, type the following in sequence which will save :w then close the editor :q
 
<pre>:w</pre><br />
<pre>:q</pre>
<pre>:q</pre>


Line 66: Line 124:
<pre>sudo service mysql restart</pre>
<pre>sudo service mysql restart</pre>


Now we need to create the Moodle MySQL User with the correct permissions
Now we need to create the Moodle database and the Moodle MySQL User with the correct permissions


Use the password you created in step 1
Use the password you created in step 1
<pre>mysql -u root -p</pre>
<pre>sudo mysql -u root -p</pre><br />
mysql><pre>CREATE DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;</pre>
mysql><pre>CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;</pre>
 
{{Note| Use 'utf8mb4' for full range (4-byte) support of UTF-8, including Emoji ('utf8' only supports 3-byte). You will be compliant by Moodle admin page if you don't use 'utf8mb4' here.}}


Where it says "moodledude" and "passwordformoodledude" you should change to the username and password of your choosing.
Where it says "moodledude" and "passwordformoodledude" you should change to the username and password of your choosing.
mysql><pre>GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO moodledude@localhost IDENTIFIED BY 'passwordformoodledude';</pre>
mysql><pre>create user 'moodledude'@'localhost' IDENTIFIED BY 'passwordformoodledude';</pre><br />
mysql><pre>GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO moodledude@localhost IDENTIFIED BY 'passwordformoodledude';</pre><br />
mysql><pre>quit;</pre>
mysql><pre>quit;</pre>


Note - If you are using MySQL 5.6+ and when you issue the create user and get an error about the password hash you need to adjust the password to use the hash value
You can get this by following the below
mysql><pre>SELECT password('passwordformoodledude');</pre><br />
This will print the hash of the password like *AD51BAFB2GD003D3480BCED0DH81AB0BG1712535, you will want to use this in the IDENTIFIED BY ' part


== Step 7: Complete Setup ==
== Step 7: Complete Setup ==
*Note - If you are not comfortable using terminal to create the config.php file that needs to be created when going through the installer, you should temporarily make the webroot writable by doing the following:
<pre>sudo chmod -R 777 /var/www/html/moodle</pre>
After you have ran the installer and you have moodle setup, you NEED to revert permissions so that it is no longer writable using the below command.
<pre>sudo chmod -R 0755 /var/www/html/moodle</pre>


Open your browser and go to http://IP.ADDRESS.OF.SERVER/moodle  
Open your browser and go to http://IP.ADDRESS.OF.SERVER/moodle  


Follow the prompts selecting:
Follow the prompts:
 
===Change the path for moodledata===
 
/var/moodledata


===Database Type===
===Database Type===
Line 93: Line 173:
Database: moodle
Database: moodle


User: moodledude
User: moodledude (the user you created when setting up the database)


Password: passwordformoodledude
Password: passwordformoodledude (the password for the user you created)


Tables Prefix: mdl_
Tables Prefix: mdl_
Line 113: Line 193:
===Installation Complete ===
===Installation Complete ===
Congrats! You can now start using Moodle!
Congrats! You can now start using Moodle!
===Don't Forget===
If you made the webroot writable, revert permissions
<pre>sudo chmod -R 0755 /var/www/html/moodle</pre>


== System Paths After Install==
== System Paths After Install==
After installing Moodle you should set the system paths, this will provide better performance VS not setting them. Each entry in Moodle will have it's explanation.


After installing Moodle you should set the system paths.
Navigate, on the moodle webpage, to Site Administration > Server > System Paths
 
Navigate to Site Administration > Server > System Paths


Input the following;
Input the following;


Path to Du: /usr/bin/du
Path to du: /usr/bin/du


Path to Apsell: /usr/bin/aspell
Path to apsell: /usr/bin/aspell


Path to dot: /usr/bin/dot
Path to dot: /usr/bin/dot
Line 130: Line 214:
Save Changes
Save Changes


== Suggestions: Install APC/Change Document Root==


*Ignore this if you installed Ubuntu Server 14.04LTS then you can use the built-in PHP OPcache, https://docs.moodle.org/36/en/OPcache
*Optional if you do not already have an AntiVirus Solution
 
We also installed ClamAV in Step 3 so we need to set the path in Moodle
 
1st Create the Quarantine Directory
<pre>sudo mkdir /var/quarantine</pre>
Change Ownership
<pre>sudo chown -R www-data /var/quarantine</pre>
 
Navigate to Site Administration > Plugins > Antivirus plugins  >  Manage antivirus plugins
 
Enable ClamAV antivirus
 
Click on Settings
 
Set the proper settings
 
Save changes
 
In previous Moodle branches:
Check "Use ClamAV on uploaded files"
ClamAV Path : /usr/bin/clamscan
Quarantine Directory : /var/quarantine
 
Save Changes
 
== Suggestions: Enable Zend OpCache/Change Document Root==
 
*Since we have installed Ubuntu Server 14.04LTS, we can use the built-in PHP OPcache, https://docs.moodle.org/26/en/OPcache


Highly suggest that you install a PHP Accelerator, We will use APC for this install.
Within the link above, https://docs.moodle.org/26/en/OPcache add the recommended settings to your 05-opcache.ini file. Again, substitute vi with vim and remember to use the correct key squences from the introduction.


<pre>sudo apt-get install php-apc</pre>
<pre>sudo vi /etc/php5/apache2/conf.d/05-opcache.ini</pre>
 
NOTE: In Ubuntu 16.04 opcache.ini is located in:
 
<pre>/etc/php/7.0/mods-available/opcache.ini</pre>


Restart Apache for changes to take affect.
Restart Apache for changes to take affect.
Line 142: Line 257:
<pre>sudo service apache2 restart</pre>
<pre>sudo service apache2 restart</pre>


That's it for the PHP Accelerator!
That's it for the Zend OpCache!
 
You can also install a GUI to view the status of your Zend OpCache, not recommended on production servers.
 
<pre>cd /var/www/html/moodle/</pre>
 
Download the PHP Script to your Moodle directory, you should also add this file to /opt/moodle/.git/info/exclude file so it does not get removed when upgrading your installation.


Don't like http://ip.address.of.server/moodle?
<pre>sudo wget https://github.com/rlerdorf/opcache-status/blob/master/opcache.php</pre>


Open up Apache Config and change the document root
Visit http://ip.address.of.server/moodle/opcache.php


<pre>sudo vi /etc/apache2/sites-available/default</pre>
If you do not want your end users to type http://yourserver/moodle and just want them to navigate to http://youserver you will need to edit the site configuration for Apache which will tell Apache to use the /var/www/html/moodle as the root directory and not /var/www/html


On 2nd or 3rd line where DocumentRoot is;
Open up the Apache sites config and change the document root


<br>Change From: DocumentRoot /var/www<br>
<pre>sudo vi /etc/apache2/sites-available/000-default.conf</pre>
<br>Change To:  DocumentRoot /var/www/moodle<br>


Scroll down a little farther where it says <Directory /var/www/>
On the line where DocumentRoot is;


<br>Change From: <Directory /var/www/><br>
<br>Change From: DocumentRoot /var/www/html<br>
<br>Change To:  <Directory /var/www/moodle/><br>
<br>Change To:  DocumentRoot /var/www/html/moodle<br>


<pre>:w</pre>
<pre>:w</pre>
Line 170: Line 290:


If you have already installed Moodle then you should make the below changes.
If you have already installed Moodle then you should make the below changes.
== Editing config.php for moodle ==
In the installation instructions, one of the suggested settings for 'webroot' is 'localhost'. This is fine if all you want to do is some local testing of your new Moodle installation. If, however, you want to view your new installation from another machine on the same local area network, or view your site on the Internet, you will have to change this setting:
For local testing, 'localhost' is fine for the webroot ($CFG->wwwroot in config.php).
If you want to test your site from other machines on the same local area network (LAN), then you will have to use the private ip address of the serving machine, (e.g. 192.168.1.2/moodle) or the network name of the serving computer (e.g. network_name_of_serving_machine/moodle) as the web root. Depending on your LAN setup, it may be better to use the network name of the computer rather than its (private) ip address, because the ip address can and will change from time to time. If you don't want to use the network name, then you will have to speak to your network administrator and have them assign a permanent ip address to the serving machine.
Finally, if you want to test your new installation across the internet, you will have to use either a domain name or a permanent (public) ip address/moodle as your web root. To handle both types of access, see masquerading.


Edit config.php for Moodle
Edit config.php for Moodle


Under $CFG->wwwroot change to http://ip.address.of.server/ instead of http://ip.address.of.server/moodle
cd /var/www/html/moodle
sudo vim config.php
 
Hit the "insert" button on your keyboard, make then changes you need to make. Then press "escape" and type the following in to quit and to save changes (excluding quotation marks): ":wq"
 
Under $CFG->wwwroot change to http://ip.address.of.server instead of http://ip.address.of.server/moodle
 
 
==Hosting several Moodle branches in one Ubuntu server==
* This is very useful for the language pack maintainers to test translations in several Moodle branches.
* It is also very useful for developers to test their plugins in different Moodle branches.
* Just create a folder for each instance inside the web folder and that would be enough.
* To access the sites you only need to add the folder to localhost URL: http://localhost/moodle31
* You can have an instance for each version from 1.9 to 3.1
 
* You do need a separate data folder for each instance and a separate database (You can use phpmyadmin to set your database, but that's not necessary), add each instance in its own folder, and carry on as above. You can also host another service (eg, Mahara) in it's separate folder.
 
===Example 1===
*So, one example folder tree on one Linux laptop (an actual server would be more) may look something like:
 
var
--www
    ----maharadata
    ----moodlecleandata
    ----moodlestabledata
    ----moodlemasterdata
    ----moodletestingdata
    ----uswmoodledata
    ----html
        ------mahara
        ------moodleclean
        ------moodlestable
        ------moodlemaster
        ------moodletesting
        ------uswmoodle
 
===Example 2===
* Have several sandboxed Moodles on a single (CentOS X) server all of different versions .. only the ones that are supported for security fixes and above - 2.7,2.8,2.9,3.0, and now a 3.1.  Pretty much 'stock' Moodles with only occasional addons, etc. for testing.
* All have their separate code and data directories as well as their separate DB's.
 
* Hint: install and maintain them all with [[Git_for_Administrators|git]] ... even if you don't prefer/like command line, that is by far the most efficient way to update and/or upgrade a site.
 
/var/www/html/moodle27/version.php:$release  = '2.7.14 (Build: 20160509)'
/var/www/html/moodle28/version.php:$release  = '2.8.12 (Build: 20160509)'
/var/www/html/moodle29/version.php:$release  = '2.9.6+ (Build: 20160520)'
/var/www/html/moodle30/version.php:$release  = '3.0.4+ (Build: 20160603)'
/var/www/html/moodle31/version.php:$release  = '3.1+ (Build: 20160603)'
 
* The git -b command locks a site into the version provided with the rest of the git command ... for example, installing the 3.1, which is a long term support version, installed with git -b option.  Don't plan on upgrading nor testing upgrades with that one.
 
git clone -b MOODLE_31_STABLE git://git.moodle.org/moodle.git moodle31
 
* All the other moodles I have on that server have been installed via git
 
git clone git://git.moodle.org/moodle.git [nameofdir]
 
* then from nameofdir
 
git branch --track MOODLE_2#_STABLE origin/MOODLE_2#_STABLE
git checkout MOODLE_2#_STABLE
 
* 2# is the version number.
 
* That allows one to march that moodle upwards ... higher branch(es).  So one can test an upgrade (as opposed to an 'update').
 
* This second method 'gits' more code and backups will range in the 5+ Meg range due to all the older version git stuff    The 3.1 much less (restricted to 3.1 branch):
 
* 545M    ./moodle296-code-20160604145012.tar
 
* 193M    ./moodle31+-code-2016060883737.tar
 
 
[[es:Guia de instalacion paso-a-paso para Ubuntu 16.04]]

Revision as of 08:11, 11 July 2019

Note: This document is about installing Moodle 3.6 in an Ubuntu 18.04 server with PHP 7.2.


Before you begin

It is a good idea to write down the passwords (and usernames) you will need to use for Ubuntu and Moodle:

  • The Ubuntu root password
  • The MySQL username and password that Moodle will use
  • The Moodle main admin username and password
  • An additional admin Moodle username and password

Step 1: Install Ubuntu

Why we prefer Ubuntu server over Ubuntu desktop

  • Most IT professionals prefer to use a Command Line Interface (CLI) server, because it is safer and less prone to hacking.
  • Amateur users might find it easier to use a graphical (desktop) interface.
  • If you will only be using your Moodle server for local, experimental purposes, you might prefer to install the desktop (64 bits preferred) version of Ubuntu.
  • If you install a CLI only server and later regret it, you can easily add a graphical desktop:
Note: Even though it is not recommended by most experts, you could install a Graphical User Interface (desktop) by issuing the command 'sudo apt install ubuntu-desktop' to install 'Ubuntu desktop'. BUT USE WITH CAUTION: The GUI may not appear as expected, and may prevent user from getting even the CLI. Try it at test machine first.


Why we prefer (or don't prefer) Ubuntu 18.04 over Ubuntu 16.04 over Ubuntu 14.04

  • All three are LTS (Long Term Service) releases. amd64 edition preferred. http://www.ubuntu.com/download
  • Ubuntu Server 18.04 has all the required packages (comes default with Apache2, PHP 7.2, MySQL 5.7). Ubuntu Server 18.04 has some minor differences from 16.04 and 14.04, mainly PHP. This document has been updated to reflect those changes.
  • Moodle 3.0.1 onwards can use PHP 7.0. Moodle 3.6 requries PHP 7.0.
  • But beware that if you are using external authentication or enrollment plug-ins, please note that at the moment of Moodle 3.0.1 release (December 2015) neither MSSQL nor SQLSRV are available under php7. So, anybody using SQL*Server as primary database or remote auth/enrol plugin should not move to PHP 7 at all ! Also, depending of your configuration, some extensions (memcached can be installed, redis, mongodb, xmlrpc...) maybe missing or work in progress for your distribution, triple check the exact availability for your OS.

Procedure

  • Ubuntu has a well known issue with its automatic updates filling up the /boot directory until automated updates start to fail and automated removal of old kernel files from /boot is impossible. Because of this you should consider installing Ubuntu with a /boot directory of around 5Gb and putting some automated clean up in place. More info can be found here - [1]
  • You can use either VI (lightweight editor) or VIM (heavyweight editor), however, if you wish to use VIM you will need to install it
sudo apt-get install vim
  • VI or VIM Commands

To edit a file press "Insert" Key
To finish editing press "Esc" Key
To write the file press ":w"
To Exit the editor press ":q"
You can also write and quit ":wq"

  • In Ubuntu, the standard user, the account you created during the install, does not have rights to install/write to many of the directories. In the below tutorial we will be using the term "sudo" which stands for "super user do" before most of the commands.

Step 2: Install Apache/MySQL/PHP

Note: Moodle 3.0.1 introduced support for PHP 7.0 and we will be using PHP 7.2 in this tutorial


Open up Terminal and install the following;

sudo apt install apache2 mysql-client mysql-server php libapache2-mod-php

Run 'sudo mysql_secure_installation' to set the root password for mysql - please, please my dear friends, WRITE IT DOWN and spare yourself some grief, you will need it in step 6.

Step 3: Install Additional Software

sudo apt install graphviz aspell ghostscript clamav php7.2-pspell php7.2-curl php7.2-gd php7.2-intl php7.2-mysql php7.2-xml php7.2-xmlrpc php7.2-ldap php7.2-zip php7.2-soap php7.2-mbstring

Restart Apache so that the modules are loaded correctly

sudo service apache2 restart

We will be using Git to install/update the Moodle Core Application

sudo apt install git

Step 4: Download Moodle

Setup your local repository and download Moodle, We will use /opt for this installation.

  • Git is what is called a "version control system". By using git it will much easier down the road to update the moodle core application. Within Step 5 there is a little more detail on why we put the moodle core application code in the /opt directory.
cd /opt

Download the Moodle Code and Index

sudo git clone git://git.moodle.org/moodle.git

Change directory into the downloaded Moodle folder

cd moodle


Retrieve a list of each branch available

sudo git branch -a

Tell git which branch to track or use

sudo git branch --track MOODLE_36_STABLE origin/MOODLE_36_STABLE

Finally, Check out the Moodle version specified

sudo git checkout MOODLE_36_STABLE

Step 5: Copy local repository to /var/www/html/

sudo cp -R /opt/moodle /var/www/html/


sudo mkdir /var/moodledata


sudo chown -R www-data /var/moodledata


sudo chmod -R 777 /var/moodledata


sudo chmod -R 0755 /var/www/html/moodle


  • Explanation:


Since we setup a local repository in the previous step, you will copy it to your webroot after any updates and making changes. Having your local repository outside of the webroot, like we have in /opt, you will be able to prepare and stage your upgrades in a more efficient manner. For example, you want to make some changes or add some plug-ins, you would download the plugin and copy it to your local moodle repository. After you have added the plug-in and any other changes you might have made you will need to edit the file located in /opt/moodle/.git/info/exclude. Within that file you want to tell git which files/folders to exclude when it pulls down the updates when you run your next "sudo git pull". An example entry would be the certificate mod located in /opt/moodle/mod/certificate so within the exclude file you want to add "/mod/certificate" below the last comments. You would add additional entries, 1 per line, for each plug-in or file you might have changed. If I were to change the favicon.ico file you would just add "favicon.ico" to the exclude file. Now when you run "sudo git pull" to update moodle to the latest version it will ignore those files and directories and just update the core moodle code. Before copying to your webroot to upgrade you want to make sure and download and copy over the latest versions of the plug-ins you might have added.

Step 6: Setup MySQL Server

First we need to change the default storage engine to innodb and change the default file format to Barracuda, this is a new setting compared to previous versions. You also need to set innodb_file_per_table in order for Barracuda to work properly. Ref: https://dev.mysql.com/doc/refman/5.6/en/innodb-compression-usage.html

  • You should not need to make innodb the default storage engine anymore, the latest version of Moodle will select it automatically during install. It is always a good idea to make it default anyway. You do however need to set the default file format!
  • If you chose to use VIM instead please substitute vi for vim
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

Scroll down to the [mysqld] section and under Basic Settings add the following line under the last statement. if you want to add you have to press the "insert" button on your keyboard. this is usually above the "delete" button. this allows you to add some text.

default_storage_engine = innodb


innodb_file_per_table = 1


innodb_file_format = Barracuda

In order to save my.cnf using the editor, press the Esc (Escape) key, type the following in sequence which will save :w then close the editor :q

:w


:q

Restart MySQL Server for changes to take affect

sudo service mysql restart

Now we need to create the Moodle database and the Moodle MySQL User with the correct permissions

Use the password you created in step 1

sudo mysql -u root -p


mysql>

CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Note: Use 'utf8mb4' for full range (4-byte) support of UTF-8, including Emoji ('utf8' only supports 3-byte). You will be compliant by Moodle admin page if you don't use 'utf8mb4' here.


Where it says "moodledude" and "passwordformoodledude" you should change to the username and password of your choosing.

mysql>

create user 'moodledude'@'localhost' IDENTIFIED BY 'passwordformoodledude';


mysql>

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO moodledude@localhost IDENTIFIED BY 'passwordformoodledude';


mysql>

quit;

Note - If you are using MySQL 5.6+ and when you issue the create user and get an error about the password hash you need to adjust the password to use the hash value

You can get this by following the below

mysql>

SELECT password('passwordformoodledude');


This will print the hash of the password like *AD51BAFB2GD003D3480BCED0DH81AB0BG1712535, you will want to use this in the IDENTIFIED BY ' part

Step 7: Complete Setup

  • Note - If you are not comfortable using terminal to create the config.php file that needs to be created when going through the installer, you should temporarily make the webroot writable by doing the following:
sudo chmod -R 777 /var/www/html/moodle

After you have ran the installer and you have moodle setup, you NEED to revert permissions so that it is no longer writable using the below command.

sudo chmod -R 0755 /var/www/html/moodle

Open your browser and go to http://IP.ADDRESS.OF.SERVER/moodle

Follow the prompts:

Change the path for moodledata

/var/moodledata

Database Type

Choose: mysqli

Database Settings

Host server: localhost

Database: moodle

User: moodledude (the user you created when setting up the database)

Password: passwordformoodledude (the password for the user you created)

Tables Prefix: mdl_

Environment Checks

This will indicate if any elements required to run moodle haven't been installed.

Next next next...

follow prompts and confirm installation

Create a Site Administrator Account

Create your moodle user account which will have site administrator permissions.

The password you select has to meet certain security requirements.

Installation Complete

Congrats! You can now start using Moodle!

Don't Forget

If you made the webroot writable, revert permissions

sudo chmod -R 0755 /var/www/html/moodle

System Paths After Install

After installing Moodle you should set the system paths, this will provide better performance VS not setting them. Each entry in Moodle will have it's explanation.

Navigate, on the moodle webpage, to Site Administration > Server > System Paths

Input the following;

Path to du: /usr/bin/du

Path to apsell: /usr/bin/aspell

Path to dot: /usr/bin/dot

Save Changes


  • Optional if you do not already have an AntiVirus Solution

We also installed ClamAV in Step 3 so we need to set the path in Moodle

1st Create the Quarantine Directory

sudo mkdir /var/quarantine

Change Ownership

sudo chown -R www-data /var/quarantine

Navigate to Site Administration > Plugins > Antivirus plugins > Manage antivirus plugins

Enable ClamAV antivirus

Click on Settings

Set the proper settings

Save changes

In previous Moodle branches: Check "Use ClamAV on uploaded files" ClamAV Path : /usr/bin/clamscan Quarantine Directory : /var/quarantine

Save Changes

Suggestions: Enable Zend OpCache/Change Document Root

Within the link above, https://docs.moodle.org/26/en/OPcache add the recommended settings to your 05-opcache.ini file. Again, substitute vi with vim and remember to use the correct key squences from the introduction.

sudo vi /etc/php5/apache2/conf.d/05-opcache.ini

NOTE: In Ubuntu 16.04 opcache.ini is located in:

/etc/php/7.0/mods-available/opcache.ini

Restart Apache for changes to take affect.

sudo service apache2 restart

That's it for the Zend OpCache!

You can also install a GUI to view the status of your Zend OpCache, not recommended on production servers.

cd /var/www/html/moodle/

Download the PHP Script to your Moodle directory, you should also add this file to /opt/moodle/.git/info/exclude file so it does not get removed when upgrading your installation.

sudo wget https://github.com/rlerdorf/opcache-status/blob/master/opcache.php

Visit http://ip.address.of.server/moodle/opcache.php

If you do not want your end users to type http://yourserver/moodle and just want them to navigate to http://youserver you will need to edit the site configuration for Apache which will tell Apache to use the /var/www/html/moodle as the root directory and not /var/www/html

Open up the Apache sites config and change the document root

sudo vi /etc/apache2/sites-available/000-default.conf

On the line where DocumentRoot is;


Change From: DocumentRoot /var/www/html

Change To: DocumentRoot /var/www/html/moodle

:w
:q

Restart Apache for changes to take affect.

sudo service apache2 restart

Important note!

If you have already installed Moodle then you should make the below changes.

Editing config.php for moodle

In the installation instructions, one of the suggested settings for 'webroot' is 'localhost'. This is fine if all you want to do is some local testing of your new Moodle installation. If, however, you want to view your new installation from another machine on the same local area network, or view your site on the Internet, you will have to change this setting:

For local testing, 'localhost' is fine for the webroot ($CFG->wwwroot in config.php). If you want to test your site from other machines on the same local area network (LAN), then you will have to use the private ip address of the serving machine, (e.g. 192.168.1.2/moodle) or the network name of the serving computer (e.g. network_name_of_serving_machine/moodle) as the web root. Depending on your LAN setup, it may be better to use the network name of the computer rather than its (private) ip address, because the ip address can and will change from time to time. If you don't want to use the network name, then you will have to speak to your network administrator and have them assign a permanent ip address to the serving machine. Finally, if you want to test your new installation across the internet, you will have to use either a domain name or a permanent (public) ip address/moodle as your web root. To handle both types of access, see masquerading.


Edit config.php for Moodle

cd /var/www/html/moodle sudo vim config.php

Hit the "insert" button on your keyboard, make then changes you need to make. Then press "escape" and type the following in to quit and to save changes (excluding quotation marks): ":wq"

Under $CFG->wwwroot change to http://ip.address.of.server instead of http://ip.address.of.server/moodle


Hosting several Moodle branches in one Ubuntu server

  • This is very useful for the language pack maintainers to test translations in several Moodle branches.
  • It is also very useful for developers to test their plugins in different Moodle branches.
  • Just create a folder for each instance inside the web folder and that would be enough.
  • To access the sites you only need to add the folder to localhost URL: http://localhost/moodle31
  • You can have an instance for each version from 1.9 to 3.1
  • You do need a separate data folder for each instance and a separate database (You can use phpmyadmin to set your database, but that's not necessary), add each instance in its own folder, and carry on as above. You can also host another service (eg, Mahara) in it's separate folder.

Example 1

  • So, one example folder tree on one Linux laptop (an actual server would be more) may look something like:
var

--www

   ----maharadata
   ----moodlecleandata
   ----moodlestabledata
   ----moodlemasterdata
   ----moodletestingdata
   ----uswmoodledata
   ----html
       ------mahara
       ------moodleclean
       ------moodlestable
       ------moodlemaster
       ------moodletesting
       ------uswmoodle

Example 2

  • Have several sandboxed Moodles on a single (CentOS X) server all of different versions .. only the ones that are supported for security fixes and above - 2.7,2.8,2.9,3.0, and now a 3.1. Pretty much 'stock' Moodles with only occasional addons, etc. for testing.
  • All have their separate code and data directories as well as their separate DB's.
  • Hint: install and maintain them all with git ... even if you don't prefer/like command line, that is by far the most efficient way to update and/or upgrade a site.
/var/www/html/moodle27/version.php:$release  = '2.7.14 (Build: 20160509)'
/var/www/html/moodle28/version.php:$release  = '2.8.12 (Build: 20160509)'
/var/www/html/moodle29/version.php:$release  = '2.9.6+ (Build: 20160520)'
/var/www/html/moodle30/version.php:$release  = '3.0.4+ (Build: 20160603)'
/var/www/html/moodle31/version.php:$release  = '3.1+ (Build: 20160603)'
  • The git -b command locks a site into the version provided with the rest of the git command ... for example, installing the 3.1, which is a long term support version, installed with git -b option. Don't plan on upgrading nor testing upgrades with that one.
git clone -b MOODLE_31_STABLE git://git.moodle.org/moodle.git moodle31
  • All the other moodles I have on that server have been installed via git
git clone git://git.moodle.org/moodle.git [nameofdir]
  • then from nameofdir
git branch --track MOODLE_2#_STABLE origin/MOODLE_2#_STABLE
git checkout MOODLE_2#_STABLE
  • 2# is the version number.
  • That allows one to march that moodle upwards ... higher branch(es). So one can test an upgrade (as opposed to an 'update').
  • This second method 'gits' more code and backups will range in the 5+ Meg range due to all the older version git stuff The 3.1 much less (restricted to 3.1 branch):
  • 545M ./moodle296-code-20160604145012.tar
  • 193M ./moodle31+-code-2016060883737.tar