Installing Moodle

From Newroco tech docs
Jump to navigationJump to search


  2. sudo apt-get install apache2
  3. sudo apt-get install graphviz aspell php-pspell php-xmlrpc php-ldap php-soap
  4. sudo apt-get install php-gd php-json php-pgsql php-curl
  5. sudo apt-get install php-intl php-mcrypt php-imagick
  6. sudo apt-get install php-zip php-xml php-mbstring php-ldap libapache2-mod-php
  7. sudo apt-get install postgresql postgresql-contrib

Creating Moodle Database

These instructions assume that the database server and web server are on the same machine

Log into the PostgreSQL command line client. The exact form depends on how your PostgreSQL is configured but will be something like

  2. $ psql -U postgres
  3. Password for user postgres:

Create the user for the Moodle database and assign a password:

  2. postgres=# CREATE USER moodleuser WITH PASSWORD 'quickM@ss50';

Provide a suitably strong password. Please note that the actual authentication method depends on your PostgreSQL server's pg_hba.conf file. Some authentication methods (like ident) do not require the password.

Create the database:

  2. postgres=# CREATE DATABASE moodle WITH OWNER moodleuser;

Edit PostgreSQL settings to allow local connections for yourdbuser to the nextcloud database (on all DB servers):

# vi /etc/postgresql/<version number>/main/pg_hba.conf

Adding a line before the default "local" permission line e.g.

  2. # "local" is for Unix domain socket connections only
  3. local all moodleuser trust
  4. local all all peer

Then restart postgresql

  2. systemctl restart postgresql

Download and copy files into place

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.

  2. cd /opt

Download the Moodle Code and Index

  2. sudo git clone git://
  4. or
  6. sudo git clone git://

If the error appear

  2. fatal: The remote end hung up unexpectedly7.96 MiB | 179.00 KiB/s
  3. fatal: early EOF
  4. fatal: index-pack failed


  2. git config --global http.postBuffer 524288000


  2. git config --global core.compression 0
  4. Next, let's do a partial clone to truncate the amount of info coming down:
  6. git clone --depth 1 <repo_URI>
  8. When that works, go into the new directory and retrieve the rest of the clone:
  10. git fetch --unshallow
  12. or, alternately,
  14. git fetch --depth=2147483647
  16. Now, do a regular pull:
  18. git pull --all
  19. </code/
  21. Change directory into the downloaded Moodle folder
  22. <code>
  23. cd moodle

Retrieve a list of each branch available

  2. sudo git branch -a

Tell git which branch to track or use

  2. sudo git branch --track MOODLE_33_STABLE origin/MOODLE_33_STABLE

Finally, Check out the Moodle version specified

  2. sudo git checkout MOODLE_33_STABLE

Copy local repository to /var/www/html/

  2. sudo cp -R /opt/moodle /var/www/html/
  3. sudo mkdir /var/moodledata
  4. sudo chown -R www-data /var/moodledata
  5. sudo chmod -R 777 /var/moodledata
  6. sudo chmod -R 0755 /var/www/html/moodle


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.


While there are now a number of places you can get the Moodle code, you are strongly advised to obtain Moodle from If you run into problems it will be a great deal easier to support you.

