Host your E-Learning platform with Moodle

schBenedikt - Aug 10 '23 - - Dev Community

If you like this article, we would appreciate a comment and a like! ❤️


In this guide we will show you today how to install the learning platform Moodle.

It's best if we start right now!


Don't you like to do this installation or don't have the possibility? Then register on our website, here you also have the option to create your own courses for free.
We would be pleased!


We switch to the terminal, and then with

cd /var/www/

in our data directory.

Here we also download the latest Moodle files

sudo wget https://github.com/moodle/moodle/archive/refs/heads/master.zip

In our case, this ZIP file is now called "moodle-4.2.1.zip" and we unpack it

sudo unzip master.zip

And we've already unzipped the folder. If you want, we can move or rename the folder, we'll take care of everything

mv foldername folderpath

We rename the folder that has now been extracted (moodle-master) to "moodle".

We'll do that

sudo mv moodle-master/ moodle/

Then we still have to adjust the permissions, we'll do that with you

sudo chown -R root moodle/
sudo chmod -R 0755 moodle/

Now we have to create our database.

We'll do that

sudo mysql
CREATE DATABASE database-name;
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
EXIT;

You can define the username, database name and user password as you wish - but we will need the data again later!

When we have done that, we can already call up the IP address/moodle and we have arrived at our web installer!

Optionally, we can now specify a domain.

For this we create

sudo nano /etc/apache2/sites-available/moodle.conf

a new file.

The content can look something like this:

<VirtualHost *:80>
      ServerAdmin master@domain.com
      DocumentRoot /var/www/moodle/
      Server name learn.xn--schchner-2za.de
      Server alias www.learn.schächner.de
      Alias /moodle "/var/www/moodle/"
      <Directory /var/www/moodle/>
         Options+FollowSymlinks
         AllowOverrideAll
         Require all granted
           <IfModule mod_dav.c>
             dav off
           </IfModule>
         SetEnv HOME /var/www/moodle
         SetEnv HTTP_HOME /var/www/moodle
      </Directory>
      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =learn.xn--schchner-2za.de [OR]
RewriteCond %{SERVER_NAME} =www.learn.schächner.de
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Enter fullscreen mode Exit fullscreen mode

We activate the page with,

sudo a2ensite moodle.conf

adjust the privileges again:

sudo chown -R www-data:www-data /var/www/moodle/
sudo chmod -R 755 /var/www/moodle/

and restart our web server:

sudo service apache2 restart
sudo systemctl restart apache2.service

Now all we need is a Let's Encrypt SSL certificate to keep our website secure.

For that we run this code:

sudo certbot --apache

Here we have to choose our domain with the number and it's done!

Now we can really start installing Moodle on the web.

Note here that you open the web installer via the IP address!

First we choose our language

Image description

Then we need to confirm our paths.

Image description

You can either create the data directory yourself (it is not safe in the specified folder) or we can create the directory ourselves

sudo mkdir /var/moodledata/
sudo chmod 0777 /var/moodledata/

Then we have that too.

Image description

We let that as it is.

Image description

Here you have to enter the password and username from the database. You can leave the last two fields empty.

Image description

Now we have to confirm the conditions.

And then everything is checked again:

Image description

If the PHP extension is missing, you can usually use it with

sudo apt install php-EXTENSIONNAME

to install.

But the red bug is worse; to do this we need to edit the config.php file. We'll do that

sudo nano config.php

And here we change the line

$CFG->dbtype = 'mysqli';

to

$CFG->dbtype = 'mariadb';

around.

At the bottom is the error because of the max_input_vars.

We can remove it by adding in the file with

sudo nano /etc/php/8.1/apache2/php.ini

open and the line

;max_input_vars = 1000
Enter fullscreen mode Exit fullscreen mode

to

max_input_vars = 5000
Enter fullscreen mode Exit fullscreen mode

adjust.

NOTE THAT PHP 8.2 WILL NOT WORK!

Then we start the server and PHP

sudo service apache2 reset

new.

Image description

If this error comes up, you have to wait a few minutes or start the installation again.

You can also simply try to check the permissions again.

Image description

(almost 6 hours later when we finally solved the problem)

Here we see that everything is finally ready.

Then we go to "next"

Image description

and make general settings - it doesn't matter how you configure them!

Image description

Image description

Last but not least, we specify the name of the website and other settings.

Thanks for reading,
Schächner

. . . . . . . . . . . . . .