install-moodle-on-an-ubuntu-14-04-vps-with-mariadb-php-fpm-and-nginxIn this tutorial, we will explain how to install Moodle on an Ubuntu 14.04 VPS with MariaDB, PHP-FPM and Nginx. Moodle is an acronym for Modular Object-Oriented Dynamic Learning Environment and it is the most widely used learning platform. This guide should work on other Linux VPS systems as well but was tested and written for an Ubuntu 14.04 VPS.

Login to your VPS via SSH

ssh [email protected]

Update the system and install necessary packages

[email protected]:~# sudo apt-get update && sudo apt-get -y upgrade
[email protected]:~# sudo apt-get install python-software-properties software-properties-common git curl vim graphviz aspell

Install MariaDB 10.0

[email protected]:~# sudo apt-key adv --recv-keys --keyserver hkp:// 0xcbcb082a1bb943db
[email protected]:~# sudo add-apt-repository 'deb trusty main'
[email protected]:~# sudo apt-get install mariadb-server

When the installation is complete, run the following command to secure your installation:


Add the following line in the my.cnf file under [mysqld] section and restart mysql service

[email protected]:~# sudo vim /etc/mysql/my.cnf

binlog_format = ROW
sudo service mysqld restart

Next, we need to create a database for our Moodle installation.

mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE moodle;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON moodle.* TO 'moodleuser'@'localhost' IDENTIFIED BY 'moodleuser_passwd';
MariaDB [(none)]> \q

Clone the Moodle git repository

Create a root directory for your web site and clone the git repository from github using the following commands:

[email protected]:~# mkdir -p ~/{public_html,logs}
[email protected]:~# git clone -b MOODLE_28_STABLE git:// ~/

Create the data directory (moodledata)

[email protected]:~# mkdir -p ~/moodledata

Install PHP-FPM and Nginx

Installing PHP and Nginx is pretty easy, just run the following command:

[email protected]:~# sudo apt-get install nginx php5-fpm php5-cli php5-pspell php5-intl php5-xmlrpc php5-gd php5-mysqlnd php5-curl

PHP-FPM configuration

Create a new PHP-FPM pool for your user:

[email protected]:~# sudo tee /etc/php5/fpm/pool.d/$(whoami).conf << EOF
user = $(whoami)  
group = $(whoami)  
listen = /var/run/php5-fpm-$(whoami).sock  
listen.owner = $(whoami) = $(whoami)  
listen.mode = 0666  
pm = ondemand  
pm.max_children = 5  
pm.process_idle_timeout = 10s;  
pm.max_requests = 200  
chdir = /  

Restart PHP-FPM

[email protected]:~# sudo service php5-fpm restart

Nginx configuration

Create a new Nginx server block with the following content:

[email protected]:~# sudo tee /etc/nginx/sites-available/ << EOF
server {
    listen 80;
    root $HOME/;
    access_log $HOME/;
    error_log $HOME/;
    index index.php;
    location / {
        try_files \$uri \$uri/ /index.php?\$args;
    location ~* \.(?:ico|css|js|gif|jpe?g|png|ttf|woff)\$ {
        access_log off;
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public, mustrevalidate, proxy-revalidate";
    location ~ \.php\$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)\$;
        fastcgi_pass unix:/var/run/php5-fpm-$(whoami).sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    location ~ /\.ht {
        deny all;

Activate the server block by creating a symbolic link :

[email protected]:~# sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Test the Nginx configuration and restart nginx:

[email protected]:~# sudo nginx -t
[email protected]:~# sudo service nginx restart

Final steps

Open your browser and type the address of your website,

  • Step 1: Select language
  • Step 2: Enter the “Data directory (moodledata) path, in our case it is /home/yourusername/moodledata
  • Step 3: Choose database driver, MariaDB
  • Step 4: Enter the Database settings

That’s it. You have successfully installed your Moodle. For more information about Moodle, please refer to the Moodle website.

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.