moodLearning Wiki


Run this command on screen every time you log in, so when you get cut off, you can just pick up from where you left off:

screen -dR primecut

Following the processes and commands below should enable you to run a fully functioning Moodle installation on a minimally endowed Ubuntu machine.


fallocate -l 1G /swapfile1G
mkswap /swapfile1G
swapon /swapfile1G
swapon -s
nano /etc/fstab

to add the ff entry:

/swapfile1G   none    swap    sw    0   0

Apache, PHP, MySQL

sudo add-apt-repository ppa:ondrej/php7.3
apt update && sudo apt upgrade
apt install -y mysql-client mysql-server php7.3 libapache2-mod-php7.3 php7.3-mysql php7.3-mysqli graphviz aspell ghostscript clamav php7.3-pspell php7.3-curl php7.3-gd php7.3-intl php7.3-xml php7.3-xmlrpc php7.3-ldap php7.3-zip php7.3-soap php7.3-mbstring apache2


  • install mysql
   apt install mysql
  • secure it and set the root password

Set your root password, remove anonymous users, disallow root's remote login, remove test database, reload privilege tables now.

  • set up the moodle database
  mysql -u root -p[rootpasswordhere]
CREATE user 'moodleadmin'@'localhost' IDENTIFIED BY 'Secur3P@zzwd';


sudo chown www-data:www-data -R /var/www/html/moodle
sudo chmod 775 -R /var/www/html/moodle
sudo mkdir -p /var/moodledata
sudo chmod 775 -R /var/moodledata
sudo chown www-data:www-data -R  /var/moodledata
cd /var/www/html/moodle/
sudo cp config-dist.php config.php
nano config.php

Set up your config.php

$CFG->dbtype    = 'mysql';    
$CFG->dblibrary = 'native';     
$CFG->dbhost    = 'localhost';  // eg 'localhost' or '' or IP
$CFG->dbname    = 'moodle';     
$CFG->dbuser    = 'moodleadmin';   // your database username
$CFG->dbpass    = 'Secur3P@zzwd';   // your database password
$CFG->prefix    = 'mdl_';       // prefix to use for all table names

$CFG->wwwroot   = 'http://<domain name>';
$CFG->dataroot  = '/var/moodledata';

Vhost Setup

  • Create your vhost config file
cd  /etc/sites-available/
<VirtualHost *:80> 
ServerAdmin [email protected]
DocumentRoot /var/www/html/moodle/ 
  <Directory /var/www/html/moodle/> 
  Options +FollowSymlinks 
  AllowOverride All 
  Require all granted 
ErrorLog ${APACHE_LOG_DIR}/error.log 
CustomLog ${APACHE_LOG_DIR}/access.log combined  
  • enable your vhost or site

sudo a2enmod rewrite

sudo a2ensite 
systemctl restart apache2

You may also have to disable the default vhost. Check the actual file. It could be

sudo a2dissite 000-default.conf
systemctl restart apache2

Moodle Setup

  • Set it up via
  • Fill out these fields:
    Web address: [ your IP address or domain name ]
    Moodle directory: /var/www/html/moodle
    Data Directory: /var/moodledata

Click next. Get to database section and fill out these fields:

    Database host: localhost
    Database name: moodle
    Database user: moodleadmin
    Database password: Secur3P@zzwd
    Tables prefix: mdl_

Get to the section where you have to set up the site administrator. Under General, you see

    New password: 
    First name: 

= Post-Installation=

Backup/Moving to Another Machine

  • Files to backup
   [ db backup ]
  • To backup db
 mysqldump -h localhost -u root --password=mypassword -C -Q -e --create-options moodle > moodle-database.sql
  • To restore db
mysql -u root -pmypassword moodle < moodle-database.sql


In case you don't have an email account that can be used to send out emails in bulk, you may also use the Moodle server itself as a send-only postfix mailer.

 sudo apt install mailutils

If prompted for type of mail configuration, just choose Internet site. For the system mail name, it is important you key in your FQDN (fully qualified domain name), the one reflected on your rDNS, so something like

Once done, you may configure your postfix:

 nano /etc/postfix/

Replace the appropriate lines with these:

inet_interfaces = loopback-only
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, $mydomain
sudo systemctl restart postfix

Once done, you may test your mailer with this:

 echo "Just testing the send-only postfix" | mail -s "Testing 1 2 3" <yourdestinationemailhere>

Note that the initial messages coming out of this server will be flagged as “spam”. If you want it to be “perfect” right from the get-go, you need to know more about TXT records, SPF, DKIM, Amavis. Otherwise, your mails will get better over time.

SSL Certificate

Every site needs encryption these days. So you may install an SSL Certificate on your site. This section requires that you have a proper rDNS entry on your machine and your DNS points to your machine's IP with an A/AAAA record.

 sudo apt install snapd
 sudo snap install --classic certbot
 sudo certbot --apache

We recommend an autoredirect to the secure site. Once done, confirm by adding S to your address in the “http”. So something like httpS://