Moodle is a free and open-source software learning management system written in PHP. In this post, we will be sharing you step by step installations guide to setup Moodle with MariaDB or MySQL on Apache Webserver with PHP FPM support.

We have select PHP FPM support(mod_fastcgi & php-fpm) for Apache because of its high performance compared to default Apache’s mod_php module. The FastCGI Process Manager (PHP-FPM) helps to reduce the amount of system resources used by forcing the web server to act as a proxy and passing only files ending with the php file extension to PHP-FPM. Additionally, using PHP-FPM allows each virtual host to be configured to run PHP code as individual users. Previously, this was only possible by using suPHP.

MariaDB and MySQL are similar and we don’t have to think much on which to select. We have shared steps for both MySQL as well as MariaDB.

Steps:

1) Install the dependent packages:

sudo apt-get install apache2 mariadb-server php5 libapache2-mod-fastcgi php5-fpm

2) Other dependencies:

sudo apt-get install graphviz aspell php5-pspell php5-curl php5-gd php5-intl php5-mysql php5-xmlrpc php5-ldap git-core

3) Prerequisites (Configure PHP FPM in Apache using mod_proxy_fcgi)

Enable Apache proxy modules:

cp -p /etc/apache2/mods-available/proxy.* /etc/apache2/mods-enabled/
cp -p /etc/apache2/mods-available/proxy_fcgi.load /etc/apache2/mods-enabled/

Add under the Apache Virtual host:

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1

Make PHP FPM to listen on TCP port instead of default Unix Socket:

vi /etc/php5/fpm/pool.d/www.conf
Comment the line "listen = /var/run/php5-fpm.sock"
Add the line "listen = 127.0.0.1:9000"
Restart apache2 and php5-fpm services

4) Clone the stable version of Moodle from Github:

4.1) cd /opt
4.2) sudo git clone git://git.moodle.org/moodle.git
4.3) cd moodle
4.3) sudo git branch -a [list all the branches of the git repo]
4.4) sudo git branch --track remotes/origin/MOODLE_31_STABLE origin/MOODLE_31_STABLE [select the lastest stable branch]
4.5) sudo git checkout MOODLE_31_STABLE

5) Copy the moodle files to Apache document root and setup the directory structure:

5.1) sudo cp -R /opt/moodle/* /var/www/html/
5.2) sudo mkdir /var/moodledata
5.3) sudo chown -R www-data /var/moodledata
5.4) sudo chmod -R 777 /var/moodledata
5.5) sudo chmod -R 0755 /var/www/html/moodle
5.6) sudo service apache2 restart

6) MySQL setup (Can use RDS if wanted):

6.1) make innodb the default storage engine by editing "/etc/mysql/my.cnf" and adding the line "default-storage-engine = innodb" under the [mysqld] section and under Basic Settings.
6.2) sudo service mysql restart
6.3) create DB for Moodle: CREATE DATABASE IF NOT EXISTS moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
6.4) create DB user: GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO moodle_user@localhost IDENTIFIED BY 'passwordformoodle_user';

OR

6) MariaDB setup (Can use RDS if wanted):

6.1) Make sure default Storage Engine is set to Innodb. Command to check it: "show engines" from MariaDB console
6.2) create DB for Moodle: CREATE DATABASE IF NOT EXISTS moodle DEFAULT CHARACTER SET = utf8 COLLATE = utf8_unicode_ci;
6.3) create DB user: GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO moodle_user@localhost IDENTIFIED BY 'passwordformoodle_user';

7) Complete the setup:

7.1) chmod -R 777 /var/www/
7.2) Take the URL in your browser: http://<IP address of your server>
7.3) Follow steps:
7.3.1) Database Type: choose mysqli or MariaDB (whichever you opted in step 6)
7.3.2) Database Settings
Host server: localhost
Database: moodle
User: moodle_user (the user you created when setting up the database)
Password: passwordformoodle_user (the password for the user you created)
Tables Prefix: mdl_
7.5) Environment Checks: This will show error if any of the requirements is not setup correctly
7.6) Follow through the steps and enter admin details wherever required
7.7) chmod -R 755 /var/www/

Thats it. You are good to go with the Moodle. Hope it helps.

Comment below if you face any issues or go to our home page “http://pheonixsolutions.com/” to get a best priced quote for any kind of support of Moodle.

Leave a Reply