In today’s digital era, eLearning platforms have become essential tools for educators and organizations worldwide. One such platform is Moodle, a free and open-source Learning Management System (LMS) that enables the creation of interactive online courses. If you’re using Rocky Linux 8 as your server, this guide will walk you through the step-by-step process of installing Moodle and configuring it for optimal performance.
Prerequisites
Before we dive into the installation process, let’s ensure that we have everything we need:
- A server running Rocky Linux 8
- A domain name pointing to the server (e.g., moodle.example.com)
- A non-root user with sudo privileges
To begin, update your system by running the following command:
$ sudo dnf update
Next, install essential utility packages that we’ll need throughout the installation process:
$ sudo dnf install wget curl nano unzip yum-utils -y
With the prerequisites in place, we can now proceed with the installation of Moodle on Rocky Linux 8.
Step 1 – Configure Firewall
First and foremost, let’s configure the firewall to allow HTTP and HTTPS traffic. Rocky Linux uses Firewalld Firewall, which we’ll work with in this step.
Check the status of the firewall by running the following command:
$ sudo firewall-cmd --state
If the firewall is running, proceed to list all active services and ports by executing:
$ sudo firewall-cmd --permanent --list-services
To enable Moodle’s functionality, we need to open the HTTP and HTTPS ports:
$ sudo firewall-cmd --add-service=http --permanent $ sudo firewall-cmd --add-service=https --permanent
Finally, reload the firewall to apply the changes:
$ sudo firewall-cmd --reload
Step 2 – Install Git
Moodle requires Git to fetch its application files. Install Git by running the following command:
$ sudo dnf install git
Step 3 – Install and Configure PHP
Now, let’s install PHP 8.0, the version recommended for Moodle. We’ll begin by adding the Epel and Remi repositories:
$ sudo dnf install epel-release $ sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Check the available PHP streams:
$ dnf module list php -y
Enable Remi’s PHP 8.0 repository:
$ sudo dnf module reset php -y $ sudo dnf module enable php:remi-8.0
After enabling the repository, install PHP and the required extensions:
$ sudo dnf install graphviz aspell ghostscript clamav php-fpm php-iconv php-curl php-mysqlnd php-cli php-mbstring php-xmlrpc php-soap php-zip php-gd php-xml php-intl php-json php-sodium php-opcache
Verify the installation by running:
$ php --version
Open the php.ini
file for editing:
$ sudo nano/etc/php.ini
Within the file, modify the following variables to set the mail attachment size to 25MB:
upload_max_filesize = 25M post_max_size = 25M
Uncomment the max_input_vars
variable by removing the semicolon and set its value to 5000:
max_input_vars = 5000
Save the changes and exit the editor.
Next, open the /etc/php-fpm.d/www.conf
file:
$ sudo nano /etc/php-fpm.d/www.conf
Find the lines user=apache
and group=apache
and change them to:
user = nginx group = nginx
Uncomment the socket file owner, group, and default permission lines, and modify them as follows:
listen.owner = nginx listen.group = nginx listen.mode = 0660
Comment out the listen.acl_users
line by adding a semicolon in front of it:
;listen.acl_users = apache,nginx
Save the changes and exit the editor.
To ensure proper permissions, run the following command:
$ sudo chown -R nginx:nginx /var/lib/php/session/
Finally, enable and start the PHP-FPM service:
$ sudo systemctl enable php-fpm --now
Step 4 – Install and Configure MySQL
Moodle requires a database to store its data. Let’s install and configure MySQL as the database server.
Install MySQL server:
$ sudo dnf install mysql-server
Confirm the installation by checking the version:
$ mysql --version
Enable and start the MySQL service:
$ sudo systemctl enable mysqld --now
Run the secure installation script to configure MySQL:
$ sudo mysql_secure_installation
Follow the prompts to set up the Validate Password Plugin, create a strong root password, and enhance the database security.
Once the secure installation is complete, log in to the MariaDB shell:
$ sudo mysql
Create a database for Moodle:
mysql> CREATE DATABASE moodledb DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Create an SQL user and grant access to the database:
mysql> CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'YourPassword23!'; mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodledb.* TO 'moodleuser'@'localhost'; mysql> FLUSH PRIVILEGES;
Exit the MariaDB shell:
mysql> exit
Step 5 – Install Nginx
Rocky Linux 8 ships with an older version of Nginx. To install the latest version, we’ll need to add the official Nginx repository.
Create and open the /etc/yum.repos.d/nginx.repo
file:
$ sudo nano /etc/yum.repos.d/nginx.repo
Copy and paste the following code into the file:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
Save the changes and exit the editor.
Install Nginx:
$ sudo dnf install nginx
Verify the installation:
$ nginx -v
Step 6 – Install Moodle
Now, let’s create the necessary directories and clone the Moodle repository.
Create the public directory for Moodle:
$ sudo mkdir /var/www/html/moodle
Grant permission to the logged-in user to access the directory:
$ sudo chown -R $USER:$USER /var/www/html/moodle
Switch to the public directory:
$ cd /var/www/html/moodle
Clone the Moodle GitHub repository:
$ git clone https://github.com/moodle/moodle.git.
Check the available branches:
$ git branch -a
Create and track the MOODLE400STABLE branch:
$ git branch --trackMOODLE_400_STABLE origin/MOODLE_400_STABLE
Switch to the newly created local branch:
$ git checkoutMOODLE_400_STABLE
Create a data directory for Moodle:
$ sudo mkdir /var/moodledata
Configure the necessary permissions for the Moodle data directory:
$ sudo chown -R nginx /var/moodledata $ sudo chmod -R 775 /var/moodledata
Give write permissions to the Moodle directory:
$ sudo chmod -R 755 /var/www/html/moodle
Step 7 – Configure Moodle
Now, let’s configure Moodle by copying the sample configuration file and editing it.
Switch to the Moodle directory:
$ cd /var/www/html/moodle
Copy the sample configuration file:
$ cp config-dist.php config.php
Open the configuration file for editing:
$ nano config.php
In the file, locate the database configuration section and provide the necessary details:
$CFG->dbtype = 'mysqli'; $CFG->dblibrary = 'native'; $CFG->dbhost = 'localhost'; $CFG->dbname = 'moodledb'; $CFG->dbuser = 'moodleuser'; $CFG->dbpass = 'YourPassword23!'; $CFG->prefix = 'mdl_';
Also, configure the Moodle domain name and data directory:
$CFG->wwwroot = 'https://moodle.example.com'; $CFG->dataroot = '/var/moodledata';
Save the changes and exit the editor.
Step 8 – Install SSL
To secure your Moodle site, we’ll generate an SSL certificate using Certbot and Let’s Encrypt.
Install Certbot:
$ sudo dnf install certbot
Generate the SSL certificate:
$ sudo certbot certonly --standalone --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m test@example.com -d moodle.example.com
This command will download the certificate to the /etc/letsencrypt/live/moodle.example.com
directory on your server.
Generate a Diffie-Hellman group certificate:
$ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem4096
Create a challenge web root directory for Let’s Encrypt auto-renewal:
$ sudo mkdir -p /var/lib/letsencrypt
Create a cron job to renew the SSL certificate automatically:
$ sudo nano /etc/cron.daily/certbot-renew
Paste the following code into the file:
#!/bin/sh certbot renew --cert-name moodle.example.com --webroot -w /var/lib/letsencrypt/ --post-hook "systemctl reload nginx"
Save the changes and exit the editor.
Make the task file executable:
$ sudo chmod +x /etc/cron.daily/certbot-renew
Step 9 – Configure Nginx
Let’s configure Nginx to serve Moodle.
Create and open the /etc/nginx/conf.d/moodle.conf
file:
$ sudo nano /etc/nginx/conf.d/moodle.conf
Paste the following Nginx configuration into the file:
# Redirect all non-encrypted to encrypted server { listen 80; listen [::]:80; server_name moodle.example.com; return 301 https://$host$request_uri; } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name moodle.example.com; root /var/www/html/moodle; index index.php; ssl_certificate /etc/letsencrypt/live/moodle.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/moodle.example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/moodle.example.com/chain.pem; ssl_session_timeout 1d; ssl_session_cache shared:MozSSL:10m; ssl_session_tickets off; ssl_stapling on; ssl_stapling_verify on; ssl_dhparam /etc/ssl/certs/dhparam.pem; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; access_log /var/log/nginx/moodle.access.log main; error_log /var/log/nginx/moodle.error.log; client_max_body_size 25M; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ ^(.+\.php)(.*)$ { fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_index index.php; fastcgi_pass unix:/run/php-fpm/www.sock; include /etc/nginx/mime.types; include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } # Hide all dot files but allow "Well-Known URIs" as per RFC 5785 location ~ /\.well-known { allow all; } # Don't allow direct access to various internal files. See MDL-69333 location ~ (/vendor/|/node_modules/|composer\.json|/readme|/README|readme\.txt|/upgrade\.txt|db/install\.xml|/fixtures/|/behat/|phpunit\.xml|\.lock|environment\.xml) { deny all; return 404; } }
Save the changes and exit the editor.
Open the /etc/nginx/nginx.conf
file for editing:
$ sudo nano /etc/nginx/nginx.conf
Add the following line before the include /etc/nginx/conf.d/*.conf;
line:
server_names_hash_bucket_size 64;
Save the changes and exit the editor.
Verify the Nginx configuration file syntax:
$ sudo nginx -t
If the syntax is correct, enable and start the Nginx service:
$ sudo systemctl enable nginx --now
If you encounter an error regarding permissions for /var/run/nginx.pid
, run the following commands to fix it:
$ sudo ausearch -c 'nginx' --raw | audit2allow -M my-nginx $ sudo semodule -X 300 -i my-nginx.pp
Start the Nginx service again:
$ sudo systemctl start nginx
Step 10 – Configure SELinux
To ensure SELinux compatibility with Moodle, we need to make some adjustments.
Change the file security context for the Moodle web and data directories:
$ sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/moodle' $ sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/moodledata' $ sudo restorecon -Rv '/var/www/html/moodle' $ sudo restorecon -Rv '/var/moodledata'
Allow network connections from Moodle by configuring SELinux:
$ sudo setsebool -P httpd_can_network_connect on
Step 11 – Completing Moodle Installation
With all the configurations in place, it’s time to complete the Moodle installation through the web interface.
Open your browser and navigate to https://moodle.example.com
. You’ll see a welcome screen prompting you to continue the installation process.
Click the “Continue” button to proceed. Moodle will then perform a system requirements check to ensure everything is set up correctly.
If all requirements are met, scroll down and click “Continue” to proceed with the installation of files and database setup.
Once the installation is complete, click “Continue” to create an administrator account by providing the necessary details.
After creating the administrator account, scroll down and click “Update profile” to proceed.
Next, you’ll be prompted to configure Moodle’s front page settings. Customize them according to your requirements and click “Save changes” to proceed.
Finally, you’ll be redirected to the Moodle dashboard, where you can start building and managing your online courses.
Congratulations! You have successfully installed and configured Moodle on Rocky Linux 8. You’re now ready to create engaging and interactive eLearning experiences for your learners.
If you have any questions or need further assistance, feel free to leave a comment below.
At Shape.host, we provide reliable and scalable cloud hosting solutions, including Linux SSD VPS services. Our hosting platform ensures optimal performance and security for your Moodle installation.