In this tutorial, we will show you how to install Moodle on Debian 10. For those of you who didn’t know, Moodle is a free and open-source learning management system written in PHP and often deployed in Linux under Apache/Nginx web servers with PHP and MySQL/MariaDB database management system, also known as LAMP or LEMP stack.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of Moodle on a Debian 10 (Buster).
Prerequisites
- A server running one of the following operating systems: Debian 10 (Buster).
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Moodle on Debian 10 Buster
Step 1. Before running the tutorial below, it’s important to make sure your system is up to date by running the following apt
commands in the terminal:
sudo apt update
Step 2. Installing the LAMP stack.
A Debian 10 LAMP server is required. If you do not have LAMP installed, Please read our previous tutorial to install LAMP Server on Debian 10.
Step 3. Installing Moodle on Debian 10.
Now we download the latest Moodle package using the following command:
cd /var/www/html wget https://download.moodle.org/download.php/stable310/moodle-3.10.3.tgz
Extract the downloaded file:
tar xzf moodle-3.10.3.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
Next, create a data directory and set Moodle directory permissions:
mkdir /var/www/html/moodledata
Set ownership and permissions so that Apache can access the files:
chown www-data:www-data /var/www/html/moodledata chmod 775 /var/www/html/moodledata
Step 4. Configuring MariaDB for Moodle.
By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation
script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:
mysql_secure_installation
Configure it like this:
- Set root password? [Y/n] y - Remove anonymous users? [Y/n] y - Disallow root login remotely? [Y/n] y - Remove test database and access to it? [Y/n] y - Reload privilege tables now? [Y/n] y
Next, we will need to log in to the MariaDB console and create a database for Moodle. Run the following command:
mysql -u root -p
This will prompt you for a password, so enter your MariaDB root password and hit Enter. Once you are logged in to your database server you need to create a database for Moodle installation:
MariaDB [(none)]> CREATE DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; MariaDB [(none)]> GRANT ALL PRIVILEGES ON moodle.* TO 'moodle_user'@'localhost' IDENTIFIED BY 'your-strong-passwd'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> quit;
Once the database server is installed, open the configuration file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Then, add the below lines under [mysqld] section:
default_storage_engine = innodb innodb_file_per_table = 1 innodb_file_format = Barracuda innodb_large_prefix = 1
Step 5. Configure Apache Web Server.
Now we create a new Apache virtual host for your domain name with the following content:
nano /etc/apache2/sites-available/your-domain.com.conf
Add the following lines:
<VirtualHost *:80> ServerAdmin admin@your-domain.com DocumentRoot /var/www/html/moodle ServerName your-domain.com ServerAlias www.your-domain.com <Directory /var/www/html/moodle/> Options FollowSymLinks AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/yourdomain.com-error_log CustomLog /var/log/apache2/yourdomain.com-access_log common </VirtualHost>
Save the file and enable the virtual host with the following command:
sudo a2enmod rewrite sudo a2ensite your-domain.com.conf sudo systemctl restart apache2
Step 6. Accessing Moodle Web Interface.
Moodle will be available on HTTP port 80 by default. Open your favorite browser and navigate to http://your-domain.com
and complete the required steps to finish the installation.
Congratulations! You have successfully installed Moodle. Thanks for using this tutorial for installing the latest version of Moodle on the Debian system. For additional help or useful information, we recommend you check the official Moodle website.