AlmaLinuxRHEL Based

How To Install Moodle on AlmaLinux 9

Install Moodle on AlmaLinux 9

In today’s digital age, online learning has become an essential part of education and training. Moodle, a powerful open-source Learning Management System (LMS), has gained popularity among educational institutions and organizations worldwide. Its flexibility, scalability, and user-friendly interface make it an ideal choice for delivering online courses and facilitating collaborative learning experiences. AlmaLinux 9, a stable and secure server operating system, provides a reliable foundation for hosting Moodle. In this comprehensive guide, we will walk you through the step-by-step process of installing Moodle on AlmaLinux 9, enabling you to create a robust online learning platform.

What is Moodle?

Moodle, short for Modular Object-Oriented Dynamic Learning Environment, is a free and open-source Learning Management System (LMS) designed to support online education and training. It offers a wide range of features, including course creation, user management, quizzes, assignments, forums, and multimedia integration. Moodle’s flexibility allows educators to create engaging and interactive learning experiences, fostering collaboration and communication among students and instructors. With its extensive plugin ecosystem and customization options, Moodle can be tailored to meet the specific needs of any educational institution or organization.

Prerequisites

Before embarking on the Moodle installation journey, ensure that you have the following prerequisites in place:

  • AlmaLinux 9 VPS (Virtual Private Server) with root access or a user with sudo privileges
  • Stable internet connection
  • SSH client (e.g., PuTTY for Windows or Terminal for macOS/Linux)

Additionally, familiarize yourself with basic Linux commands and navigation, as you will be working in the command-line interface throughout the installation process.

Step 1: Login to Your Server

To begin the installation, you need to log in to your AlmaLinux 9 server using SSH. Open your SSH client and enter the following command:

ssh username@server_ip

Replace “username” with your server’s username and “server_ip” with the IP address of your AlmaLinux 9 server. Press Enter and provide the password when prompted. Once logged in, you can verify the AlmaLinux version by running:

cat /etc/almalinux-release

This command will display the AlmaLinux version installed on your server.

Step 2: Update the System

Before proceeding with the Moodle installation, it’s crucial to update your AlmaLinux 9 system to ensure you have the latest security patches and software updates. Run the following commands to update and upgrade the system packages:

sudo dnf update -y
sudo dnf upgrade -y

These commands will fetch and install any available updates, keeping your system up-to-date and secure.

Step 3: Install PHP

Moodle relies on PHP to power its dynamic functionality. To install PHP 8.0 and the necessary extensions, follow these steps:

  1. Install the EPEL (Extra Packages for Enterprise Linux) repository:
sudo dnf install epel-release -y
  1. Install the Remi repository:
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y
  1. Enable the PHP 8.0 module:
sudo dnf module enable php:remi-8.3 -y
  1. Install PHP and the required extensions:
sudo dnf install php php-fpm php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-pgsql php-zip php-curl php-opcache php-intl php-iconv -y

After the installation, you can verify the PHP version by running:

php -v

To optimize PHP performance for Moodle, you may need to adjust some PHP settings in the configuration file. Open the PHP configuration file using a text editor:

sudo nano /etc/php.ini

Look for the following settings and modify them as needed:

memory_limit = 256M
upload_max_filesize = 100M
post_max_size = 100M
max_execution_time = 360
max_input_vars = 5000
date.timezone = "your_timezone"

Replace “your_timezone” with your desired timezone (e.g., “America/New_York”). Save the changes and exit the text editor.

Step 4: Install and Configure Nginx

Nginx is a high-performance web server that efficiently handles Moodle’s web requests. To install and configure Nginx, follow these steps:

  1. Install Nginx:
sudo dnf install nginx -y
  1. Start the Nginx service and enable it to start automatically on system boot:
sudo systemctl start nginx
sudo systemctl enable nginx
  1. Create a new Nginx server block configuration file for Moodle:
sudo nano /etc/nginx/conf.d/moodle.conf
  1. Paste the following configuration into the file:
server {
    listen 80;
    server_name your_domain.com;
    root /var/www/moodle;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm/www.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

Replace “your_domain.com” with your actual domain name. Save the changes and exit the text editor.

  1. Test the Nginx configuration for any syntax errors:
sudo nginx -t

If no errors are reported, restart the Nginx service to apply the changes:

sudo systemctl restart nginx

Step 5: Install and Secure MariaDB

MariaDB is a reliable and efficient database management system that Moodle uses to store and retrieve data. To install and secure MariaDB, follow these steps:

  1. Install MariaDB:
sudo dnf install mariadb-server -y
  1. Start the MariaDB service and enable it to start automatically on system boot:
sudo systemctl start mariadb
sudo systemctl enable mariadb
  1. Secure the MariaDB installation by running the security script:
sudo mysql_secure_installation

Follow the prompts to set a strong root password, remove anonymous users, disallow remote root login, remove the test database, and reload the privilege tables.

  1. Log in to the MariaDB shell as the root user:
sudo mysql -u root -p

Enter the root password when prompted.

  1. Create a new database and user for Moodle:
CREATE DATABASE moodle;
CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON moodle.* TO 'moodleuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace “your_password” with a strong password for the Moodle database user. Remember these credentials, as you will need them later during the Moodle installation.

Step 6: Download and Install Moodle

With the necessary prerequisites in place, you can now download and install Moodle. Follow these steps:

  1. Change to the web server directory:
cd /var/www/
  1. Download the latest stable version of Moodle:
wget https://download.moodle.org/download.php/stable404/moodle-latest-404.tgz 
  1. Extract the downloaded archive:
sudo tar -xzf moodle-latest-404.tgz
  1. Rename the extracted directory to “moodle”:
sudo mv moodle /var/www/moodle
  1. Set the appropriate ownership and permissions for the Moodle directory:
sudo chown -R nginx:nginx /var/www/moodle
sudo chmod -R 755 /var/www/moodle

Step 7: Configure Moodle Settings

Before finalizing the Moodle installation, you need to configure some essential settings. Follow these steps:

  1. Change to the Moodle directory:
cd /var/www/moodle
  1. Create a new configuration file by copying the sample file:
sudo cp config-dist.php config.php
  1. Open the configuration file in a text editor:
sudo nano config.php
  1. Locate the following lines and update them with your database connection details:
$CFG->dbtype = 'mariadb';
$CFG->dblibrary = 'native';
$CFG->dbhost = 'localhost';
$CFG->dbname = 'moodle';
$CFG->dbuser = 'moodleuser';
$CFG->dbpass = 'your_password';

Replace “your_password” with the password you set for the Moodle database user in Step 5.

  1. Set the data directory path:
$CFG->dataroot = '/var/www/moodledata';
  1. Save the changes and exit the text editor.
  1. Create the Moodle data directory and set the appropriate permissions:
sudo mkdir /var/www/moodledata
sudo chown -R nginx:nginx /var/www/moodledata
sudo chmod -R 755 /var/www/moodledata

Step 8: Configure SSL with Let’s Encrypt

To ensure secure connections and protect sensitive data, it’s essential to configure SSL (Secure Sockets Layer) for your Moodle site. Let’s Encrypt provides free SSL certificates. Follow these steps to configure SSL with Let’s Encrypt:

  1. Install the Certbot package and the Nginx plugin:
sudo dnf install certbot python3-certbot-nginx -y
  1. Obtain an SSL certificate for your domain:
sudo certbot --nginx -d your_domain.com

Replace “your_domain.com” with your actual domain name. Follow the prompts to provide an email address and agree to the Let’s Encrypt terms of service.

  1. Certbot will automatically configure Nginx to use the obtained SSL certificate. Verify the SSL configuration by accessing your Moodle site using HTTPS.

Step 9: Set Up Cron Job and Finalize Installation

Moodle relies on a cron job to perform scheduled tasks and maintain the system’s health. To set up the cron job and finalize the installation, follow these steps:

  1. Open the crontab file for the Nginx user:
sudo crontab -u nginx -e
  1. Add the following line to the crontab file:
*/5 * * * * php /var/www/moodle/admin/cli/cron.php >/dev/null

This cron job will run every 5 minutes, executing Moodle’s scheduled tasks.

  1. Save the changes and exit the crontab file.
  1. Open a web browser and access your Moodle site using the domain name you configured:
https://your_domain.com

Install Moodle on AlmaLinux 9

  1. Follow the on-screen instructions to complete the Moodle installation wizard. Provide the necessary information, such as site name, administrator account details, and language settings.
  1. Once the installation is complete, log in to your Moodle site using the administrator account you created during the installation process.

Congratulations! You have successfully installed Moodle. Thanks for using this tutorial for installing Moodle on the AlmaLinux system. 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