In this tutorial I set up new Ubuntu server 14.04 and Moodle 2.7 for my school. Here is the stack:

  1. Nginx
  2. Php5-fpm
  3. MariaDB (Mysql)

Near Future upgrade: MariaDB cluster + HAProxy for High availability Database

First let update your server

sudo apt-get update && apt-get -y dist-upgrade 

Moodle installation

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

Note: remember your mysql administrator password
Checkout latest Moodle 2.7 from Git repository

cd /opt
sudo git clone git://git.moodle.org/moodle.git
cd moodle
sudo git branch -a
sudo git branch –track MOODLE_27_STABLE origin/MOODLE_27_STABLE
sudo git checkout MOODLE_27_STABLE
sudo mkdir -p /var/www/moodledata
sudo cp -R /opt/moodle /var/www/
chown -R www-data:www-data /var/www/moodle/
chown -R www-data:www-data /var/www/moodledata/
sudo chmod -R 777 /var/www/moodledata
sudo chmod -R 0755 /var/www/html/moodle

In the future just checkout update from git and copy to moodle dir

MariaDB

I left default setting for Mysql because MariaDb run InnoDB as default
Create moodle database and its user. Use your mysql root pass as installation of MariaDB

mysql -u root -p
CREATE DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO moodle_user@localhost IDENTIFIED BY ‘moodle_user_password’;
quit;

Php5-fpm

I run php-fpm on TCP. Edit /etc/php5/fpm/pool.d/www.conf

[www]
user = www-data
group = www-data
listen = 127.0.0.1:9000

pm = ondemand
pm.max_children = 30
pm.start_servers = 10
pm.min_spare_servers = 4
pm.max_spare_servers = 10

pm.max_requests = 50000
request_terminate_timeout = 180
php_flag[display_errors] = off
php_admin_value[error_reporting] = 0
php_admin_value[error_log] = /var/log/php5-fpm.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 128M
chdir = /

service php5-fpm restart

Nginx

This box dedicated for Moodle only. Edit /etc/nginx/site-enabled/default

server {
        listen 80 default_server;
        root /var/www/moodle;
        index index.php index.html index.htm;
        server_name moolde27.mydomain.vn;
        location / {
                try_files $uri $uri/ =404;
        }
        location ~ .php$ {
                fastcgi_split_path_info ^(.+.php)(/.+)$;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi_params;
                }
        }

service nginx restart

 Complete Setup

Notice these Path: /var/www/moodle, /var/www/moodledata

Open your browser and go to http://moodle27.mydomain.vn

Follow the prompts selecting:

Database Type

Choose: MariaDB

Database Settings

Host server: 127.0.0.1
Database: moodle
User: moodle_user
Password: moodle_user_password
Tables Prefix: mdl_

Environment Checks

This will indicate if any elements required to run moodle haven’t been installed.

Next next next…

follow prompts and confirm installation

Create a Site Administrator Account

Create your moodle user account which will have site administrator permissions.

Installation Complete

Congrats! You can now start using Moodle!

It was extremely annoying instead of showing nice Moodle Bootstrap interface it show only text and text. Troubleshooting Nginx does not show Images and CSS
Use browser search for the text path Sites Administration > Server > HTTP
Disable Use slash arguments which is enabled by Default

Reload your Browser and BINGO!

Reference:
http://docs.moodle.org/27/en/Step-by-step_Installation_Guide_for_Ubuntu