Start Moodle install

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:

  2. sudo chmod -R 777 /var/www/html/moodle


  2. Change the path for moodledata : /var/moodledata
  4. Database type : postgresql
  6. Database Settings
  8. Host server: localhost
  10. Database: moodle
  12. User: moodledude (the user you created when setting up the database)
  14. Password: passwordformoodledude (the password for the user you created)
  16. Tables Prefix: mdl_
  18. Open your browser and go to http://IP.ADDRESS.OF.SERVER/moodle


  2. sudo -u www-data /usr/bin/php7.0 admin/cli/install.php
  4. .-..-.
  5. _____ | || |
  6. /____/-.---_ .---. .---. .-.| || | .---.
  7. | | _ _ |/ _ \/ _ \/ _ || |/ __ \
  8. * | | | | | || |_| || |_| || |_| || || |___/
  9. |_| |_| |_|\_____/\_____/\_____||_|\_____)
  11. Moodle 3.3.1+ (Build: 20170714) command line installation program
  12. -------------------------------------------------------------------------------
  13. == Choose a language ==
  14. en - English (en)
  15. ? - Available language packs
  16. type value, press Enter to use default value (en)
  17. : en
  18. -------------------------------------------------------------------------------
  19. == Data directories permission ==
  20. type value, press Enter to use default value (2777)
  21. :
  22. -------------------------------------------------------------------------------
  23. == Web address ==
  24. type value
  25. :
  26. -------------------------------------------------------------------------------
  27. == Data directory ==
  28. type value, press Enter to use default value (/var/www/moodledata)
  29. : /var/moodledata
  30. -------------------------------------------------------------------------------
  31. == Choose database driver ==
  32. pgsql
  33. type value, press Enter to use default value (pgsql)
  34. : pgsql
  35. -------------------------------------------------------------------------------
  36. == Database host ==
  37. type value, press Enter to use default value (localhost)
  38. : localhost
  39. -------------------------------------------------------------------------------
  40. == Database name ==
  41. type value, press Enter to use default value (moodle)
  42. : moodle
  43. -------------------------------------------------------------------------------
  44. == Tables prefix ==
  45. type value, press Enter to use default value (mdl_)
  46. : mdl_
  47. -------------------------------------------------------------------------------
  48. == Database port ==
  49. type value, press Enter to use default value ()
  50. : 5432
  51. -------------------------------------------------------------------------------
  52. == Database user ==
  53. type value, press Enter to use default value (root)
  54. : user_moodle
  55. -------------------------------------------------------------------------------
  56. == Database password ==
  57. type value
  58. : parola_moodle
  59. -------------------------------------------------------------------------------
  60. == Full site name ==
  61. type value
  62. : Moodle
  63. -------------------------------------------------------------------------------
  64. == Short name for site (eg single word) ==
  65. type value
  66. : Moodle
  67. -------------------------------------------------------------------------------
  68. == Admin account username ==
  69. type value, press Enter to use default value (admin)
  70. : admin_moodle
  71. -------------------------------------------------------------------------------
  72. == New admin user password ==
  73. type value
  74. : parola_moodle
  75. -------------------------------------------------------------------------------
  76. == New admin user email address ==
  77. type value, press Enter to use default value ()
  78. :
  79. -------------------------------------------------------------------------------
  80. == Upgrade key (leave empty to not set it) ==
  81. type value
  82. :
  83. -------------------------------------------------------------------------------
  84. == Copyright notice ==
  85. Moodle - Modular Object-Oriented Dynamic Learning Environment
  86. Copyright (C) 1999 onwards Martin Dougiamas (
  88. This program is free software: you can redistribute it and/or modify
  89. it under the terms of the GNU General Public License as published by
  90. the Free Software Foundation, either version 3 of the License, or
  91. (at your option) any later version.
  93. This program is distributed in the hope that it will be useful,
  94. but WITHOUT ANY WARRANTY; without even the implied warranty of
  97. See the Moodle License information page for full details:
  100. Have you read these conditions and understood them?
  101. type y (means yes) or n (means no)
  102. : y
  103. -------------------------------------------------------------------------------
  104. == Setting up database ==
  105. -->System
  106. ++ Success ++

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

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

For http

append into the confing file /var/www/http/moodle/config.php

  2. $CFG->sslproxy=true;

Upgrade moodle to a new version

Verify the version prerequisites<version>_release_notes.

Set up moodle into maintenance mode

  1. sudo -u www-data /usr/bin/php /var/www/html/moodle/admin/cli/maintenance.php --enable

Backup the moodle folder (THere no need to copy the hole folder. Just need to have a copy of the custom changes to moodle : theme, config.php, custom plugins )

  1. cp -r /var/www/html/moodle/ /opt/old_moodle

Obtaining the new code from Git ( [guide |] )

  2. cd /opt
  3. git clone git://
  4. cd moodle
  5. git branch -a (2)
  6. git branch --track MOODLE_35_STABLE origin/MOODLE_35_STABLE (3)
  7. git checkout MOODLE_35_STABLE

Notice: If it doesn't work and pops up a message about "stash" just do:

  2. git stash

And afterwards redo the above step.

Delete the old version ( Don't make your life harder make a back-up of the folder before deleting, or a snapshot of the vm )

  2. rm -rf /var/www/html/moodle

Copy the new version and the custom config

  2. cp -r /opt/moodle /var/www/html/
  3. cp /opt/old_moodle/config.php /var/www/html/moodle/
  4. cp -r /opt/old_moodle/theme/boost /var/www/html/moodle/theme/

Copy all the additionally installed blocks and plugins (compare the new moodle directory with the old_moodle directory and copy all the plugins or bloks):

  2. cd /opt/old_moodle/blocks
  3. cp -r community attendance teaching_team karma participants quickfindlist turnitin /var/www/html/moodle/blocks
  4. sudo cp -r /opt/old_moodle/local/mass_enroll /var/www/html/moodle/local
  5. sudo cp -r /opt/old_moodle/grade/grading/form/multigraders /var/www/html/moodle/grade/grading/form
  6. sudo cp -r /opt/old_moodle/mod/scheduler /var/www/html/moodle/mod/
  7. sudo cp -r /opt/old_moodle/mod/turnitintooltwo /var/www/html/moodle/mod/
  8. sudo cp -r /opt/old_moodle/plagiarism /var/www/html/moodle/

Run the installer via command line or by disabling the maintenance mode opening the browser and accessing the moodle address To not have problems with folder rights run

  2. sudo chown -R www-data:www-data /var/www/html/moodle
  3. sudo chmod -R 0777 /var/www/html/moodle
  4. sudo chmod -R 0444 /var/www/html/moodle/config.php
  5. sudo -u www-data /usr/bin/php /var/www/html/moodle/admin/cli/upgrade.php

After the installer has finished with success restore rights on the folder

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

Disable maintenance mode

  1. sudo -u www-data /usr/bin/php /var/www/html/moodle/admin/cli/maintenance.php --disable

From the web app purge the theme cache:

  2. Home/Site administration/Development/Purge caches

Notice: After disabling the maintenance mode go to your website and finish the upgrade process via interface. Afterwards it might pop up the update plugins, check if they are stable with the current version of the moodle update and do them. If everything goes well it will pop up a reports page with the status of each settings, for safety reasons move the node_modules from moodle folder or delete it so it wont have a security breach due to it.Also for config.php if it pops up warning/critical messages you should leave permissions only for read to the file. And via moodle interface -> site administration -> disable the following if they pop up in the reports ... .swf , enable site(secure) cookies. For web cron warning enable the setting that will not allow anonymous users to access cron. via search

Bug : errors generated by /var/www/html/moodle/lib/form/filemanager.js

Since V3.9 the configuration has changed and the custom theme settings might hide or disable some buttons or functions. In this case /var/www/html/moodle/lib/form/filemanager.js is accessing some buttons without checking if they exist resulting in errors that prevent the rest of the code to run. The fix is to add some conditions to check these buttons exist on the interface before adding triggers or style to them. Also check /var/www/html/moodle/lib/navigation.php for any configuration options!!!

Bug : outcomes do not appear in right order on grader

Check the name of the outcomes that have this problem. Find their id into the moodle database and change the id of them to be into the right order.

update mdl_grade_items set itemnumber = 1005 where id = 2097; update mdl_grade_items set itemnumber = 1001 where id = 2098;

Reset User Password

Note: Run the command with a space in front of it so it is not stored in the commands history

  1. sudo -u www-data /usr/bin/php <moodle_path>/admin/cli/reset_password.php --username=<username> --password=<password>

Bug : login does not work after update

Since 3.5 or so they implemented a security fix , but since not all the plugins haven't yet implemented this feature not even in 3.6 one quickaround would be to edit config.php and add the following line :

//security check for moodle <---> plugins disable token

$CFG->disablelogintoken = true;

Bug : save settings doesnt work

Spawned at 3.5 + so on update to 3.6+ or other version it might pop up go to moodle->theme->boost->core_admin->settings.mustache and add the following :

           <input type="hidden" name="Template:Name" value="Template:Value">
           <input type="hidden" name="action" value="save-settings">   <----- this is the line that needs to be added

Increase disk space

The second disk used for moodle date has no partition created (e.g. /dev/vda1), instead it's using the whole disk (/dev/vda) as a partitionless filesystem. If you need to increase it here's how you can do it.

Put moodle in maintenance mode:

  1. sudo -u www-data /usr/bin/php /var/www/html/moodle/admin/cli/maintenance.php --enable

Go to the host, shutdown the VM, increase the disk image and start the VM.

  1. virsh shutdown moodle
  3. qemu-img resize /moodle_data/moodle_data.qcow2 +50G
  5. virsh start moodle

After the VM started SSH back to the moodle VM and increase the volume at the VM level as well

  1. umount /dev/vda
  3. e2fsck -f /dev/vda
  5. resize2fs /dev/vda
  7. mount /dev/disk/by-uuid/8642b96b-5e42-4211-b116-a86726398693 /var/moodledata

After finishing disable the maintenance mode on moodle

  1. sudo -u www-data /usr/bin/php /var/www/html/moodle/admin/cli/maintenance.php --disable