How to install Moodle on CenotOS 7
Moodle is a popular open-source learning management system (LMS) written in PHP. It was built to help educators easily create quality online courses. In this article, we will show you how to install Moodle on a CentOS 7.
In order to run Moodle on your CentOS 7 server, you need the following requirements pre-installed:
- Web Server: Apache >= 2.0 compiled with mod_rewrite module, or Nginx
- PHP >= PHP 7.0 or above is recommended, with the following PHP extensions enabled: intl, Zip, XMLRPC, Soap and opcache
- MySQL 5.5.31 or later, MariaDB 5.5.31 or later or PostgreSQL 9.3 or later installed on your CentOS server
- CentOS 7 system with root access enabled.
1. Login via SSH
Log in to your CentOS 7 system via ssh as user root
ssh roo@IP_Address -p Port_number
2. Update all packages
Once you are logged in to the server run the following command to make sure that all installed packages are up to date
yum clean all yum update
3. Install LAMP stack
As mention in the requirements section of the tutorial, a LAMP stack (Apache, MySQL/MariaDB, and PHP) is required to run Moodle on the server. We will start with installing Apache web server
yum -y install httpd
Start the Apache web server and enable it to start upon server boot
systemctl enable httpd
PHP version 7.1 is not available in the default CentOS 7 repositories so we will use the Remi repository.
To install and enable both EPEL and Remi repositories run the following commands:
yum install epel-release rpm -Uhv https://rpms.remirepo.net/enterprise/remi-release-7.rpm yum-config-manager --enable remi-php71
Install PHP 7.1 and all necessary PHP modules using the following command:
yum install php php-common php-intl php-zip php-soap php-xmlrpc php-opcache php-mbstring php-gd php-curl php-mysql php-xml
During the installation, the yum package manager will prompt you to install the Remi GPG Signing key. Accept the key by typing ‘y’ and the package manager will install all necessary PHP extensions.
In order to complete the LAMP installation, install the MariaDB database server using the following command:
yum -y install mariadb mariadb-server
Start the MariaDB service and set it to start on reboot
systemctl start mariadb systemctl enable mariadb
Run the ‘mysql_secure_installation’ post-installation script provided by MariaDB to strengthen the security of the database server and set a root password. You can use the following options:
Set root password? [Y/n] Y Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y
4. Install Moodle on CentOS 7
Moodle is not available in the official CentOS 7 repositories, so we will have to download the latest stable version from the official website page at https://download.moodle.org/releases/latest/ and extract the Moodle archive to a directory on the server by executing the following commands:
cd /opt wget https://download.moodle.org/download.php/direct/stable35/moodle-latest-35.tgz -O moodle-latest.tgz tar -xvzf moodle-latest.tgz mv /opt/moodle/ /var/www/html/moodle/
This will create a new directory named ‘moodle’ containing the necessary files and directories.
Change the ownership of the /var/www/html/ directory:
chown -R apache:apache /var/www/html/
5. Configure Apache to serve Moodle
Create a new Apache configuration file and add the following contents below to the /etc/httpd/conf.d/moodle.conf file using vi or your favorite text editor:
# vi /etc/httpd/conf.d/moodle.conf
Add the following lines:
Alias /moodle “/var/www/html/moodle/”
CustomLog /var/log/httpd/moodle-access_log common
Save the changes and restart the Apache web server for the changes to take effect:
systemctl restart httpd
6. Create a MariaDB database for Moodle
Log into MariaDB with the root account:
# mysql -u root -p
Now we will create a MariaDB database for Moodle using the following query:
mysql> CREATE DATABASE moodledb;
Add a separate user for Moodle that will interact with the database:
mysql> GRANT ALL PRIVILEGES ON moodledb.* to 'moodle'@'localhost' IDENTIFIED BY '5tr0ng_Pa55w0rd';
Execute the following command to apply the privileges we set:
mysql> FLUSH PRIVILEGES;
Now we can exit the MariaDB session:
Edit the MariaDB configuration file (/etc/my.cnf.d/server.cnf) and add the following lines:
[client] default-character-set = utf8mb4 [mysqld] innodb_file_format = Barracuda innodb_file_per_table = 1 innodb_large_prefix character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci skip-character-set-client-handshake [mysql] default-character-set = utf8mb4
Restart MariaDB service for the changes to take effect
service mariadb restart
You can now open a web browser and access the Moodle application at http://your-domain.com
From here you can finish the setup by following the steps below:
- Choose a language for the Moodle installation.
- Confirm the website address, Moodle directory, and data directory.
- Choose a database driver (improved MySQL or MariaDB).
- Enter the database settings: localhost or 127.0.0.1 as database host, then enter a database name, username, password, database port (3306), and once you have filled in the form, click Next.
- Edit the /var/www/html/moodle/config.php configuration file and replace ‘mysqli’ with ‘mariadb’.
- Moodle will check to make sure that your server meets the Moodle requirements. If everything is OK, click Next.
- Enter a username, password and email address for the administrator user account.
- Complete registration with Moodle.net.moodle
That’s it, now you should have successfully installed Moodle on your CentOS 7 server.