Moodle 3 Administration - Third Edition - Sample Chapter
Moodle 3 Administration - Third Edition - Sample Chapter
Moodle 3 Administration - Third Edition - Sample Chapter
Third Edition
$ 49.99 US
31.99 UK
P U B L I S H I N G
E x p e r i e n c e
D i s t i l l e d
Moodle 3 Administration
Third Edition
An administrator's guide to configuring, securing, customizing,
and extending Moodle
Sa
m
pl
C o m m u n i t y
Alex Bchner
Moodle 3 Administration
Third Edition
Moodle 3 Administration
ee
Alex Bchner
Moodle, and Mahara partner, Synergy Learning. He has been involved in system
and database administration for more than two decades and has been administering
virtual learning environments of all shapes and sizes since their advent on the
educational landscape.
Alex holds a PhD in computer science and an MSc in software engineering. He has
authored over 50 international publications, including two books, and is a frequent
speaker on Totara, Moodle, Mahara, and related open source technologies. His first
two books on Moodle Administration by Packt Publishing have become the de facto
standard on the topic.
Preface
Since its launch in 2002, Moodle has become the benchmark that every learning
management system is measured against. It has won a wide range of international
accolades and established itself as an ecosystem for a large number of educational
tools and services.
Moodle 3 Administration, Third Edition is a complete, practical guide for administering
Moodle sites. It covers setting up Moodle, configuration, and day-to-day
administrative tasks as well as advanced options to customize and extend Moodle.
The author, who has been at the cutting edge of Moodle administration since its
advent, has adopted a problem-solution approach to bring the content in line with
your day-to-day operations. The practical examples will help you to set up Moodle
for large organizations and small courses alike.
This is a one-stop reference for tasks that you will come across when administering
a Moodle site of any shape or size. It not only covers core Moodle functionality, but
also third-party tools and add-ons that will increase your flexibility and efficiency
even further when dealing with administrative duties.
Why another book on Moodle administration? Since the second edition of the title
in 2011, the system has been modified and extended significantly to cover all the
relevant new functionality in Moodle 3.
Preface
Chapter 1, Moodle Installation, tells you about the most suitable Moodle setup for your
organization, including software and hardware requirements. You will learn how to
install Moodle in three environments, namely, LAMP/Unix, Windows, and Mac OS,
before Moodle updates options are covered in detail. Throughout the chapter, you
will also learn how to perform some of the described operations using the Moodle
Command-line Interface (CLI), Git, and Moodle Shell (Moosh).
Chapter 2, The Moodle System, covers the building blocks of the learning platform. First,
we cover the Moodle architecture, that is, the main Moodle components and where its
data and code is stored. We then provide you with the skills to find your way a round
in Moodle via its intuitive user and administration interface. Finally, we deal with the
management of files, which includes Moodle's standard file management, web host file
management, and file management via the file system repository.
Chapter 3, Courses, Users, and Roles, gives you an overview of Moodle courses, users,
and roles. It covers the basics of the three key concepts and demonstrates how the
three core elements are inherently intertwined.
Preface
Chapter 4, Course Management, shows you how to set up new courses (also in bulk)
and organize them in categories. The remainder of the chapter deals with an array of
enrolment options, covering Moodle's internal enrolment (manual, self, and guest),
cohort enrolment and synchronization, database-driven enrolment, for instance, via
LDAP, meta courses, and payment-driven enrolments.
Chapter 5, User Management, explains how to manage users on your system. We first
cover what user profiles look like and how they can be extended before presenting
(manual and bulk) standard user actions. We then explain how to add users to Moodle
manually, that is, one-by-one, and via batch upload before dealing with cohorts. Then,
you will learn about a plethora of authentication mechanisms that Moodle equips us
with. Finally, we discuss the best practices of user naming schemes.
Chapter 6, Managing Permissions Roles and Capabilities, guides you through
permission management. It applies roles and capabilities to users in different
contexts. We will cover the assignment of roles, modification of existing roles, and
creation of new roles before we deal with any administrative role-related settings.
Chapter 7, Moodle Look and Feel, tells you how to adapt your Moodle system to
bring it in line with the corporate branding of your organization. We will cover
the customization of the front page, basic creation of Moodle themes, and support
for mobile devices via responsive themes. You will also learn how to configure the
Moodle editor and support users with accessibility requirements.
Chapter 8, Moodle Plugins, explains in detail how to extend your Moodle system via
third-party add-ons. You will be able to distinguish between good add-ons and
not-so-good add-ons before we cover extensions that are popular with other users.
We will then cover how to install, configure, and uninstall third-party add-ons.
Plugins that are covered are activities, blocks and filters, repositories, portfolios, text
editors, licenses, question types and behaviors, plagiarism prevention, licenses, and
availability restrictions.
Chapter 9, Moodle Configuration, deals with the educational and technical
configuration of your Moodle system. Pedagogical topics that are covered are
badges, collaboration (blogs, comments and tags), LTI, localization, grades and
gradebook settings, and a number of miscellaneous parameters. Technical subjects
that are dealt with include synchronous communication (instant messaging and
video conferencing), asynchronous communication (inbound and messaging as well
as RSS feeds), and a number of experimental settings.
[ xiii ]
Preface
Chapter 10, Moodle Logging and Reporting, equips you with the tools that you require
in order to interpret and analyze the vast amount of usage data that Moodle is
collecting. You will learn about the logging framework and monitoring facilities
provided by Moodle that include activity reporting, user tracking, and some basic
statistics. Then, we will take a look at third-party tools that cover learning analytics,
report generation, web log analyzers, and live data trackers such as Google Analytics
and Piwik.
Chapter 11, Moodle Security and Privacy, focuses on ensuring that the data in your
Moodle system is protected from any misuse. You will learn about security
notifications, user security, data and content security, and system security. We will
conclude the chapter with information on privacy and data protection concerns.
Chapter 12, Moodle Performance and Optimization, makes sure that your Moodle system
runs to its full potential. We will cover configuring, monitoring, and fine-tuning your
virtual learning environment for maximum speed. You will learn how to optimize
Moodle content before we focus on system parameters, namely, caching via the
Moodle Universal Cache (MUC), session handling, cron management, scheduled
tasks, module settings, and miscellaneous settings. We also present some basic
performance profiling and monitoring tools.
Chapter 13, Backup and Restore, focuses on ensuring that your data would not be
lost in the event of a disaster. We will cover course backups, site backups, system
backups, and restoring data from the taken data archives.
Chapter 14, Moodle Admin Tools, covers Moodle admin tools that assist you with
certain specific administrative tasks. These include web-based helpers such as
upgrade and database tools as well as CLI scripts. We will also be looking at some
add-ons, especially the powerful Moodle Shell, Moosh.
Chapter 15, Moodle Integration, looks at ways to integrate Moodle with other systems
via web services. We will provide information about the basic concepts of Moodle
web services before you learn how to set up external systems and users controlling
Moodle. This also covers the support for the official mobile app.
Chapter 16, Moodle Networking, tells you how to connect disparate Moodle and Totara
systems either in a peer-to-peer setup or via a Moodle hub. You will also be able
to apply the learned networking techniques to connect the popular open source
e-portfolio system, Mahara, and the social learning tool, Totara Social, to Moodle.
We will further show you how to connect to Moodle.net and set up your own
community hub.
Appendix, Configuration Settings, provides you with a list of parameters that can be
modified in Moodle's configuration file and the impact that each of these values will
have. The areas covered are Administration Settings and System Settings.
[ xiv ]
Moodle Installation
Let's get started by installing Moodle.
After providing an overview that describes which setup is most suitable, software as
well as hardware requirements are outlined.
We will then cover the following installations:
You will only need to study the section(s) of the operating system(s) you are
planning to use. Moodle can be scaled from a single instructor to an entire
institution. We will only be able to cover the most common installations and present
solutions to some common problems. We also have to assume that you are familiar
with basic system administration of the operating system on which you will be
installing Moodle.
[1]
Moodle Installation
Flexibility: If you want to have full control over your system, be able to tweak
system settings, and make frequent changes to the setup, you are best suited to
host your own server. However, if your preferred choice is to only administer
Moodle while somebody else is looking after the operating system, the web
server, and backups, it is better to opt for a professionally-hosted setup, and
particularly, the offerings provided by the authorized Moodle Partners.
Scalability: This is entirely driven by the number of concurrent users, that is,
the number of active learners and teachers logged in to Moodle at the same
time. A Moodle on a single-processor desktop computer will not be able to
cope with hundreds of simultaneously logged-in users. A load-balanced
cluster, on the other hand, would be overkill for a small institution with a
handful of learners. The following table provides some indicative setups for
different types of educational organizations, and is by no means complete:
Recommended setup
20 (single class)
Shared server
Dedicated server
+500 (university/corporate)
Load-balanced cluster
Please bear in mind that these are only indicative numbers, which are not
written in stone, and also depend on the other factors mentioned here. The
mentioned hosting option on https://moodlecloud.com/en/ offers free
Moodle hosting by Moodle HQ with a number of limitations: maximum
number of users is set to 50, storage capacity is limited to 200 MB, there is no
ability to install plugins, and there is advertisement displayed throughout the
site. This is a good way to try out Moodle, but not intended for production sites.
Organizations require a server (either dedicated or shared) that is either
hosted in-house or externally. If you decide to go down the hosted route, it is
highly recommended to avoid a cheap hosting package as their systems are
not optimized for Moodle usage. This will have a significant impact on the
performance of the system, especially with an increasing number of users.
[2]
Chapter 1
Cost: Budgetary constraints will certainly play an important role in your setup.
Unless you already have the appropriate infrastructure in place, it is likely to
be more cost-effective to host your Moodle system externally as it saves you
from having to purchase servers and provide a 24/7 data connection that
caters to your learners' needs. Licensing cost is significantly higher if you use
commercial operating systems, web servers, and database systems, instead of
an open source solution. Either way, Moodle is designed to support a wide
range of possible infrastructures suitable to your organization's IT policy.
In addition to these three key criteria that usually influence the decision about the
underlying infrastructure, there are other factors that will have an impact on your
decision, such as in-house expertise, compatibility with other systems, personal preference,
and existing resources.
We will cover the three most popular operating systems for hosting MoodleLinux,
Windows, and Mac OS. For other setups such as on a memory stick, in a virtualized
environment, or a larger multi-server cluster, please consult your local Moodle
Partner (https://moodle.com/). Some hosting companies offer quick one-click
installations (often via the Fantastico installer, which usually doesn't contain the
latest version). While the resulting Moodle system is sufficient for experimental sites,
it is certainly unsuitable for production environments.
Moodle prerequisites
There are a number of hardware and software requirements that have to be satisfied
before we can start installing Moodle.
Hardware requirements
These requirements apply if you host Moodle yourself or if it is hosted on an external
server (shared, virtual, dedicated, or clustered). On cheaper hosting packages, the
hardware configuration is often insufficient to run Moodle efficiently:
Disk space: Moodle takes up between 150 MB and 200 MB of disk space.
However, this only provides you with an empty system and does not take
into account the space you require for any learning resources. The faster the
disks, the better. RAIDed disks are recommended, but are not essential on
smaller installations.
Moodle Installation
The more RAM the better; the faster the RAM the better.
CPU: Processor type and speed is important too, but not as important as
RAM. As always, the faster the CPU the better, and the more cores a CPU
has, the more powerful it will be.
Network: While Moodle can run on a standalone machine, its full potential
is in a networked environment. A fast network card is essential, as is good
upload and download speed if the LMS is accessed over the Internet.
Software requirements
While it is recommend to have the latest version installed, for Moodle 3, you must
have the following components up and running on your server (release specific notes
can be found at https://docs.moodle.org/dev/Releases):
Web server: Apache is the preferred web server option, but Moodle works
well with any other web server that supports PHP such as Microsoft IIS.
PHP: PHP 5.4.4 is the minimum PHP version to run Moodle 3. PHP 7 is also
supported. There are a number of PHP settings, which you might have to
change in the php.ini or .htaccess file (see https://docs.moodle.org/en/
Installing_Moodle for more details).
[4]
Chapter 1
Downloading Moodle
Go to https://download.moodle.org/ and select Latest release in the Standard
Moodle section:
[5]
Moodle Installation
Latest release: For the current version of Moodle, there are two releasesthe
latest stable build and the latest official release. The latest stable version is
created weekly (every Wednesday) and is the best choice for a new server.
The latest official release contains the stable build as well as new fixes, but
the version will not have gone through the weekly code review and might
contain unresolved issues.
Other supported releases: Older versions than the current one are
maintained by the Moodle development team and bug fixes are back-ported
for 12 months after release. Sometimes, the newly-added functionality is
back-ported. Version 3.1 will be a long-term support release and will be
supported for 3 years.
Legacy releases: For older versions, the last build is made available.
However, these are not maintained any further.
Development release: Moodle also offers you the option to download beta
releases of the software (if available) and also the latest development release.
These should only be downloaded for testing or development purposes,
never in production environments!
Each version is made available in the two compressed formats: TGZ (use the tar
command to uncompress) and ZIP (requires unzip). You can either download them
by clicking on the respective link or, if you have (secure) shell access, retrieve the file
directly by using the wget command:
wget http://download.moodle.org/moodle/moodle-latest.zip
[6]
Chapter 1
If you make use of Moodle Shell (MOOSH), which is described in more detail in
Chapter 14, Moodle Admin Tools, you can use the following command to download the
latest stable branch of Moodle:
moosh download-moodle
Once you have moved the file to the location where you want to install it on your
web server (dirroot), extract the file using the unzip command (or tar xvfz if you
downloaded the TGZ version). In a hosted environment, you might have to use the
uncompressing method provided by the web administration interface (cPanel, Plesk,
or any bespoke system):
unzip moodle-latest.zip
tar xvfz moodle-latest.tgz
If you place the entire folder in your web server documents directory, the site
will be located at www.yourwebserver.com/moodle. To access your site from
www.yourwebserver.com, copy the contents directly into the main web server's
documents directory.
The URL via which Moodle is accessed is referred to
as wwwroot.
Once this has been successfully done, you have to create the database that Moodle
uses to store its data.
Moodle Installation
Once you have started phpMyAdmin, go to the Databases section and create a new
database using the UTF collation (utf8_general_ci collation). You don't need to create
any tables; Moodle will be populating the database during the installation process.
While you can use an existing database user account, it is good practice to
create a dedicated user for the Moodle database. This step is carried out in the
Privileges section.
Do not use the MySQL root account for your Moodle database!
Chapter 1
3. Set the default character and collation order to UTF8 by entering ALTER
DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_
unicode_ ci;.
You have now completed the database setup. All we have to do now is to create
Moodle's data directory before we are ready to start the installation of Moodle itself.
Later on, the Moodle installer will attempt to create this directory but, in some
setups, this is not possible due to security restrictions. To be on the safe side, it is
better to create moodledata manually or via a web-based file manager, as provided
by some systems:
It is crucial to create moodledata on your server where it cannot
be accessed publicly, that is, outside your web directory.
1. Create the directory by entering mkdir moodledata. This is where all the
uploaded files by course authors and learners will be stored, so make sure
this is dimensioned properly. You might also consider to create this in a
separate partition.
2. Change permissions recursively by entering chmod R 0770 moodledata
(if you use 0777, then everybody on the server will have access to the files).
[9]
Moodle Installation
3. Change the user and group of the directory to that of your web server
(usually apache or www-data and nobody or www-data, respectively) by
entering chown R apache:nobody moodledata.
If you don't have permission to create the data directory in a secure location, create
the .htaccess file in your home directory containing the following two lines:
order deny,allow
deny from all
This will prevent files from being accessed without the user having permissions to
do so.
[ 10 ]
Chapter 1
The following screenshot displays the expected values for Web address of the site
(wwwroot), Moodle directory (dirroot) and Data directory (dataroot); you might
have to modify the data directory entry if the location of your moodledata differs:
If dataroot cannot be located or does not have the correct permissions, an error
message with details will be displayed. The same applies if dataroot is accessible
directly via the Web and is hence, not secure.
In the following screenshot, you have to select which database you wish to use. On
my system, only the drivers for MySQL, MariaDB, and PostgresSQL are installed. To
use other database systems such as Oracle or MS SQL Server, the respective driver
has to be installed first.
[ 11 ]
Moodle Installation
This interface is using the configuration details previously established. The following
screenshot will look slightly different if you have chosen a different database driver
to the native MySQL:
Setting
Description
Database host
Database name
This is the database name, user name, and password you enter
when you run the mysql command.
Database user
Database password
Tables prefix
Database port
Unix socket
[ 12 ]
Chapter 1
Once you see the following screen, you will know the Moodle configuration file,
config.php, has been successfully created. If the creation of the configuration file
fails (usually because of incorrect permissions), the installer will display the content
of the configuration file. You will have to copy the text from the screen and paste it to
config.php in your dirroot.
Before Moodle can proceed with the installation, you have to agree to the GPL
license agreement. You find the full license text at https://docs.moodle.org/dev/
License.
Once you have accepted the license agreement, the Moodle installer checks to see
whether certain components are installed. Not all the modules are compulsorysee
the Moodle prerequisites section in this chapter and notice on screen. The installer also
verifies the key PHP settings. If any of the tests are not passed, it is important that you
go back to the Software requirements section to resolve any problems and restart the
installation process after the issues have been fixed. Otherwise, some features may not
work or the installer will not continue, depending on the importance of the module.
[ 13 ]
Moodle Installation
Two common issues that arise when using MySQL are the prerequisite to use
the InnoDB Barracuda file format and file-per-table mode. In both cases entries
have to be added to the [mysqld] section in /etc/mysql/my.cnf (innodb_file_
format=Barracuda and innodb_file_per_table, respectively).
Once this screen has been confirmed, the Moodle installer will create all the tables in
the database. This process might take a few minutes.
[ 14 ]
Chapter 1
Once the table creation and population has been concluded, you will see the screen
to set up the administrator account. The default Username is admin, which should be
changed for security reasons. The self-explanatory fields you have to fill in are New
password, First name, Surname, Email address, City/town, and Select a country.
All other fields are explained in great detail in Chapter 5, User Management.
The last screen of the installation script asks you to enter some front page settings,
namely, the Full site name, Short name for site and Front page description.
These front page settings can be modified later (see Chapter 7, Moodle Look and
Feel). Additionally, the installer allows you to turn on Self registration. Leave this
disabled for now, until you have covered Chapter 5, User Management.
Once this information has been entered and the screen has been confirmed, you are
ready to start using Moodle. However, it is recommended to finalize the installation
and to set up the execution of the Moodle maintenance script.
[ 15 ]
Moodle Installation
In the case of my installation, there are two issuesa PHP setting has a value that is
not recommended (I have to change this in the php.ini file) and the so-called cron
maintenance script has not run for at least 24 hours. We will solve that mystery after
we have registered our site. Other messages might appear in the Notifications area,
and you should resolve them in due course.
Moodle provides some statistics about its usage on https://moodle.net/
stats/. To be included in these figures, you have to register your Moodle site.
Registration(below the Notification link) with https://moodle.org/ (MOOCH) is
optional and free, and you decide what information will be made public. Even if you
opt out of providing any usage patterns for your site, it is still highly recommended
to register, as you will get occasional notices, for example, advanced security alerts:
[ 16 ]
Chapter 1
Description
Name
The name of your site, as you just specified in the front page
settings.
Privacy
Description
Language
Postal address/Country
Geolocation
Administrator
Phone/Email address
Contact form
Email notifications
[ 17 ]
Moodle Installation
Most control panels allow you to set up scheduled tasks via a cron job management
tool. Bear in mind that this is not part of Moodle but a part of your hosting package.
The following screenshot is from the widely used Plesk system, which executes the
script every five minutes:
There are a number of ways to call the cron script. The most popular option in a
Linux environment is wget q O /dev/null http://<yoursite>/admin/cron.
php (see Command in the preceding screenshot). However, if this does not suit your
setup, check out https://docs.moodle.org/en/Cron for alternatives.
The interface shown earlier creates an entry in crontab, a file located in the /etc
directory that contains all the system-wide cron entries. This file can also be edited
manually using crontab -e, but be careful to get the syntax right!
On larger sites, it is recommended to run the cron process
every minute!
This concludes the installation process for Moodle in a LAMP environment. If you
have come across any problems that have not been covered in these instructions or
if your setup differs from the one described, go to https://docs.moodle.org/en/
Installing_Moodle, where more installation details are provided and exceptions
are covered in great detail.
[ 18 ]
Chapter 1
[ 19 ]
Moodle Installation
Instead of starting and stopping Moodle manually, you can start Apache and
MySQL automatically as Windows services. In the server directory of your Moodle
system, you find an executable called service.exe, which you have to run with the
-install parameter as administrator, as in the following example:
C:/moodle/server/service.exe -install
2. Drag the MAMP folder on this screen onto the Applications icon, which will
copy the Moodle system and its required components.
[ 20 ]
Chapter 1
3. Open the MAMP folder in Applications, where you will find the following
relevant icons:
4. Double-click on the MAMP.app icon and start servers (Apache and MySQL).
You can configure MAMP to automatically start the two servers in the
preferences:
[ 21 ]
Moodle Installation
The default password for the admin account is 12345, which you should change in
the user profile.
The MAMP folder also includes a shell script called UpdateMoodle30.sh (this requires
Git to be installedsee the Updating Moodle section discussed later). When you
double-click on the file, the script will be executed to download the latest version of
Moodle and install it on your Mac. On all other operating systems, you will have to
go through a more cumbersome update process, which is described further.
Chapter 1
From your dirroot, you can initiate the interactive script as follows:
sudo u www-data /usr/bin/php admin/cli/install.php
More interesting is the non-interactive mode as this can be used for scripting and
automation purposes. The list of all the available parameters is displayed using the
--help command:
sudo u www-data /usr/bin/php admin/cli/install.php --help
An example command line would look similar to the following, where you will have
to adjust the parameters to your local setup:
sudo -u www-data /usr/bin/php admin/cli/install.php
--wwwroot=http://123.54.67.89/moodle --dataroot=/var/moodledata/
--dbtype=mysqli --dbhost=localhost --dbname=moodle --dbuser=moodle
--dbpass=Password123! --fullname=moodle2 --shortname=moodle2
--adminpass=Password123! --non-interactive --agree-license
[ 23 ]
Moodle Installation
There are more Moodle tasks that can be administered via the CLI, for example,
resetting passwords or putting Moodle in maintenance mode. We will show the
relevant syntax at the appropriate places throughout the book.
If your installer crashes, you might have to increase your PHP
memory_limit and post_max_size settings in php.ini.
Updating Moodle
Moodle is being updated constantly, which is common practice in open source
development environments. A new version containing resolved bug fixes is created
every night and, as mentioned earlier, a fully-tested version is released on a weekly
basis. There is usually no need to install updates every week; however, there are a
number of scenarios when you should upgrade your Moodle system:
There are principally two ways Moodle systems can be updated. You can either run
updates manually (using the web interface or the CLI) or stay up to date using Git
commands. Both procedures are described in this section.
Either way, before you start, make sure you put Moodle in maintenance mode to
ensure that no other user is logged in during the update. Go to Server | Maintenance
mode, Enable the Maintenance mode, and enter a maintenance message:
[ 24 ]
Chapter 1
You can also put Moodle in maintenance mode using its CLI as follows:
sudo u www-data /usr/bin/php admin/cli/maintenance.php --enable
Using the --enablelater=MINUTES flag you can specify the time period before
entering CLI maintenance mode. This is useful when you run an automatic update.
To change back to normal mode, use the --disable parameter instead of --enable
as follows:
sudo u www-data /usr/bin/php admin/cli/maintenance.php --disable
Manual update
The high-level process for updating a Moodle system manually is as follows:
1. Creating a backup.
2. Creating a new Moodle system.
3. Installing the update.
If you are updating from a previous version of Moodle, the process is the same.
However, double-check the Upgrading document at https://docs.moodle. org/
en/Upgrading for any version-specific issues.
You have to be at least on version 2.2 to update directly to the
current version of Moodle.
If you are still on version 1.9 or on a dinosaur release that is even older, you will
need to get to version 2.0 first, before upgrading to 2.2, and then to the latest version.
Updating from Moodle 1.x to Moodle 3 is a big version jump that
has some serious implications. For example, some theme elements
will have to be recreated, custom code will need adjusting and,
most importantly, your support and faculty staff is likely to require
training before the new version is put in production.
Moving from Moodle 1.x to Moodle 3 is more a migration from one
system to another than an update. Setting up a separate test system
to test the migration process has proven valuable. You will have to
plan and have a budget for this.
[ 25 ]
Moodle Installation
Creating a backup
Before you install a new update, it is highly recommended that you run a backup
of your Moodle system. While most updates will run smoothly, the backup will be
required if you have to revert the system to the pre-update version. There are three
parts that have to be backed up:
Database: There are two ways you can create a so-called database dump
from a MySQL database, either via command line or via Moodle's optional
database interface.
The simplest syntax for the command line tool is:
mysqldump -u <user> -p <database> > backup.sql
To restore the database you need to use the mysql command line tool as
follows:
mysql -u <user> -p <database> < backup.sql
The interface for the database tool is accessed via Server | Moodle Adminer.
This is an optional module and has to be installed separately refer to
Chapter 8, Moodle Plugins, for more details).
Click on the Dump link on the front page, select the database to export, and
click on Export, as shown in the following screenshot. The output of the
command will be displayed on screen.
Chapter 1
Moodle: This is the Moodle software itself. Create a copy of the directory
elsewhere on the server. While only some parts of this backup are required
(config.php, added themes, modified language packs, and so on), it is
good practice to create a backup of the entire software. Finally, rename your
Moodle system from moodle to, say, moodle.old (mv moodle moodle.old).
For more information on backups, check out Chapter 13,
Backup and Restore.
config.php
Any third-party modules and custom code that is not located in local
That's it! The next time you start Moodle, the update script will kick in. We'll go
through that next.
Once you are more confident with the update process, you can copy the new version
straight on top of the current version after you have created backups. This will save
you the last steps of manually copying files from the old to the new versions.
[ 27 ]
Moodle Installation
Next, a screen is displayed that provides a link to the release notes and performs the
same server check as the one described during the installation.
Moodle plugins, whether core (Standard) or third-party (Additional), sometimes
cause problems when upgrading Moodle. The Status column highlights any actions
required or problems found. You should resolve any issues that have arisen. Refer to
Chapter 8, Moodle Plugins, for more details.
[ 28 ]
Chapter 1
Once this screen has been confirmed, the actual installation starts, during which
new database fields are created and data is modified if and when necessary. Any
new system settings that have been added to Moodle are shown and can be changed
straightaway. For example, in the following screenshot, a new Always send email
from the no-reply address parameter has been added:
Once the upgrade process has been completed, make sure you check the
Notifications page as earlier. Also, don't forget to turn off the Maintenance mode!
Updating Moodle via CLI is even more powerful when combined with the Git
checkout of the Moodle source code. That is what we look at next.
An alternative approach exists to keep a current version up-to-date. It uses an open
source versioning system which is supported by Moodle, namely Git. All checked-in
Moodle code is made available via this method, which allows you to update only the
modules that have actually changed.
[ 29 ]
Moodle Installation
Setting up Git is a cumbersome process, which is beyond the scope of this book.
You can find details at https://docs.moodle.org/en/Git_for_Administrators.
However, once set up, Git is a very streamlined system to use, particularly, in
conjunction with the CLI we discussed earlier. The following is a sample script
which gets the latest version of the source code, puts Moodle in maintenance
mode, merges the old code with the new, runs the upgrade script, and disables the
maintenance mode:
git fetch
sudo -u www-data /usr/bin/php admin/cli/maintenance.php
--enable
git merge origin/cvshead
sudo -u www-data/usr/bin/php admin/cli/upgrade.php
sudo -u www-data/usr/bin/php admin/cli/maintenance.php
--disable
If you have changed any core code, potential conflicts might arise and will have to be
resolved (Git will prompt you to do so).
You might also come across some conflicting advice on whether to use Git for
production sites or not. The advantage is that your system is always up to date and
that the updates are carried out automatically. The disadvantage is that the update
process might require intervention to resolve any conflicts or it might fail, especially
when a lot of third-party add-ons have been employed.
[ 30 ]
Chapter 1
Update notifications
Moodle can notify you about a newly available version. In order to support this
feature, you will need to change the Enable updates deployment settings in Server |
Update notifications as follows:
Once this has been changed, you will be notified of any updates (system as well as
plugins), and options will be shown in Notifications:
[ 31 ]
Moodle Installation
Summary
In this chapter, you learned how to install Moodle on the most popular operating
systems and upgrade the LMS. You also learned how to use the powerful commandline interface.
The fact that Moodle uses a portable software architecture and facilitates standard
open source components allows the installation on multiple platforms. However,
this also means that different idiosyncrasies have to be considered in different
environments.
Now that your system is up and running, let's have a look at the components of
Moodle, which will provide you with a better understanding of the system and how
to administer it.
[ 32 ]
www.PacktPub.com
Stay Connected: