Install Moodle 3.3.2 on Ubuntu 17.04 | 17.10 with Nginx, MariaDB and PHP Support

Few days ago we showed students and new users how to install Moodle with Apache2 MariaDB and PHP support. This post is going to show you how to install Moodle on Ubuntu 17.04 | 17.10 with Nginx, MariaDB and PHP support.

Our previous post, we said Moodle is a free course management system (CMS) designed to help educators create great courses for students. Many reputable universities and colleges are using this software to run their courses online. Students will also find it easy to use and work on. Teachers and students can also use it to collaborate and build great teaching materials.

This post should be easy to read and understand and new users and students should find it easy to follow the install.

To get started with installing Moodle on Ubuntu 17.04 | 17.10 with Nginx, MariaDB and PHP, follow the steps below:

Step 1: Install Nginx

Moodle requires a webserver to function. In our previous post we used Apache2. This post uses Nginx as the webserver of choice to run Moodle. To install Nginx, run the commands below.

sudo apt-get update
sudo apt-get install nginx

After installing Nginx, the commands below can be used to stop, start and enable nginx service to always start up with the Ubuntu server is started.

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

STEP 2: INSTALL MARIADB

Moodle also requires a database server to function.. and MariaDB database server is a great place to start. To install it run the commands below.

sudo apt-get install mariadb-server mariadb-client

After installing, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots.

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

After that, run the commands below to secure MariaDB server.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Create password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

After that, open MariaDB default configuration file by running the commands below:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Then add the below lines just below [mysqld] section.

default_storage_engine = innodb
innodb_file_per_table = 1
innodb_file_format = Barracuda
innodb_large_prefix = 1

Save the file and exit.

Restart MariaDB server by running the commands below.

systemctl restart mariadb.service

STEP 3: INSTALL PHP AND RELATED MODULES

Moodle also requires PHP to function. To install PHP and related modules run the commands below

sudo apt-get install php-fpm php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysql php-cli php-mcrypt php-ldap php-zip php-curl

Some of the PHP packages depend on Apache2.. so since we’re using Nginx, run the commands to disable Apache2 service.

sudo systemctl disable apache2.service

STEP 4: CREATE MOODLE DATABASE

Now that you’ve install all the packages that are required, continue below to start configuring the servers. First run the commands below to create Moodle database.

Run the commands below to logon to the database server. When prompted for a password, type the root password you created above.

sudo mysql -u root -p

Then create a database called moodle

CREATE DATABASE moodle;

Create a database user called moodleuser with new password

CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'new_password_here';

Then grant the user full access to the database.

GRANT ALL ON moodle.* TO 'moodleuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;

Finally, save your changes and exit.

FLUSH PRIVILEGES;
EXIT;

STEP 5: DOWNLOAD MOODLE LATEST RELEASE

Next, run the commands below to download Moodle latest release. The commands below to download Moodle archive package.

cd /tmp && wget https://download.moodle.org/download.php/direct/stable33/moodle-latest-33.tgz

Then run the commands below to extract the download file to Apache2 default root.

sudo tar -zxvf moodle-latest-33.tgz -C /var/www/html

Next create Moodle data directory.. this is required.

sudo mkdir -p /var/www/html/moodledata

Change modify the directory permission.

sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

Step 6: Configure Nginx

Finally, run the commands below to create a new moodle site configuration file called moodle .. then add the block of code in the file and save. Run the commands below.

sudo nano /etc/nginx/sites-available/moodle

Then copy the content below into the new file and save

server {
    listen 80;
    listen [::]:80;
    root /var/www/html/moodle;
    index  index.php index.html index.htm;
    server_name  example.com www.example.com;

    location / {
    try_files $uri $uri/ =404;        
    }
 
    location /dataroot/ {
    internal;
    alias /var/www/html/moodledata/;
    }

    location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info  ^(.+\.php)(/.+)$;
    fastcgi_index            index.php;
    fastcgi_pass             unix:/var/run/php/php7.0-fpm.sock;
    include                  fastcgi_params;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

}

Step 7: Enable the New Site

Now that the new site is configured, run the commands below to enable it.

sudo ln -s /etc/nginx/sites-available/moodle /etc/nginx/sites-enabled/

Restart Nginx server.

sudo systemctl restart nginx

Now open your browser and browse to the server hostname, domain name or IP address and you should see Moodle default setup page.

Enjoy!

You may also like the post below:

Installing Spotify Linux Client on Ubuntu 17.04 / 17.10

2 Replies to “Install Moodle 3.3.2 on Ubuntu 17.04 | 17.10 with Nginx, MariaDB and PHP Support

  1. Forgot to write ‘;’
    alias /var/www/html/moodledata/;
    in /etc/nginx/sites-available/moodle causing to fail the server

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: