Install Moodle on an Ubuntu 14.04 VPS with MariaDB, PHP-FPM and Nginx

Leave reply

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 user@vps

Update the system and install necessary packages

user@vps:~# sudo apt-get update && sudo apt-get -y upgrade
user@vps:~# sudo apt-get install python-software-properties software-properties-common git curl vim graphviz aspell

Install MariaDB 10.0

user@vps:~# sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
user@vps:~# sudo add-apt-repository 'deb http://ftp.osuosl.org/pub/mariadb/repo/10.0/ubuntu trusty main'
user@vps:~# sudo apt-get install mariadb-server

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

mysql_secure_installation

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

user@vps:~# 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)]> FLUSH PRIVILEGES;
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:

user@vps:~# mkdir -p ~/yourMoodleSite.com/{public_html,logs}
user@vps:~# git clone -b MOODLE_28_STABLE git://git.moodle.org/moodle.git ~/yourMoodleSite.com/public_html

Create the data directory (moodledata)

user@vps:~# mkdir -p ~/moodledata

Install PHP-FPM and Nginx

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

user@myVPS:~# 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:

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

Restart PHP-FPM

user@vps:~# sudo service php5-fpm restart

Nginx configuration

Create a new Nginx server block with the following content:

user@vps:~# sudo tee /etc/nginx/sites-available/yourMoodleSite.com << EOF
server {
    server_name yourMoodleSite.com;
    listen 80;
    root $HOME/yourMoodleSite.com/public_html;
    access_log $HOME/yourMoodleSite.com/logs/access.log;
    error_log $HOME/yourMoodleSite.com/logs/error.log;
    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;
    }
 
}
EOF

Activate the server block by creating a symbolic link :

user@vps:~# sudo ln -s /etc/nginx/sites-available/yourMoodleSite.com /etc/nginx/sites-enabled/yourMoodleSite.com

Test the Nginx configuration and restart nginx:

user@vps:~# sudo nginx -t
user@vps:~# sudo service nginx restart

Final steps

Open your browser and type the address of your website yourMoodleSite.com/install.php,

  • 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.


50% OFF Coupon

EXCLUSIVE EMAIL UPDATES AND “MEMBERS-ONLY” CONTENT


One Response to “Install Moodle on an Ubuntu 14.04 VPS with MariaDB, PHP-FPM and Nginx”

  1. Techrights

    […] Install Moodle on an Ubuntu 14.04 VPS with MariaDB, PHP-FPM and Nginx […]

    Reply

Leave a Reply