
Setting up Moodle, the widely-used open-source learning platform, on a Debian 12 system provides a stable and robust environment for your educational needs. This guide walks you through the process, ensuring a smooth installation.
Before you begin, ensure your Debian 12 server is updated and you have root or sudo privileges. You will also need a LAMP (Linux, Apache, MariaDB, PHP) stack installed and configured.
First, update your package list and upgrade existing packages:
sudo apt update
sudo apt upgrade -y
Moodle requires a web server (Apache), a database server (MariaDB is recommended), and PHP with various extensions. Install these components:
sudo apt install apache2 mariadb-server php php-cli php-fpm php-mysql php-xml php-curl php-intl php-gd php-zip php-mbstring php-soap php-xmlrpc php-json -y
Next, secure your MariaDB installation. Run the security script:
sudo mysql_secure_installation
Follow the prompts to set the root password, remove anonymous users, disallow remote root login, and remove the test database.
Now, create a database and user for Moodle in MariaDB. Log in as the root user:
sudo mysql -u root -p
Enter your root password. Then, run these commands, replacing moodle_database
, moodle_user
, and your_password
with your desired names and a strong password:
CREATE DATABASE moodle_database CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'moodle_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON moodle_database.* TO 'moodle_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Download the latest stable version of Moodle. It’s best to get it from the official Moodle website. Use wget
or curl
.
wget https://download.moodle.org/stable403/moodle-4.3.3.zip
(Replace URL with the current stable version)
Unzip the downloaded archive into the Apache webroot directory.
sudo unzip moodle-4.3.3.zip -d /var/www/html/
This will create a directory named moodle
inside /var/www/html/
.
Create a data directory for Moodle outside the webroot, which is essential for security.
sudo mkdir /var/www/moodledata
Set the correct permissions for the Moodle and moodledata directories, ensuring the web server user (typically www-data
) owns them.
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
(Note: 777 for moodledata is commonly recommended during setup but review Moodle documentation for stricter permissions post-install if needed).
Configure Apache to serve the Moodle site. Create a new virtual host file.
sudo nano /etc/apache2/sites-available/moodle.conf
Paste the following configuration, adjusting ServerName to your domain or IP address:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName your_domain_or_IP
DocumentRoot /var/www/html/moodle
<Directory /var/www/html/moodle/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save and close the file. Enable the new site and the rewrite module, then restart Apache.
sudo a2ensite moodle.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
Finally, open your web browser and navigate to your server’s domain name or IP address (e.g., http://yourdomainor_IP). This will start the Moodle web installation wizard. Follow the on-screen instructions:
- Confirm the installation path and data directory path (
/var/www/moodledata
). - Select MariaDB as the database driver.
- Enter your database details: Database host (localhost), Database name (moodledatabase), Database user (moodleuser), and the password you created.
- The wizard will check server requirements. Ensure all checks pass.
- Continue through the installation process, which involves writing configuration files and setting up database tables.
- Set up your Moodle administrator account and site details.
Once the web installation is complete, your Moodle LMS should be accessible and ready for configuration. Remember to configure the Moodle cron job for scheduled tasks to function correctly. This typically involves adding a line to the system’s crontab to run the admin/cli/cron.php
script regularly.
Source: https://www.howtoforge.com/tutorial/debian-moodle-e-learning-platform/