Introduction
Moodle is a free and open-source Learning Management System (LMS) written in PHP. It can be used to create and manage online learning platforms, courses, users, and educational content.
In this guide, we will walk through the step-by-step process of setting up Moodle with MariaDB or MySQL on an Apache web server with PHP-FPM support on Ubuntu 14.04.
For Apache, we use PHP-FPM with FastCGI support because it can provide better performance compared with the traditional Apache mod_php approach. PHP-FPM also allows the web server to pass PHP requests to a dedicated PHP process manager and provides additional flexibility when configuring PHP applications.
MariaDB and MySQL provide similar database functionality for this setup, so the guide includes configuration steps for both database options.
Prerequisites
Before starting the Moodle installation, make sure you have:
- An Ubuntu 14.04 server.
- Root or
sudoaccess. - Apache web server access.
- Basic knowledge of Linux commands.
- Basic knowledge of MySQL or MariaDB.
- A server IP address or domain name for accessing Moodle.
Implementation
Step 1: Install the Required Packages
Install Apache, MariaDB, PHP, PHP-FPM, and the required FastCGI module:
sudo apt-get install apache2 mariadb-server php5 libapache2-mod-fastcgi php5-fpm
Step 2: Install Moodle Dependencies
Install the additional packages required by Moodle:
sudo apt-get install graphviz aspell php5-pspell php5-curl php5-gd php5-intl php5-mysql php5-xmlrpc php5-ldap git-core
These packages provide additional PHP functionality and supporting utilities required by Moodle.
Step 3: Configure PHP-FPM with Apache
Configure Apache to communicate with PHP-FPM using FastCGI.
Enable Apache Proxy Modules
Enable the required 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 PHP-FPM Proxy Configuration
Add the following configuration inside the Apache VirtualHost configuration:
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1
Configure PHP-FPM to Listen on TCP
By default, PHP-FPM may listen through a Unix socket. For this configuration, change it to listen on TCP port 9000.
Edit the PHP-FPM pool configuration:
vi /etc/php5/fpm/pool.d/www.conf
Comment out:
listen = /var/run/php5-fpm.sock
Add:
listen = 127.0.0.1:9000
Restart Apache and PHP-FPM after making the changes.
Step 4: Download the Stable Moodle Version
Clone the Moodle repository from Git:
cd /opt sudo git clone git://git.moodle.org/moodle.git cd moodle
List the available branches:
sudo git branch -a
Select the required stable branch:
sudo git branch --track remotes/origin/MOODLE_31_STABLE origin/MOODLE_31_STABLE
Checkout the stable branch:
sudo git checkout MOODLE_31_STABLE
Step 5: Copy Moodle Files and Configure the Directory Structure
Copy the Moodle files to the Apache document root:
sudo cp -R /opt/moodle/* /var/www/html/
Create the Moodle data directory:
sudo mkdir /var/moodledata
Set the ownership:
sudo chown -R www-data /var/moodledata
Set the required permissions:
sudo chmod -R 777 /var/moodledata sudo chmod -R 0755 /var/www/html/moodle
Restart Apache:
sudo service apache2 restart
Step 6: Configure the Database
Moodle can be configured with either MySQL or MariaDB.
Option 1: MySQL Setup
Make InnoDB the default storage engine by editing:
/etc/mysql/my.cnf
Under the [mysqld] section and Basic Settings, add:
default-storage-engine = innodb
Restart MySQL:
sudo service mysql restart
Create the Moodle database:
CREATE DATABASE IF NOT EXISTS moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Create the Moodle database user and grant the required permissions:
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO moodle_user@localhost IDENTIFIED BY 'passwordformoodle_user';
Option 2: MariaDB Setup
Verify that InnoDB is available as the storage engine.
From the MariaDB console, run:
show engines
Make sure InnoDB is available and configured as required.
Create the Moodle database:
CREATE DATABASE IF NOT EXISTS moodle DEFAULT CHARACTER SET = utf8 COLLATE = utf8_unicode_ci;
Create the Moodle database user:
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO moodle_user@localhost IDENTIFIED BY 'passwordformoodle_user';
Step 7: Complete the Moodle Setup
Before starting the browser-based installation, set the required permissions:
chmod -R 777 /var/www/
Open the server IP address in your browser:
http://<IP address of your server>
The Moodle installation wizard will start.
Database Type
Select:
mysqliif you selected MySQL.MariaDBif you selected MariaDB.
Database Settings
Enter the database details created during the previous step:
| Setting | Value |
|---|---|
| Host server | localhost |
| Database | moodle |
| User | moodle_user |
| Password | passwordformoodle_user |
| Tables Prefix | mdl_ |
Environment Checks
Moodle will perform environment checks to verify whether the required server configuration and dependencies are available.
If any requirement is missing or incorrectly configured, the installer will display an error that needs to be resolved before continuing.
Follow the remaining installation steps and provide the required administrator details.
After completing the installation, restore the required permissions:
chmod -R 755 /var/www/
Conclusion
Moodle can be configured on Ubuntu with Apache, PHP-FPM, and either MariaDB or MySQL as the database backend.
In this setup, PHP-FPM is configured to communicate with Apache through FastCGI, while Moodle is installed from its Git repository and configured with a dedicated database and moodledata directory.
Once the environment checks are completed and the administrator account is configured, Moodle is ready to use.
Frequently Asked Questions
1. Can Moodle use MariaDB instead of MySQL?
Yes. The original setup supports both MariaDB and MySQL as the database backend.
2. Why is PHP-FPM used with Apache?
PHP-FPM provides a separate PHP process manager that allows Apache to pass PHP requests through FastCGI instead of processing PHP through the traditional mod_php approach.
3. Where is Moodle’s data directory configured?
The guide creates the Moodle data directory at:
/var/moodledata
The directory is given www-data ownership so that the web server can access it.
Related Articles
How to Change MySQL User Authentication Plugin for Password?
Managing Multiple PHP Versions on Ubuntu Using APT
Talk to our experts
Looking for the right technology solution for your business? Our team of experts can help you with development, cloud, DevOps, design, and a wide range of other technology needs. Get in touch with our team here.