How to setup moodle on CentOS 8
Enjoying this content? Subscribe to the Channel!
Ultimate Guide: Installing Moodle 3.11 on CentOS 8 & Red Hat 8 Linux (2024 Admin Tutorial)
Welcome back to Darren’s Tech Tutorials! If you’re an administrator looking to deploy a robust learning platform, Moodle is an excellent choice. This tutorial is your comprehensive, step-by-step guide to installing Moodle 3.11 on a fresh CentOS 8 or Red Hat Enterprise Linux 8 server.
We’re going to walk through setting up all the necessary prerequisites—PHP 7.4, Apache, and MariaDB—before finally configuring the Moodle application itself. By the end of this guide, you will have a fully functional Moodle installation ready to serve your students.
Important Note for Admins: All commands executed in this tutorial are designed to be run via the Linux terminal. You do not need a GUI installed. All commands used in this video can be found here: https://darrenoneill.eu/?p=4729
Step 1: Installing the Core Prerequisites (LAMP Stack Foundation)
To run Moodle effectively, we first need to set up our core technologies: PHP, Apache (our web server), and MariaDB (our database).
1.1 Setting up PHP 7.4
Moodle 3.11 requires a modern version of PHP. We will use DNF utilities to enable version 7.4.
- Install the necessary DNF tools:
sudo dnf install dnf-utils - Reset and enable the PHP module to use version 7.4:
sudo dnf module reset php sudo dnf module enable php:7.4 - Install the core PHP package:
sudo dnf install php
1.2 Installing Apache and MariaDB
Next, we install our web server and database components.
- Install Apache (HTTPD):
sudo dnf install httpd - Install MariaDB (Client and Server):
sudo yum install mariadb sudo yum install mariadb-server - Start and Enable Services: Ensure that both the web server and the database service start automatically upon system boot.
sudo service mariadb start sudo systemctl enable mariadb sudo service httpd start sudo systemctl enable httpd
Step 2: Preparing the MariaDB Database
Moodle requires its own dedicated database and user account.
- Log into the MariaDB shell as the root user:
mysql -u root -p # (Press Enter if no password is set) - Create the database named
moodle:CREATE DATABASE moodle; - Create a dedicated user (
moodleuser) and grant all privileges on the new database. (We usemoodlepassas the example password here):GRANT ALL ON moodle.* TO 'moodleuser'@'localhost' IDENTIFIED BY 'moodlepass'; FLUSH PRIVILEGES; EXIT
Step 3: Downloading and Placing the Moodle Files
Now we grab the Moodle software and put it in the correct location for Apache to serve.
- Download Moodle 3.11: Use
wgetto pull the compressed file directly from the Moodle website (ensure you have the latest stable link for 3.11):sudo wget https://download.moodle.org/download.php/web/moodle/moodle-latest-311.tgz - Unpack the Archive: Use the
tarcommand to extract the files:sudo tar -zxvf moodle-latest-311.tgz - Move to the Web Root: Move the extracted
moodlefolder into Apache’s default serving directory (/var/www/html/on CentOS/RHEL):sudo mv moodle /var/www/html/
Step 4: Configuring Apache and Setting Permissions
We need to tell Apache where to find Moodle and ensure Moodle has the necessary write permissions for data storage.
4.1 Set the Apache Document Root
We must adjust the main Apache configuration file to point directly to the /moodle directory we just created.
- Open the Apache configuration file using a text editor like Vi or Nano:
sudo vi /etc/httpd/conf/httpd.conf - Find the
DocumentRootdirective (usually near the start of the file) and change it from/var/www/htmlto/var/www/html/moodle:DocumentRoot "/var/www/html/moodle" - Save and exit the file (In Vi: press
ESC, then type:wq!). - Restart Apache to apply the changes:
sudo service httpd restart
4.2 Create the Moodle Data Directory
Moodle needs a separate, non-web-accessible directory to store uploaded user files, backups, and cached data.
- Create the
moodle datadirectory (we’ll place it in the home directory for simplicity):sudo mkdir /home/moodle-data - Assign Ownership: Grant the Apache user (the user that runs the web server) full recursive ownership of the data directory and the main Moodle code directory:
sudo chown -R apache:apache /home/moodle-data sudo chown -R apache:apache /var/www/html/moodle - Apply SELinux Context: If SELinux is enforcing (common on RHEL/CentOS), you must set the correct context to allow Apache to write to these directories:
sudo chcon -R -t httpd_sys_rw_content_t /home/moodle-data sudo chcon -R -t httpd_sys_rw_content_t /var/www/html/moodle
Step 5: Completing the Moodle Web Installation
With the foundation set, we can now complete the Moodle setup via the web browser.
- Open your web browser and navigate to your server’s IP address or hostname (e.g.,
http://localhost). The Moodle installer should launch immediately. - Configuration Screen:
- Web Address: (Leave as default)
- Moodle Directory: (Leave as default:
/var/www/html/moodle) - Moodle Data Directory: Enter the path we created:
/home/moodle-data
- Database Connection:
- Database Driver: Select MariaDB (or MySQLi).
- Database Host:
localhost - Database Name:
moodle - Database User:
moodleuser - Database Password:
moodlepass
Troubleshooting: Installing Required PHP Extensions
It is highly likely that Moodle will flag missing PHP extensions when it attempts to verify the installation requirements. No problem! We can install them quickly via the terminal.
5.1 Fix MySQLi Error
If you receive an error about the missing mysqli extension, run the following:
sudo yum install php-mysqli
5.2 Install Remaining Essential Extensions
Once you continue, Moodle will list several other necessary extensions (like zip, gd, intl, soap, etc.). Install them all with one consolidated command:
sudo yum install php-zip php-gd php-intl php-xmlrpc php-soap
After installing the required extensions, restart Apache one final time to load the new modules:
sudo service httpd restart
Return to your browser and reload the Moodle requirements page. All checks should now turn green!
5.3 Finalizing the Setup
- Click Continue through the rest of the installation screens. Moodle will run its installation process, creating tables and populating the database.
- Once finished, you will be prompted to create your Administrator Profile. Choose a strong password and provide the required information.
- Finally, set your Site Name and Short Name (e.g., “Darren’s Test Site”).
Click Save Changes, and congratulations! You now have Moodle 3.11 running on your CentOS 8/RHEL 8 server!
Conclusion
Setting up Moodle requires careful attention to prerequisites, but following these steps ensures a smooth deployment. Whether you are using CentOS 8 or Red Hat 8, you now have a powerful, open-source learning management system ready for configuration and course development.
We plan to expand our Moodle tutorial series, diving deeper into configuration and management! If this guide helped you deploy your new LMS, please hit the like button, subscribe to Darren’s Tech Tutorials for more practical guides, and drop a comment below if you ran into any issues—I’m here to help! Happy Moodle-ing!