How to install Moodle on Debian 9

/ Category: Tutorials / Comments: 5

how to install moodle on debian 9
Spread the love

Moodle is a free and open-source learning management system designed to provide teachers or educators the tools to create personalized learning environments filled with dynamic online courses which help students and other users to achieve their learning goals. Today we will learn how to install the latest Moodle 3.5 version on Debian 9, with Apache web server, MariaDB and PHP 7.

Moodle comes with hundreds of built-in features such as:

  • Modern and easy to use interface
  • Personalized Dashboard
  • Collaborative tools and activities
  • All-in-one calendar
  • Secure authentication and mass enrollment
  • Multilingual capability
  • Direct learning paths
  • Multimedia Integration
  • Customizable site design and layout
  • and much more …

1. Login via SSH

Connect to your server via SSH as user root, using the following command:

ssh [email protected]IP_ADDRESS -p PORT_NUMBER

make sure that you replace “IP_ADDRESS” and “PORT_NUMBER” with your actual server IP address and SSH port number.

2. Update the OS Packages

Once logged in, run the following command to update your OS packages:

apt-get update
apt-get upgrade

3. Install Apache Web Server

To install the Apache web server on your server, run the following command:

apt-get install apache2

Once the installation is complete, you need to start Apache and enable it to start automatically upon system boot

systemctl start apache2
systemctl enable apache2

4. Install MariaDB

Moodle stores most of its data in a database, so we will install the MariaDB database server:

apt-get install mysql-client mysql-server

When the MariaDB installation is complete, run the following command to secure your MariaDB installation:


5. Install PHP 7

Next, we will install PHP 7 and all the additional PHP modules which will be required by Moodle:

apt-get install php7.0 libapache2-mod-php7.0 php7.0-pspell php7.0-curl php7.0-gd php7.0-intl php7.0-mysql php7.0-xml php7.0-xmlrpc php7.0-ldap php7.0-zip php7.0-soap php7.0-mbstring

6. Download and install Moodle

Before we download the moodle package, first let’s navigate to the default Apache web server root directory:

cd /var/www/html

To download the latest moodle package, use the following command:



[email protected]:/# wget
--2018-09-15 12:56:34--
Resolving (,, 2400:cb00:2048:1::6814:da19, ...
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 46447511 (44M) [application/x-gzip]
Saving to: 'moodle-latest-35.tgz'

moodle-latest-35.tgz 100%[=====================================================================================================>] 44.29M 60.7MB/s in 0.7s

2018-09-15 12:56:36 (60.7 MB/s) - 'moodle-latest-35.tgz' saved [46447511/46447511]

To extract the file, run the following command:

tar xzf moodle-latest-35.tgz

Change the ownership and the permissions of the extracted Moodle directory with the following command:

chown -R www-data:www-data /var/www/html/moodle
chmod -R 775 /var/www/html/moodle

Additionally, you will also need to create a directory for the Moodle data:

mkdir /var/www/html/moodledata

And set the correct ownership and permissions:

chown www-data:www-data /var/www/html/moodledata
chmod 775 /var/www/html/moodledata

7. Configure MariaDB and create a new database

Before you create a new moodle database, you will need to modify the default MariaDB configuration file. Moodle requires that you change the default storage engine to innodb and change the default file format to Barracuda. You will also need to set innodb_file_per_table in order for Barracuda to work properly.

To edit the MariaDB configuration file. Run the following command:

nano /etc/mysql/mariadb.conf.d/50-server.cnf

Then add the following lines just below the [mysqld] section:

default_storage_engine = innodb
innodb_file_per_table = 1
innodb_file_format = Barracuda
innodb_large_prefix = 1

Save and exit the file and restart the MariaDB server with:

systemctl restart mariadb

You can now log in to the MariaDB server as user root and create a new user and database for the Moodle installation:

mysql -u root -p
GRANT ALL PRIVILEGES ON moodle.* TO 'moodle_user'@'localhost' IDENTIFIED BY '<span style="color: #ff0000;">PASSWORD</span>';

Don’t forget to replace PASSWORD with an actual strong password.

8. Configure Apache Web Server

If you have a valid domain name which you would like to use to access your Moodle installation, you will need to create a new Apache virtual host for your domain name with the following content:

nano /etc/apache2/sites-available/
<VirtualHost *:80>
ServerAdmin [email protected]m
DocumentRoot /var/www/html/moodle

<Directory /var/www/html/moodle/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all

ErrorLog /var/log/apache2/
CustomLog /var/log/apache2/ common

Save the file and enable the virtual host with the following command:


Once you enable the virtual host, you will need to restart the Apache web server:

systemctl restart apache2

9. Finish the Moodle installation in your browser

If the DNS records are properly configured, and your domain is pointed to your server, you can use it to access your Moodle installation by typing in your browser and choose the preferred language to continue with the installation.

installing moodle on debian 9

Verify that all Moodle directory paths are correct and click on Next.

install moodle on debian 9

Choose the database type.

install moodle on debian

Enter the database name, username, and password of the moodle database we have created earlier.

Moodle Installation on Debian 9

Follow the on-screen instructions to finish the installation. In the end, you should see the following screen where you need to configure your main administrator account.

How do you install Moodle on Debian

Congratulations! You have now successfully installed Moodle on your server. For more information on how to configure and use Moodle, you can check their official documentation.

Of course, you don’t have to install Moodle on Debian 9, if you use one of our Managed Debian Cloud Hosting services, in which case you can simply ask our expert system administrators to install Moodle on Debian 9 for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, on how to install Moodle on Debian 9, please share it with your friends on the social networks using the buttons below or simply leave a comment in the comments section. Thanks.


  Comments: 5

  1. Matthew Towers

    There are a couple of errors in section 6 and 7:
    – you need to extract the .gz file of course, with tar xzf moodle-latest-35.tgz
    – the mkdir command should be mkdir moodledata, assuming you’re already in /var/www/html/
    – it’s systemctl restart mariadb, not systemctl mariadb restart
    If you install locally, your moodle page will be at localhost/moodle

  2. Very helpful for rookies!

  3. Many thanks for the detailed instructions.

    I found that in the last step, the password which I chose for moodle_user was not accepted.
    However, when I went back to step 7 and replaced ‘PASSWORD’
    by just ‘PASSWORD’, it worked.

    • Please try to use a strong password with uppercase and lowercase letters including numbers, for example, “LDGajs64KjxH”.

Responses to admin

Click here to cancel reply.