Install Moodle in RHEL7 with PHP7 and HTTP24

Girish V P
Tensult Blogs
Published in
5 min readJul 3, 2018

This Blog has moved from Medium to blogs.tensult.com. All the latest content will be available there. Subscribe to our newsletter to stay updated.

Moodle is a well-known learning management system(LMS). The data is organized as courses which a teacher can deliver to the students. Admin is the only account created at the time of moodle installation. This admin can create the users in the form of managers, teachers, students to have different levels of permission over the courses and other moodle contents.

The Environment

AMI: RHEL-7.5_HVM_GA-20180322-x86_64..(ami-5b673c34)
Cloud Platform: Amazon
Operating System: RHEL-7.5
Kernel: 3.10.0-862.el7.x86_64
Architecture: x86–64
PHP RPMS : rh-php70-*
MySQL RPMS:mysql-community-server-5.7.22-1.el7.x86_64
moodle TAR: moodle-latest-34.tgz

We will see how to implement moodle in RHEL 7 for AWS environment which involves the following steps:

  • Prepare the Operating System
  • Install and configure PHP7
  • MySQL setup
  • Configure HTTP24
  • Configure Moodle
  • Complete moodle setup with Web browser

Prepare Operating System

1) Launch RHEL7 instance and disable Selinux. Edit the file /etc/sysconfig/SELinux like below and reboot. If you enable SELinux you have to do some additional configuration.

# yum update 
# vi /etc/sysconfig/selinux
SELINUX=disabled
# init 6

Install and configure PHP7

  1. Edit the file /etc/yum.repos.d/RedHat-rhui.repo. Replace all enabled=0 with enabled=1

2) Install all PHP 7.0 related packages (If you had installed older versions of PHP remove those packages). You can select the packages based on the features you require. I have installed all the related packages.

# yum install rh-php70-*

3) Verify that files installed are under /opt/RH/RH-php70 directory.

4) The PATH environment variable has to be updated. Edit /etc/bashrc and add the following line at the end of the file. Execute source command.

# vi /etc/bashrc
export PATH=$PATH:/opt/rh/rh-php70/root/bin:/opt/rh/rh-php70/root/sbin
# source /etc/bashrc

5) Execute PHP -v to find out the version of the newly installed PHP.

# php -v

MySQL Setup

1) Visit the Oracle website and download the required version of MySQL package. You can download the latest yum repository file from the site (mysql80-community-release-el7–1.noarch.rpm at the time of writing)

2) Install above mysql80-community-release file.

# rpm -ivh mysql80-community-release-el7–1.noarch.rpm

3) Edit /etc/yum.repos.d/MySQL-community.repo. Enable mysql57-community repo and disable mysql80-community repo. We will install MySQL-5.7.

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

4) Install MySQL server and start MySQL service.

# yum install mysql-server
# service mysqld start

5) Search for a temporary password in /var/log/mysqld.log. Login with a temporary password and change the root password.

# mysql -u root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'abcdeF@123' ;

6) Create a database moodle and a user moodle user who has full access to the database. Moodle application reads/writes data to MySQL with this user’s privileges.

mysql> CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY ‘abcdeF@123’;
mysql > CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
mysql > grant all on moodle.* to 'moodleuser'@'localhost';
mysql > flush privileges;
mysql > quit

Install and Configure HTTP24

  1. The normal Http package comes with default RPM repository doesn’t have the capability of communicating with PHP 7.0. To disable/remove the same Http and install the following packages.
# yum install httpd24-*
# scl enable httpd24 bash
# systemctl start httpd24-httpd
# systemctl enable httpd24-httpd

2) Edit /opt/RH/httpd24/root/etc/httpd/conf/httpd.conf and uncomment/replace the following parameters.

ServerName moodle.tensult.com:80
DocumentRoot “/opt/rh/httpd24/root/var/www/html/moodle”

3) Assume that it is moodle.tensult.com is the website name. If you have not registered your domain edit /etc/hosts file of your local machine where you access the moodle website to emulate a test environment. Replace with your moodle server’s public IP and moodle website name /etc/hosts file looks like below.

x.x.x.x  moodle.tensult.com

Configure Moodle

1) Download latest package from https://download.moodle.org/releases/latest/

2) I used moodle-latest-34.tgz. untar the package.

# tar xzvf moodle-latest-34.tgz

3) Move the extracted moodle directory to httpd document root and assign required permissions.

# mv moodle /opt/rh/httpd24/root/var/www/html
# cd /opt/rh/httpd24/root/var/www/html
# chown root moodle -R
# chmod 755 moodle -R

4) Create a moodle data directory and give full permission. If you feel there is a security loophole in this step, refer moodle official documentation for more information.

# mkdir -m 777  /opt/rh/httpd24/root/var/www/moodledata

5) Now you restart the httpd service.

# systemctl restart httpd24-httpd

Continue to Web browser based moodle setup

The access you're moodling site from your web browser. Web console set up is self-explanatory. Navigate through the slide and enter the information appropriate to your organization. During the process create a file /opt/rh/httpd24/root/var/www/html/moodle/config.php when it is prompted to copy the contents to it from we console.

Conclusion

Installation of moodle is an easy process that involves LAMP( Linux, Apache, MySQL, PHP) configuration. The latest version of moodle can be installed only over PHP7 and later. We have configured httpd24 for the new version of PHP to have supported.

--

--