How To Install Moodle on Rocky Linux 9
In this tutorial, we will show you how to install Moodle on Rocky Linux 9. For those of you who didn’t know, Moodle, a widely-used open-source Learning Management System (LMS), has revolutionized the way educational institutions and businesses deliver online learning content. Its user-friendly interface, extensive features, and customization options make it an ideal choice for creating and managing online courses. Rocky Linux 9, a stable and reliable community-driven operating system, provides a solid foundation for hosting Moodle.
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 online Learning Management System (LMS) on Rocky Linux. 9.
Prerequisites
- A server running one of the following operating systems: Rocky Linux 9.
- 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
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 Rocky Linux 9
Step 1. To begin, it’s crucial to update your Rocky Linux 9 system to ensure that you have the latest security patches and software updates. Open your terminal and run the following commands:
sudo dnf check-update sudo dnf install dnf-utils
These commands will fetch and install any available updates for your system packages. It’s a good practice to keep your system up to date to maintain stability and security.
Step 2. Installing Apache.
By default, Apache is available on the Rocky Linux 9 base repository. Now we install the latest version of Apache using dnf
the command:
sudo dnf install httpd httpd-tools
You can start the httpd
service and configure it to run on startup by entering the following commands:
sudo systemctl start httpd sudo systemctl enable httpd sudo systemctl status httpd
To make your pages available to the public, you will have to edit your firewall rules to allow HTTP and HTTPS requests on your web server by using the following commands:
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
For additional resources on installing Apache, read the post below:
Step 3. Installing PHP.
PHP is a popular scripting language that powers the dynamic content of millions of websites and apps. Now we run the commands below to install PHP:
sudo dnf epel-release sudo dnf module enable php:remi-8.3
Once the Remi PHP 8.3 module is enabled, you can now install PHP 8.3 and commonly used PHP extensions as follows:
sudo dnf install php php-cli php-fpm php-gd php-curl php-zip php-mbstring php-opcache php-intl php-mysqlnd
Check and verify the installed version:
php -v
For additional resources on installing PHP, read the post below:
Step 4. Installing MariaDB.
By default, MariaDB is available on the Rocky Linux 9 base repository. Simply install the MariaDB package by using the dnf
command:
sudo dnf install mariadb-server mariadb
After the installation is completed, start the service of the Database server and then enable the same, so that it can start itself automatically with the system reboot:
sudo systemctl restart mariadb sudo systemctl status mariadb sudo systemctl enable mariadb
By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation
script. you should read 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
First, log into the MariaDB shell with the following command:
mysql
Now we create a database and user for Moodle with the following command:
MariaDB [(none)]> CREATE DATABASE moodledb DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; MariaDB [(none)]> create user 'moodleuser'@'localhost' IDENTIFIED BY 'Your-Str0ng-Passwd'; MariaDB [(none)]> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodledb.* TO 'moodleuser'@'localhost'; MariaDB [(none)]> flush privileges; MariaDB [(none)]> exit;
For additional resources on installing MariaDB Database, read the post below:
Step 5. Installing Moodle on Rocky Linux 9.
Now run the following command below to download the latest version of Moodle from the official page:
wget -c https://download.moodle.org/download.php/stable404/moodle-latest-404.tgz
Next, extract the downloaded file:
tar -xzvf moodle-latest-404.tgz mv moodle /var/www/html/
We will need to change some folders permissions:
chmod 770 -R /var/www/html/moodledata chown apache:apache -R /var/www/html/moodledata
Step 6. Configure Moodle.
First, change into the previously extracted Moodle folder. For example:
cd /var/www/html/moodle/ cp config-dist.php config.php nano config.php
Set the correct database type, correct database host, database name, database user, and the user’s password:
$CFG->dbtype = 'mariadb'; // 'pgsql', 'mariadb', 'mysqli', 'auroramysql', 'sqlsrv' or 'oci' $CFG->dblibrary = 'native'; // 'native' only at the moment $CFG->dbhost = 'localhost'; // eg 'localhost' or 'db.isp.com' or IP $CFG->dbname = 'moodledb'; // database name, eg moodle $CFG->dbuser = 'moodleuser'; // your database username $CFG->dbpass = 'Your-Str0ng-Passwd'; // your database password $CFG->prefix = 'mdl_'; // prefix to use for all table names
Also, set the URL used to access your Moodle site:
$CFG->wwwroot = 'https://learning.your-domain.com'; $CFG->sslproxy = 'https'; $CFG->dataroot = '/var/www/html/moodledata';
Step 6. Configure Apache for Moodle.
Now we configure the Moodle VirtualHost file using the following command below:
nano /etc/httpd/conf.d/moodle.conf
Add the following file:
<VirtualHost *:80> ServerName learning.your-domain.com ServerAlias www.learning.your-domain.com ServerAdmin admin@your-domain.com DocumentRoot /var/www/html/moodle/ <Directory /var/www/html/moodle> Options Indexes FollowSymLinks AllowOverride All Require all granted RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] </Directory> </VirtualHost>
Save and close the file, then restart the Apache service to apply the changes:
sudo systemctl restart httpd
Step 7. Securing Moodle,
Enabling HTTPS on Moodle on Rocky Linux is crucial for securing your data and ensuring that no unauthorized user can access your Moodle site. In this section, we will guide you through the steps required to enable HTTPS on your Moodle instance running on Rocky Linux.
The first step in enabling HTTPS is to install Certbot. Certbot is a free and open-source tool that automatically configures HTTPS on your server. To install Certbot on Rocky Linux, use the following command:
sudo dnf install certbot python3-certbot-apache
Once Certbot is installed, you can use it to generate an SSL certificate for your Moodle site. Use the following command to generate an SSL certificate:
sudo certbot --apache -d learning.your-domain.com
Step 8. Accessing Moodle Web Interface.
Once successfully installed, open your web browser and access Moodle using the URL https://learning.your-domain.com
. You will be redirected to the following page:
Congratulations! You have successfully installed Moodle. Thanks for using this tutorial for installing Moodle Learning Platform or course management system (CMS) on your Rocky Linux 9 system. For additional help or useful information, we recommend you check the official Moodle website.