Install Moodle On Ubuntu with Nginx/PHP-fpm

Jump to: navigation, search

This page requires updating. Please do so and remove this template when finished.

From scratch

This is a starting guide to install Moodle with Nginx/PHP-fpm/Postgres on the latest Ubuntu LTS 14.04. It is important to take note that Moodle is heavily tested in an Apache2 environment, not in a nginx environment. This document is for people having previously installed a Moodle site and a Ubuntu distribution, and having some basic knowledge of Linux command lines (vim, linux permissions, compiling, etc.).

Nginx 1.9.x

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nginx
mkdir -p /home/nginx/localhost/public
sudo chgrp www-data /home/nginx/localhost/public

sudo vim /etc/nginx/sites-available/default (or better yet, make a new one: sudo vim /etc/nginx/sites-available/moodle)

server {
listen 80;
server_name  ;
root /usr/share/nginx/html/your-moodle;
index index.php index.html index.htm;
location / {
# First attempt to serve request as file
try_files $uri $uri/index.php;
# pass the PHP scripts to FastCGI server listening on
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
#free to choose between port or sock file.
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;

Postgres 9.3.5

sudo apt-get install postgresql

Create database user and database see Moodle doc PostgreSQL

PHP 5.5.9

Note: if you use postgres do not take PHP 5.3.5, pg_set_client_encoding() will crash with a http 500 error.

sudo apt-get install php5-fpm
sudo apt-get install php5-pgsql
sudo apt-get install php5-curl
sudo apt-get install php5-gd
sudo apt-get install php5-xmlrpc
sudo apt-get install php5-Intl
sudo service nginx restart
sudo service php5-fpm restart

vim /home/nginx/localhost/public/info.php


Check if the site is available. localhost/info.php

PHP 5.5 comes with OPCache. on older versions you might want to use APC:


Install Moodle into /home/nginx/localhost/public/. Note that it is recommended to install Git and to get the Moodle files with Git.

Start by enabling "Slash Arguments" on Nginx, and if it fails to work try adding the following line to the "server" section of the Nginx config file (where "/your-moodle" is used in case you have your Moodle folder show up on your domain name, otherwise, discard it):

rewrite ^/your-moodle/(.*\.php)(/)(.*)$ /your-moodle/$1?file=/$3 last;

More info stackoverflow


In the Moodle administration, disable 'slash arguments' (http://YOURMOODLESITE/admin/search.php?query=slashargument). Without disabling the 'slash arguments', you may notice that the admin setup page is missing the images and css styling. However, if you turn off slash arguments, then other things won't work, so really someone ought to work out what is wrong here and fix it.

If you cannot access the Admin interface, you can edit the database using a tool like phpMyAdmin.

1. Go to the table labeled 'mdl_config'

2. Browse to line 281 (line 309 in 2.5), and change the value of 'slasharguments' from 1 to 0

3. Use Control-F5 to fully refresh the setup page.

Workaround if the above steps don't work:

1. Empty the database and try the command line installation.

cd /var/www/YOURMOODLESITE/public/moodle
php /admin/cli/install.php

Enabling PHP errors in php.ini will help you diagnose any errors that may arise.

Use if you ran the cli install.php as root: chown www-data:www-data config.php

2. Go to your Moodle site and log in. It will ask you to fill in your email address, City and Country. Save the changes.

3. Go to http://YOURMOODLESITE/admin/search.php?query=slashargument and uncheck "Use slash arguments"

Note: some version of Internet Explorer will display the page CSS with slash arguments on, while Firefox, Chrome and IE10 will not.

More to do

There are still a lot more to do (setting up your domain name, establishing a maintenance plan, performance tweaking, security testing...). Be patient and have fun.

Related document