Difference between revisions of "RedHat Linux installation"

Jump to: navigation, search
(MariaDB / MySQL)
(MariaDB / MySQL)
Line 167: Line 167:
* Make sure at least 'mariadb' and 'mariadb-server' packages are installed.
* Make sure at least 'mariadb' and 'mariadb-server' packages are installed.
** (use "mysql", "mysql-client", "mysql-server" for MySQL)
** (use "mysql" and "mysql-server" for MySQL)
yum install mariadb mariadb-server
yum install mariadb mariadb-server

Revision as of 04:21, 16 July 2019

Note: This document is about installing Moodle 3.6 in an RedHat Enterprise Linux (RHEL) 7 with PHP 7

Server Installation

  • Web Server
    • DON'T install PHP here, since RHEL comes with PHP5 and we need PHP7 in Moodle 3.6, we will install it later.
    • Also the default version of Apache 'httpd' won't work with the PHP7 install later, we will install 'httpd24' to replace it, but there is no harm to install it first.
  • Database
    • Install MariaDB (MySQL is replaced by MariaDB since RHEL 7.3).
  • Also BEWARE OF the 'Server with a GUI' option, it may not work as expected.

Note: Set up the firewall if necessary. You probably only need to enable HTTP (and perhaps FTP and SSH) access to your server machine, unless you know different.

System Registration

  • To receive updates, create a user account at redhat.com, and then login and register as developer at https://developers.redhat.com/
  • Subscribe the system by:
subscription-manager register --auto-attach
  • Update the system and then reboot
yum update

See [1]

Configure hostname and domain name

Type system-config-network to open the GUI editor. Click on the DNS tab. In the "DNS Search Path" fill in your domain name for example myuniversity.edu. Now ensure the "Hostname" contains the computer name you will use and click activate to make changes


Default RedHat Enterprise Linux comes with SELinux set to enforcing. But this may cause problem accessing the Moodle server. If you are not used to SELinux and setting permissions it's (maybe less secure but) often easier to lower the SELinux level to permissive.

# vi /etc/sysconfig/selinux


See the CentOS [2]

Adding extra repo

To install the httpd24 and PHP7 we need, add extra repo:

subscription-manager repos --enable rhel-server-rhscl-7-rpms


  • The default version (httpd) doesn't work with the PHP7 we need, so install httpd24 to replace it:
yum install httpd24-httpd
or everything
yum install httpd24-*
  • Stop the existing version, prevent it from starting after reboot:
service httpd stop; chkconfig httpd off
  • Start the new version, and make it auto-start after reboot:
