DebianDebian Based

How To Install Moodle on Debian 12

Install Moodle on Debian 12

In this tutorial, we will show you how to install Moodle on Debian 12. Moodle stands out as a beacon of open-source learning management systems (LMS). Renowned for its flexibility and robustness, Moodle caters to educators’ and learners‘ diverse needs, offering a platform for creating personalized learning environments.

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 the Moodle learning management system on Debian 12 (Bookworm).

Prerequisites

Before proceeding with the installation of Moodle on Debian 12, ensure you meet the following requirements:

  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • 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).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Moodle.
  • A user account with sudo privileges to execute administrative commands.

Install Moodle on Debian 12 Bookworm

Step 1. Start by updating your system packages to ensure everything is up-to-date. This step is crucial for security and performance:

sudo apt update
sudo apt upgrade

Step 2. Installing the LAMP stack.

A Debian 12 LAMP server is required. If you do not have LAMP installed, Please read our previous tutorial to install LAMP Server on Debian Linux.

Step 3. Installing Moodle on Debian 12.

Download Moodle from the official repository and set the correct permissions:

cd /var/www/html
sudo git clone https://github.com/moodle/moodle.git

Moodle requires a directory for course files:

sudo mkdir /var/www/moodledata

Correct permissions are critical for security and functionality:

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

Step 4. Setting Up MySQL for Moodle.

First, log in to MySQL as the root user:

sudo mysql -u root -p

Create a dedicated database and user for Moodle:

CREATE DATABASE moodle CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'your-strong-password';
GRANT ALL PRIVILEGES ON moodle.* TO 'moodleuser'@'localhost';
FLUSH PRIVILEGES;

Step 5. Configuring Apache for Moodle.

Create a virtual host file for your Moodle site. Replace your_domain.com with your actual domain name:

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

 Insert the configuration, adjusting for your domain:

<VirtualHost *:80>
    ServerAdmin admin@your_domain.com
    DocumentRoot /var/www/html/moodle
    ServerName your_domain.com

    <Directory /var/www/html/moodle>
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/moodle_error.log
    CustomLog ${APACHE_LOG_DIR}/moodle_access.log combined
</VirtualHost>

Enable the site and restart Apache:

sudo a2ensite moodle.conf
sudo systemctl restart apache2

Step 6. Configure Firewall.

To configure the firewall (UFW) for Moodle on Debian 12, follow these steps:

sudo apt install ufw

Before enabling UFW, ensure that SSH connections are allowed to prevent being locked out of your server:

sudo ufw allow ssh

Then, enable UFW:

sudo ufw enable

For a Moodle installation, you need to allow web traffic on both HTTP (port 80) and HTTPS (port 443). Execute the following commands to allow traffic on these ports:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

Whenever you make changes to your UFW rules, it’s a good practice to reload the firewall to apply the changes:

sudo ufw reload

Step 7. Setup HTTPS Let’s Encrypt.

To set up HTTPS with Let’s Encrypt for Moodle on Debian 12, you will need to install and configure Certbot, a free tool that automates the installation of Let’s Encrypt SSL certificates:

sudo apt update
sudo apt install certbot python3-certbot-apache

Run Certbot to obtain an SSL certificate and configure your Apache server to use it:

sudo certbot --apache

During the process, you will be prompted to enter an email address for notifications, agree to the terms of service, and choose whether or not to redirect HTTP traffic to HTTPS.

Step 8. Completing the Moodle Installation.

Navigate to https://your_domain.com to complete the installation through Moodle’s web interface. Follow the on-screen instructions, using the database details created earlier.

Install Moodle on Debian 12 Bookworm

Install Moodle on Debian 12 Bookworm

Step 7. Configure Cron for Moodle.

Set up a cron job to automate Moodle tasks:

sudo crontab -u www-data -e

Add the following line to execute Moodle cron every minute:

* * * * * /usr/bin/php /var/www/html/moodle/admin/cli/cron.php >/dev/null

Congratulations! You have successfully installed Moodle. Thanks for using this tutorial to install the latest version of the Moodle learning management system on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official Moodle website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button