RedHat Linux installation: Difference between revisions

From MoodleDocs
(→‎SELinux: Added details prompted by https://moodle.org/mod/forum/discuss.php?d=446229)
 
(31 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Note|This document is about installing Moodle 3.7 in an RedHat Enterprise Linux (RHEL) 8}}
{{Update}}


== Server Installation ==
== Server Installation ==
* Web Server
* Web Server
** Moodle 3.7 needs PHP 7.1 and RHEL8 comes with PHP 7.2.[https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/8.0_release_notes/index#web-servers-databases-dynamic-languages]
** Moodle 3.7 needs PHP 7.1; RHEL8 comes with PHP 7.2.[https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/8.0_release_notes/index#web-servers-databases-dynamic-languages]
* Database
* Database
** Moodle 3.7 needs MariaDB 5.5 or MySQL 5.6, and RHEL8 comes with MariaDB 10.3 and MySQL 8.0 (They cannot be installed at the same time).[https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/8.0_release_notes/index#web-servers-databases-dynamic-languages]
** Moodle 3.7 needs MariaDB 5.5 or MySQL 5.6; RHEL8 comes with MariaDB 10.3 and MySQL 8.0 (They cannot be installed at the same time).[https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/deploying_different_types_of_servers/index#using-mariadb]
* BEWARE OF the 'Server with a GUI' option, it may not work as expected.
* BEWARE OF the 'Server with a GUI' option, it may not work as expected.


Line 12: Line 12:
== Network Interface ==
== Network Interface ==


During installation, under "System" -> "Network & Host Management", remember to enable the NIC. It's not enabled by default.
During installation, under "System" -> "Network & Host Name", remember to enable the NIC. It's not enabled by default.


== Configure hostname and domain name==
== Configure hostname and domain name==
Line 24: Line 24:
subscription-manager register --auto-attach
subscription-manager register --auto-attach
</pre>
</pre>
Enter the username, password as requested.
Enter the username and password as requested.
* Update the system and then reboot
* Update the system and then reboot
<pre>
<pre>
Line 33: Line 33:


== SELinux ==
== SELinux ==
Default RedHat Enterprise Linux comes with SELinux set to 'enforcing'. But this may cause user problem accessing web content placed at directory other than the default directory (/var/www/html) or other access problem. 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' or even 'disabled'.
By default Red Hat Enterprise Linux comes with SELinux set to 'enforcing'. This may cause user problem accessing web content placed at directory other than the default directory (/var/www/html) or other access problem.
 
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' or even 'disabled'.


<pre>
<pre>
Line 42: Line 44:


See the CentOS [https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-Working_with_SELinux-Changing_SELinux_Modes.html]
See the CentOS [https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-Working_with_SELinux-Changing_SELinux_Modes.html]
=== Moodledata ===
To allow writing to the Moodledata directory run the following commands after creating the directory (assuming your Moodledata directory is in '''/var/www/moodle.example.com/moodledata'''):
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/moodle.example.com/moodledata"
# restorecon -v "/var/www/moodle.example.com/moodledata"
If the Moodledata directory already exists and is not empty instead run:
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/moodle.example.com/moodledata(/.*)?"
# restorecon -R -v "/var/www/moodle.example.com/moodledata"
=== Access to network services ===
If your Moodle site needs access to remote network services then you must allow this access with:
# setsebool -P httpd_can_network_connect 1
This is required if your Moodle database is remote, or if you are using a network service such as LDAP (auth_ldap or enrol_ldap), or some external database (auth_db or enrol_database). This is not required if your Moodle database is a local MySQL/MariaDB database, but is required if your Moodle database is a local PostgreSQL database.
=== Access to execute commands ===
To run commands such as those specified under [[System_paths|System paths]]:
# setsebool -P httpd_execmem on


== Firewall ==
== Firewall ==
The internal firewall (RHEL 7 uses 'firewalld' instead of 'iptables' by default) is on by default. It will block the access to the web server. You may stop it first to test connection:
The internal firewall (RHEL since version 7 uses 'firewalld'[https://firewalld.org/]) is on by default. It will block the access to the web server. You may stop it first to test connection:


<pre>
<pre>
Line 67: Line 95:
firewall-cmd --zone=public --list-services
firewall-cmd --zone=public --list-services
</pre>
</pre>
To disable certain types of ICMP traffic [http://www.freekb.net/Article?id=2639], e.g. timestamp request and reply:
<pre>
firewall-cmd --add-icmp-block=timestamp-request --permanent
firewall-cmd --add-icmp-block=timestamp-reply --permanent
</pre>
Restart the firewall and then check the block status:
<pre>
firewall-cmd --reload
firewall-cmd --query-icmp-block=timestamp-request
firewall-cmd --query-icmp-block=timestamp-reply
</pre>


To use iptables instead of firewalld, see [https://access.redhat.com/solutions/1264743]
To use iptables instead of firewalld, see [https://access.redhat.com/solutions/1264743]
Line 73: Line 115:


* Make sure at least 'mariadb' and 'mariadb-server' packages are installed.
* Make sure at least 'mariadb' and 'mariadb-server' packages are installed.
** (use "mysql" and "mysql-server" for MySQL)
<pre>
<pre>
yum install mariadb mariadb-server
yum install mariadb mariadb-server
</pre>
</pre>
*Then get the daemon running, it is not running by default. And set it to auto-start. See also [https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/selinux_users_and_administrators_guide/chap-managing_confined_services-mariadb]
*Then get the daemon running, it is not running by default. And set it to auto-start. See also [https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/selinux_users_and_administrators_guide/chap-managing_confined_services-mariadb]
** (use "mysqld" for MySQL)
<pre>
<pre>
service mariadb start; chkconfig mariadb on
service mariadb start; chkconfig mariadb on
</pre>
</pre>
*Edit /etc/my.cnf
*Edit /etc/my.cnf (May be different for MySQL) (MariaDB 10.3 doesn't need this as these are already the default settings.)


<pre>vi /etc/my.cnf</pre>
<pre>vi /etc/my.cnf</pre>


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


<pre>innodb_file_format = Barracuda</pre><br />
<pre>innodb_file_format = Barracuda</pre><br />
Line 90: Line 134:
<pre>innodb_large_prefix</pre>
<pre>innodb_large_prefix</pre>


* If you haven't yet, as root, change the MariaDB(MySQL) root password
* If you haven't yet, as root, change the MariaDB/MySQL root password, also secure the installation
** mysqladmin -u root password mysqlpass (<-- should change this to something of your own)
** mysql_secure_installation
** Or run 'mysql_secure_installation' to set password for root and secure the system
* Next, set up the MariaDB/MySQL database (see http://moodle.org/doc/?file=install.html#Database for more details)
* Next, set up the MySQL database (see http://moodle.org/doc/?file=install.html#Database for more details)
* Launch MariaDB/MySQL as root
* Launch MySQL as root
** mysql -u root -p
** mysql -u root -p
*** (at the password prompt, enter the password from above)
*** (at the password prompt, enter the password from above)
* At the '>' MySQL prompt, enter the following commands (MySQL commands are ended with a ';')
* At the '>' MariaDB/MySQL prompt, enter the following commands (MariaDB/MySQL commands are ended with a ';')
** CREATE DATABASE mymoodle CHARSET 'utf8mb4';
** CREATE DATABASE mymoodle CHARSET 'utf8mb4';
*** ('mymoodle' is the name of the database you would like to use, it will be entered to the Moodle 'config.php' later)
*** ('mymoodle' is the name of the database you would like to use, it will be entered to the Moodle 'config.php' later)
Line 104: Line 147:
** flush privileges;
** flush privileges;
** quit
** quit
* (! Consider MariaDB(MySQL) security - not covered here. If you run a firewall, you don't have too much to worry about.)
* (! Consider MariaDB/MySQL security - not covered here. If you run a firewall, you don't have too much to worry about.)


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


Line 116: Line 159:
** mkdir /usr/moodle_data
** mkdir /usr/moodle_data
** cp moodle_111.zip /usr/moodle
** 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 [https://docs.moodle.org/402/en/Git_for_Administrators Git_for_Administrators] for details.
* If you prefer you can install the GIT version directly for all the latest features. Instead of downloading and copying the zip file. See [https://docs.moodle.org/400/en/Git_for_Administrators Git_for_Administrators] for details.
** cd /usr
** cd /usr
** git clone git://git.moodle.org/moodle.git
** git clone git://git.moodle.org/moodle.git
Line 126: Line 169:
=== Unpack and set file permission etc ===
=== 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.
* Still as root we unpack moodle and rename to something appropriate (I have multiple moodle installs, hence this setup). I will call this install mymoodle.
** cd /usr/moodle
** cd /usr/moodle
** unzip moodle_xxx.zip
** unzip moodle_xxx.zip
Line 134: Line 177:
*** (same name as the moodle install above)
*** (same name as the moodle install above)
** chown -R apache:apache /usr/moodle
** 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.)
*** (! Giving Apache full rights to your Moodle programs is not secure. Check out the forums for recommendations on how to secure a production environment.)
** chown -R apache:apache /usr/moodle_data
** chown -R apache:apache /usr/moodle_data


Line 144: Line 187:
** vi config.php (or whatever your favourite editor is!)
** vi config.php (or whatever your favourite editor is!)
* Your config.php settings should be something like...
* Your config.php settings should be something like...
** dbtype = "mariadb" (use "mysqli" for MySQL)
** dbtype = 'mariadb' (use 'mysqli' for MySQL)
** dbhost = "localhost"
** dbhost = 'localhost'
** dbname = "mymoodle"
** dbname = 'mymoodle'
** dbuser = "moodleuser"
** dbuser = 'moodleuser'
** dbpass = "moodlepass" (<-- better make this something of your own)
** dbpass = 'moodlepass' (<-- better make this something of your own)
** prefix = ""
** prefix = 'mdl_'
*** (keep the default 'mdl_' prefix if you plan on sharing the database with other applications)
*** (Use different prefix if there is more than one instance of Moodle on the same server, and you plan to share the database)
** wwwroot = "http://myhost.mydomain/mymoodle"
** wwwroot = 'http://myhost.mydomain'
*** (If you only want to try moodle out and will not be accessing it from other machines you can use "http://localhost/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'
** dataroot = '/usr/moodle_data/mymoodle'
* Save your changes and exit from the editor
* Save your changes and exit from the editor


== Apache ==
== Apache ==
* Open a web browser and make sure you can connect to the installed web server and default port (80) of the server. If not OK, it may be blocked by the firewall (see below). Correct the problem.
* Install it if it's not installed already.
<pre>
<pre>
yum install httpd
yum install httpd
</pre>
</pre>
or everything<pre>
or everything<pre>
yum install httpd-*
yum install httpd*
</pre>
</pre>
* Start it and make it auto-start after reboot:
* Start it and make it auto-start after reboot:
Line 169: Line 211:
service httpd start; chkconfig httpd on
service httpd start; chkconfig httpd on
</pre>
</pre>
* Open a web browser and make sure you can connect to the installed web server and default port (80) of the server. If not OK, it may be blocked by the firewall (see above). Correct the problem before continuing.
* Edit the Apache configuration file <pre>/etc/httpd/conf/httpd.conf</pre>
* Edit the Apache configuration file <pre>/etc/httpd/conf/httpd.conf</pre>
* Right at the end of the file add the following lines:
* Right at the end of the file add the following lines:
Line 183: Line 226:
* 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.
* 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.
* Run the Services application (same as for Mysql) - tick and start "httpd", then save changes and exit.
=== Setting Document Root ===
Edit <pre>/etc/httpd/conf/httpd.conf</pre>
Change From: DocumentRoot /var/www/html
Change To: DocumentRoot /var/www/html/mymoodle
If you want the web site to be served as "http://www.whatever.com/mymoodle" instead of "http://www.whatever.com", don't change it, and modify the 'wwwroot' parameter of Moodle 'config.php' file accordingly.


== PHP ==
== PHP ==
* Install the version of PHP you need (7.2 in this case).
* Install PHP:
<pre>
<pre>
yum install php72 php72-php php72-php-xml php72-php-xmlrpc php72-php-mysqlnd php72-php-zip php72-php-gd php72-php-intl php72-php-mbstring php72-php-soap php72-php-opcache
yum install php php-cli php-common php-fpm php-gd php-intl php-json php-mbstring php-mysqlnd php-opcache php-pdo php-xml php-xmlrpc php-pecl-zip php-soap
</pre>
</pre>


*Check the installed PHP version:
*Check the installed PHP version:
You may need to create a link to the php executable:
<pre>
<pre>
# ln -s /opt/rh/rh-php70/root/bin/php /bin/php
# php -v
# php -v
</pre>
* Restart the web server so that PHP can start working:
<pre>
service httpd restart
</pre>
</pre>


Line 203: Line 258:
?>
?>
</pre>
</pre>
And then open web browser and browse to "http://webserver/phpinfo.php" to make sure PHP is working with the web server. Then remove the file.
And then open web browser and browse to "http://webserver/phpinfo.php" to make sure PHP is working with the web server. Then remove the file for security reason.


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.
<!--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:
You have therefore to make a choice:
Line 212: Line 267:
* Install PHP packages from a third party repo (but you won't get support from Redhat if you run into problems):
* 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)
** [rpms.famillecollet.com] Maintains recent MySQL and PHP packages for supported EL version (a EPEL contributor)
** RPMFusion and others also have newer PHP packages
** RPMFusion and others also have newer PHP packages-->


== Set up the cron job ==
== Install Moodle ==
Now everything's ready. Use web browser to open "http://webserver/mymoodle/install.php" to start the installation.
 
== Set up 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!).
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!).
Line 244: Line 302:
== Try your new installation ==
== Try your new installation ==


http://myhost.mydomain/admin
or
http://myhost.mydomain/mymoodle/admin
http://myhost.mydomain/mymoodle/admin


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


http://localhost/admin
or
http://localhost/mymoodle/admin
http://localhost/mymoodle/admin
== Installing SSL certificate ==
After installing the SSL certificate, change the 'http' to 'https' in the 'wwwroot' parameter of Moodle 'config.php' file.


[[Category:Administrator]]
[[Category:Administrator]]
[[Category:Installation]]
[[Category:Installation]]
[[pl:Instalacja_w_RedHat]]
[[pl:Instalacja w RedHat]]
 
== Setting Apache Document Root ==
If you want the web site to be served as http://www.whatever.com/ instead of http://www.whatever.com/mymoodle, edit <pre>/etc/httpd/conf/httpd.conf</pre>
 
Change From: DocumentRoot /var/www/html
 
Change To: DocumentRoot /var/www/html/mymoodle
 
Remember to modify the Moodle 'config.php' file and cron job accordingly.


==See also==
==See also==
*[[Unix or Linux Installation]]
*[[Unix or Linux Installation]]
*[[Installing Moodle]]
*[[Installing Moodle]]

Latest revision as of 16:32, 28 April 2023

This page requires updating. Please do so and remove this template when finished.


Server Installation

  • Web Server
    • Moodle 3.7 needs PHP 7.1; RHEL8 comes with PHP 7.2.[1]
  • Database
    • Moodle 3.7 needs MariaDB 5.5 or MySQL 5.6; RHEL8 comes with MariaDB 10.3 and MySQL 8.0 (They cannot be installed at the same time).[2]
  • 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/HTTPS (and perhaps FTP and SSH) access to your server machine, unless you know the difference.

Network Interface

During installation, under "System" -> "Network & Host Name", remember to enable the NIC. It's not enabled by default.

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

System Registration

  • To receive package 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

Enter the username and password as requested.

  • Update the system and then reboot
yum update
reboot

See [3]

SELinux

By default Red Hat Enterprise Linux comes with SELinux set to 'enforcing'. This may cause user problem accessing web content placed at directory other than the default directory (/var/www/html) or other access problem.

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' or even 'disabled'.

# vi /etc/sysconfig/selinux

SELINUX=disabled

See the CentOS [4]

Moodledata

To allow writing to the Moodledata directory run the following commands after creating the directory (assuming your Moodledata directory is in /var/www/moodle.example.com/moodledata):

# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/moodle.example.com/moodledata"
# restorecon -v "/var/www/moodle.example.com/moodledata"

If the Moodledata directory already exists and is not empty instead run:

# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/moodle.example.com/moodledata(/.*)?"
# restorecon -R -v "/var/www/moodle.example.com/moodledata"

Access to network services

If your Moodle site needs access to remote network services then you must allow this access with:

# setsebool -P httpd_can_network_connect 1

This is required if your Moodle database is remote, or if you are using a network service such as LDAP (auth_ldap or enrol_ldap), or some external database (auth_db or enrol_database). This is not required if your Moodle database is a local MySQL/MariaDB database, but is required if your Moodle database is a local PostgreSQL database.

Access to execute commands

To run commands such as those specified under System paths:

# setsebool -P httpd_execmem on

Firewall

The internal firewall (RHEL since version 7 uses 'firewalld'[5]) is on by default. It will block the access to the web server. You may stop it first to test connection:

service firewalld stop

and then either disable it:

chkconfig firewalld off

or enable permanent HTTP access to it, you may want to enable HTTPS as well:

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https

Restart the firewall and then check the allow status:

service firewalld restart
firewall-cmd --zone=public --list-services

To disable certain types of ICMP traffic [6], e.g. timestamp request and reply:

firewall-cmd --add-icmp-block=timestamp-request --permanent
firewall-cmd --add-icmp-block=timestamp-reply --permanent

Restart the firewall and then check the block status:

firewall-cmd --reload
firewall-cmd --query-icmp-block=timestamp-request
firewall-cmd --query-icmp-block=timestamp-reply


To use iptables instead of firewalld, see [7]

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 [8]
    • (use "mysqld" for MySQL)
service mariadb start; chkconfig mariadb on
  • Edit /etc/my.cnf (May be different for MySQL) (MariaDB 10.3 doesn't need this as these are already the default settings.)
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


innodb_large_prefix
  • If you haven't yet, as root, change the MariaDB/MySQL root password, also secure the installation
    • mysql_secure_installation
  • Next, set up the MariaDB/MySQL database (see http://moodle.org/doc/?file=install.html#Database for more details)
  • Launch MariaDB/MySQL as root
    • mysql -u root -p
      • (at the password prompt, enter the password from above)
  • At the '>' MariaDB/MySQL prompt, enter the following commands (MariaDB/MySQL commands are ended with a ';')
    • CREATE DATABASE mymoodle CHARSET 'utf8mb4';
      • ('mymoodle' is the name of the database you would like to use, it will be entered to the Moodle 'config.php' later)
    • GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON mymoodle.* TO moodleuser@localhost IDENTIFIED BY 'moodlepass';
      • (as above, 'mymoodle', 'moodleuser' and 'moodlepass' will be entered to the Moodle 'config.php' later)
    • flush privileges;
    • quit
  • (! Consider MariaDB/MySQL security - not covered here. If you run a firewall, you don't have too much to worry about.)

Setup Moodle

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

Download

  • 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 appropriate (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 recommendations 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)
    • dbhost = 'localhost'
    • dbname = 'mymoodle'
    • dbuser = 'moodleuser'
    • dbpass = 'moodlepass' (<-- better make this something of your own)
    • prefix = 'mdl_'
      • (Use different prefix if there is more than one instance of Moodle on the same server, and you plan to share the database)
    • wwwroot = 'http://myhost.mydomain'
    • dataroot = '/usr/moodle_data/mymoodle'
  • Save your changes and exit from the editor

Apache

  • Install it if it's not installed already.
yum install httpd

or everything

yum install httpd*
  • Start it and make it auto-start after reboot:
service httpd start; chkconfig httpd on
  • Open a web browser and make sure you can connect to the installed web server and default port (80) of the server. If not OK, it may be blocked by the firewall (see above). Correct the problem before continuing.
  • Edit the Apache configuration file
    /etc/httpd/conf/httpd.conf
  • Right at the end of the file add the following lines:
    • <Directory "/usr/moodle/mymoodle"> (the directory used during Moodle installation)
    • 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.

Setting Document Root

Edit

/etc/httpd/conf/httpd.conf

Change From: DocumentRoot /var/www/html

Change To: DocumentRoot /var/www/html/mymoodle

If you want the web site to be served as "http://www.whatever.com/mymoodle" instead of "http://www.whatever.com", don't change it, and modify the 'wwwroot' parameter of Moodle 'config.php' file accordingly.

PHP

  • Install PHP:
yum install php php-cli php-common php-fpm php-gd php-intl php-json php-mbstring php-mysqlnd php-opcache php-pdo php-xml php-xmlrpc php-pecl-zip php-soap
  • Check the installed PHP version:
# php -v
  • Restart the web server so that PHP can start working:
service httpd restart
  • Create a "phpinfo.php" file within the "/var/www/html" directory (or anywhere the Apache "DocumentRoot" points to) with the following content:
<?php
phpinfo();
?>

And then open web browser and browse to "http://webserver/phpinfo.php" to make sure PHP is working with the web server. Then remove the file for security reason.


Install Moodle

Now everything's ready. Use web browser to open "http://webserver/mymoodle/install.php" to start the installation.

Set up 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!).

CLI version

Note: According to Moodle's documentation, users should use the CLI version if possible, as the web version may be removed in future.[9]


  • If you wish to place an entry in your root user's crontab use:
    • crontab -e
    • Add the following line:
 */5 * * * * /usr/bin/php /path/to/mymoodle/admin/cli/cron.php

to run the command every 5 minutes.

Web version

Note: Use the CLI version if possible.
  • 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

http://myhost.mydomain/admin or http://myhost.mydomain/mymoodle/admin

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

http://localhost/admin or http://localhost/mymoodle/admin

Installing SSL certificate

After installing the SSL certificate, change the 'http' to 'https' in the 'wwwroot' parameter of Moodle 'config.php' file.

See also