How to Install Moodle with MariaDB on Ubuntu 14.04
Introduction
Moodle is a popular open-source Learning Management System (LMS) written in PHP. It enables educational institutions and organizations to create and manage online learning environments.
This guide explains how to install Moodle on Ubuntu 14.04 using Apache, PHP-FPM, and MariaDB (or MySQL). PHP-FPM is used instead of the default Apache PHP module to provide better performance and improved resource management.
Prerequisites
Before you begin, ensure you have:
- Ubuntu 14.04 server
- Root or sudo access
- Apache web server
- MariaDB or MySQL
- PHP 5.x with PHP-FPM
- Internet connectivity to download Moodle
Implementation
Step 1: Install Required Packages
Install Apache, MariaDB, PHP, and PHP-FPM.
sudo apt-get install apache2 mariadb-server php5 libapache2-mod-fastcgi php5-fpm
Install the remaining Moodle dependencies.
sudo apt-get install graphviz aspell php5-pspell php5-curl php5-gd php5-intl php5-mysql php5-xmlrpc php5-ldap git-core
Step 2: Configure Apache with PHP-FPM
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 the following line inside your Apache Virtual Host configuration.
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1
Configure PHP-FPM to listen on a TCP port.
Edit:
vi /etc/php5/fpm/pool.d/www.conf
Comment the default socket configuration:
listen = /var/run/php5-fpm.sock
Add:
listen = 127.0.0.1:9000
Restart the services.
service apache2 restart service php5-fpm restart
Step 3: Download Moodle
Navigate to the installation directory.
cd /opt
Clone the Moodle repository.
git clone git://git.moodle.org/moodle.git
Move into the Moodle directory.
cd moodle
List available branches.
git branch -a
Track the latest stable branch (example).
git branch --track MOODLE_31_STABLE origin/MOODLE_31_STABLE
Switch to the stable release.
git checkout MOODLE_31_STABLE
Step 4: Configure Moodle Files
Copy Moodle to the Apache document root.
cp -R /opt/moodle/* /var/www/html/
Create the Moodle data directory.
mkdir /var/moodledata
Set ownership and permissions.
chown -R www-data:www-data /var/moodledata chmod -R 777 /var/moodledata chmod -R 755 /var/www/html/moodle
Restart Apache.
service apache2 restart
Step 5: Configure the Database
Using MariaDB
Verify that InnoDB is the default storage engine.
SHOW ENGINES;
Create the Moodle database.
CREATE DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Create the database user.
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER ON moodle.* TO 'moodle_user'@'localhost' IDENTIFIED BY 'passwordformoodle_user';
Flush privileges.
FLUSH PRIVILEGES;
The same database configuration can also be performed using MySQL.
Step 6: Complete the Moodle Installation
Temporarily update the permissions.
chmod -R 777 /var/www/
Open your browser and access:
http://<server-ip-address>
During the installation wizard, configure:
| Setting | Value |
|---|---|
| Database Type | MariaDB or MySQL (mysqli) |
| Database Host | localhost |
| Database Name | moodle |
| Database User | moodle_user |
| Database Password | passwordformoodle_user |
| Table Prefix | mdl_ |
Complete the environment checks and follow the installation wizard to create the administrator account.
After installation, restore secure permissions.
chmod -R 755 /var/www/
Conclusion
You have successfully installed Moodle on Ubuntu 14.04 using Apache, PHP-FPM, and MariaDB. This setup provides a reliable and high-performance platform for hosting Moodle. Once the installation is complete, you can begin configuring courses, users, and plugins to build your learning environment.
Note: Ubuntu 14.04, PHP 5.x, and Moodle 3.1 are now end-of-life. For new deployments, consider using a supported Ubuntu LTS release, PHP 8.x, and the latest stable version of Moodle to benefit from security updates and improved performance.
