Moodle is an open-source digital learning solution for creating dynamic teaching and learning environments. Moodle is written in PHP, and it powers numerous learning platforms worldwide. You can download and install the Moodle software on your own web server, or let a Moodle Partner handle the hosting and implementation for you.
This tutorial focuses on how to download and install Moodle on your own Apache web server running on Red Hat Enterprise Linux 8 (RHEL 8).
- The LAMP stack installed on RHEL 8
- A user with sudo privileges
Prepare Apache for Moodle
If you would like to use Moodle with your own registered domain name, then it is recommended to create a virtual host on Apache as follows.
Open the Apache main configuration file.
$ sudo nano /etc/httpd/conf/httpd.conf
Scroll down to the bottom of the file and then append the following configuration directives.
# Virtual Hosts <VirtualHost *:80> DocumentRoot "/var/www/linuxways.net/" ServerName linuxways.net CustomLog /var/log/httpd/linuxways.net_access.log combined ErrorLog /var/log/httpd/linuxways.net_error.log </VirtualHost>
Note: Replace linuxways with your own domain name. Also, ensure that the DNS A record for your domain is pointing to the IP address of your Apache web server.
Save changes and close the httpd.conf file.
Next, run the following command to create the DocumentRoot directory where your Moodle website content will be stored.
$ sudo mkdir /var/www/linuxways.net
Prepare PHP for Moodle
Moodle requires some PHP extensions without which the installation will not complete.
$ sudo dnf install php-json php-xml php-mysqlnd php-mbstring php-zip php-gd php-intl
As of this posting, Moodle 3.10.3+ is the latest version available on the official download page.
Run the next command to extract the downloaded Moodle archive and place the contents in your website’s document root. Do remember to replace linuxways.net accordingly.
$ sudo tar -xvf moodle-latest-310.tgz -C /var/www/linuxways.net
You should now have a folder named moodle under the /var/www/yourdomain directory.
Now, you need to change the ownership of the Moodle DocumentRoot directory to the default Apache service account. For instance:.
$ sudo chown -R apache:apache /var/www/linuxways.net
Further, change the permissions on the Moodle DocumentRoot directory.
$ sudo chmod -R 755 /var/www/linuxways.net
Next, Moodle needs a data directory for storing files that are uploaded by users. This directory should not be accessible to the public.
$ sudo mkdir /var/moodledata
Change ownership of the Moodle data directory to the default Apache service account as follows.
$ sudo chown -R apache:apache /var/moodledata
Also, change the permissions on the Moodle data directory as follows.
$ sudo chmod -R 755 /var/moodledata
Prepare MariaDB for Moodle
Moodle requires a database for storing application data such as user details, site information, course details, etc.
Login to MariaDB with the command below.
$ sudo mysql -u root -p
Once logged in, you should see the MariaDB [(none)]> prompt.
Now, create a database for Moodle as follows.
MariaDB [(none)]> CREATE DATABASE moodle;
Next, create a database user. Replace moodleuser and moodlepass accordingly.
MariaDB [(none)]> CREATE USER 'moodledb'@'localhost' IDENTIFIED BY 'moodlepass';
After that, run the query below to grant all privileges on the moodle database to moodleuser.
MariaDB [(none)]> GRANT ALL PRIVILEGES ON moodle.* TO 'moodledb'@'localhost';
Update the grant tables to save your changes.
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> QUIT;
First, change into the previously extracted moodle folder. For example:
$ cd /var/www/linuxways.net/moodle
And then create the main Moodle configuration file (config.php) from the sample configuration file (config-dist.php) as follows.
$ sudo cp config-dist.php config.php
Edit the config.php Moodle configuration file.
$ sudo nano config.php
In the Moodle configuration file, locate the DATABASE SETUP section, and change the default values for dbtype, dbname, dbuser, and dbpass. The image below shows what this section should look like after making the necessary changes.
Scroll down further until you see DATA FILES. Change ‘/home/example/moodledata’ to the moodle data directory path which you created earlier. That is, ‘/var/moodledata’
Save changes and close the Moodle configuration file.
Open a web browser and go yourdomain.com/moodle/admin to complete the installation of Moodle. In my case, going to linuxways.net/moodle/admin takes me to the Moodle installation page shown in the image below.
Click Continue to proceed. On the next page, server checks might report some missing PHP extensions. As long as nothing is highlighted in red here, you are good to go. Otherwise, read the instructions next to any required extensions which are highlighted in red to resolve the issues.
As shown in the image below, nothing is highlighted in red in my case. Also, at the bottom of the page, there is a message indicating that my server meets all requirements, and I can therefore click Continue to proceed.
After you click Continue, wait for the Moodle installation to complete. You would see a series of success messages as the installation progresses. Do not leave the installation page. Once done, click Continue at the bottom of the page.
On the next page, you would be required to create your main Moodle admin account. Provide the required information and click Update Profile.
Follow the instructions on the next page to configure your site name, front page summary, etc.
After completing the installation process, users can visit yourdomain.com/moodle in a web browser to access your Moodle website.
Here is what my new Moodle website looks like.
In this tutorial, we have successfully downloaded, configured, and installed Moodle powered by the LAMP stack on RHEL 8. If you encounter any issues following this guide, do let us know.
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.