service httpd24-httpd start; chkconfig httpd24-httpd on
  • Edit the Apache configuration file
    (For the default version, it's
  • Right at the end of the file add the following lines: (once again 'mymoodle' as from Step 3)
    • <Directory "/usr/moodle/mymoodle">
    • DirectoryIndex index.php
    • AcceptPathInfo on
    • AllowOverride None
    • Options None
    • Order allow,deny
    • Allow from all
    • </Directory>
    • Alias /mymoodle "/usr/moodle/mymoodle"
  • Don't insert a space in "allow,deny" (common mistake!)
  • You might also want to run through the rest of the config file and make some other (obvious) changes - administrator email and suchlike. Not vital though.
  • Run the Services application (same as for Mysql) - tick and start "httpd", then save changes and exit.


Test access to the web server, if not ok, probably it is blocked by the firewall. Stop it by:

service firewalld stop

And then disable it, preventing it to start again after a reboot:

systemctl disable firewalld 


  • By using the extra repo, install the version of PHP you need (7.0 in this case). See [3]
yum install rh-php70 rh-php70-php
  • Check the installed PHP version:
    • As the PHP7 was installed to a non-default location, update the PATH variable by editing /etc/bashrc and then run the source command (See [4]:
# vi /etc/bashrc
  export PATH=$PATH:/opt/rh/rh-php70/root/bin:/opt/rh/rh-php70/root/sbin
# source /etc/bashrc
# php -v

RedHat EL - or 'the upstream vendor' if you are using a clone - will not introduce newer PHP packages unless there is an exception (php53 in EL5.6+). Moodle has quite a some PHP dependencies which cannot be fullfilled solely by installing all RHEL-provided packages.

You have therefore to make a choice:

  • Use RH and pay attention your Moodle version supports it + PHP modules from and maintain them on your own
  • Install the whole (latest) PHP from source on your own (and maintain it)
  • Install PHP packages from a third party repo (but you won't get support from Redhat if you run into problems):
    • [rpms.famillecollet.com] Maintains recent MySQL and PHP packages for supported EL version (a EPEL contributor)
    • RPMFusion and others also have newer PHP packages


(I will install under /usr/moodle, data in /usr/moodle_data)


  • Download your favourite version of Moodle from moodle.org (.zip archive is easiest)
  • as Root create folder under /usr and copy zip
    • su
    • mkdir /usr/moodle
    • mkdir /usr/moodle_data
    • cp moodle_111.zip /usr/moodle
  • If you prefer you can install the GIT version directly for all the latest features. Instead of downloading and copying the zip file. See Git_for_Administrators for details.
  • Or if you prefer you can install the CVS version directly for all the latest features. Instead of downloading and copying the zip file.
    • cd /usr/moodle
    • cvs -d:pserver:anonymous@uk.cvs.moodle.org:/cvsroot/moodle login
    • cvs -z3 -d:pserver:anonymous@uk.cvs.moodle.org:/cvsroot/moodle co moodle

Unpack and set file permission etc

  • Still as root we unpack moodle and rename to something appropiate (I have multiple moodle installs, hence this setup). I will call this install mymoodle.
    • cd /usr/moodle
    • unzip moodle_xxx.zip
    • mv moodle mymoodle
      • (optional step - I have more than one install under /usr/moodle)
    • mkdir /usr/moodle_data/mymoodle
      • (same name as the moodle install above)
    • chown -R apache:apache /usr/moodle
      • (! Giving Apache full rights to your Moodle programs is not secure. Check out the forums for recomendations on how to secure a production environment.)
    • chown -R apache:apache /usr/moodle_data

Setup config.php

  • Still as root copy and edit the config file, you should know the host/domain name for your server
    • cd /usr/moodle/mymoodle
    • cp config-dist.php config.php
    • vi config.php (or whatever your favourite editor is!)
  • Your config.php settings should be something like...
    • dbtype = "mariadb" (use "mysqli" for MySQL; MySQL is replaced by MariaDB since RHEL 7.3)
    • dbhost = "localhost"
    • dbname = "mymoodle"
    • dbuser = "moodleuser"
    • dbpass = "moodlepass" (<-- better make this something of your own)
    • prefix = ""
      • (keep the default 'mdl_' prefix if you plan on sharing the database with other applications)
    • wwwroot = "http://myhost.mydomain/mymoodle"
      • (If you only want to try moodle out and will not be accessing it from other machines you can use "http://localhost/mymoodle")
    • dirroot = '/usr/moodle/mymoodle'
    • dataroot = '/usr/moodle_data/mymoodle'
  • Save your changes and exit from the editor

MariaDB / MySQL

  • Make sure at least 'mariadb' and 'mariadb-server' packages are installed.
    • (use "mysql" and "mysql-server" for MySQL)
yum install mariadb mariadb-server
  • Then get the daemon running, it is not running by default. And set it to auto-start. See also [5]
    • (use "mysqld" for MySQL)
service mariadb start; chkconfig mariadb on
  • Edit /etc/my.cnf (May be different for MySQL)
vi /etc/my.cnf

Scroll down to the [mysqld] section and under Basic Settings add the following line under the last statement.

innodb_file_format = Barracuda

innodb_file_per_table = 1

  • If you haven't yet, as root, change the MySQL root password
    • mysqladmin -u root password mysqlpass (<-- should change this to something of your own)
    • Or run 'mysql_secure_installation'
  • Next, set up the MySQL database (see http://moodle.org/doc/?file=install.html#Database for more details)
  • Launch MySQL as root
    • mysql -u root -p
      • (at the password prompt, enter the password from above)
  • At the '>' MySQL prompt, enter the following commands (MySQL commands are ended with a ';')
    • CREATE DATABASE mymoodle CHARSET 'utf8mb4';
      • (the name 'mymoodle' is the same name as the database from Step 4)
      • (as above, 'mymoodle', 'moodleuser' and 'moodlepass' are from Step 4)
    • flush privileges;
    • quit
  • (! Consider MySQL security - not covered here. If you run a firewall, you don't have too much to worry about.)

Set up the cron job

As root user edit the /etc/crontab file using vi (or another editor) OR you can add a line to the root user's "personal" crontab (don't do both!).

  • If you wish to place an entry in your root user's crontab use:


  • If you wish to add an entry in /etc/crontab:
  • Open the /etc/crontab file in an editor (vi).
  • Add the following line:


  • In either case, don't forget to save the file and exit (in vi that is <Esc>, then ':wq')

Try your new installation


or, if you are running the browser on the same machine