Moodle is a free and open-source CMS (Content Management System) for serving learning courses. It is a great solution for organizations to provide an courses for students or other users.

In this tutorial we’ll install Moodle on Ubuntu 18.04 using LEMP Stack – Nginxm, PHP, and MariaDB.


For this tutorial we recommend the following:

  • A non-root sudo user. If you need help setting this up on Ubuntu, you can follow our tutorial on creating sudo users on Ubuntu.
  • A machine with the minimum requirements of 512 RAM (although 1GB RAM is better), running Ubuntu 18.04

Get a High RAM VPS at Entry-level Pricing

Starting with 2GB RAM at $6.99/month

Take your pick from our KVM VPS that offer a generous amount of RAM at an affordable price. We've got 5 plans for you to choose from, our smallest featuring 2GB RAM at $6.99/mo.

[Main Features]
  - SSD Drives
  - KVM Virtualization
  - 1Gbps Shared Uplink
  - Location: Chicago, IL

Pick one of our KVM plans

Step 1 – Install Nginx Web Server

First we’ll set up a web server. In this tutorial we’ll use Nginx. To install it, update your package index and install nginx via the apt package manager:

After installing nginx, we’ll stop, start and enable nginx to always start on boot:

Step 2 – Install MariaDB

Moodle also needs a database server to store and manage part of it’s data. For this, we’ll use MariaDB. To install it, run the following:

As we’ve done with Apache, after installing it we’ll stop, start and enable MariaDB to make sure it starts on server boot:

To secure the installation, MariaDB comes with a script to help adjust some insecure defaults. Start the script by running:

If you haven’t set a MariaDB password already and are prompted with Enter current password for root (enter for none) then just hit enter to move on – you’ll set the password next.

You should be prompted to set the root password for MariaDB. Answer Y to this.

And set your password. Make sure it’s different than your SSH password, for security reasons.

You’ll also be prompted to answer some questions to remove/keep some defaults. We recommend you answer them as follows:

We’ll also need to configure MariaDB to be compatible with Moodle. To do this, we’ll open up the MariaDB default configuration file:

And we’ll add the following lines under Basic Settings, in the [mysqld] section:

It should look something like this:

Save and exit the file when you’re done.

Restart MariaDB to apply the changes:

Step 3 – Install PHP7.1-FPM and Related Modules

Since PHP7.1 may not be available in the Ubuntu default repositories, we’ll have to add a third party repository from which to install it.

We’ll do this by first installing software-properties-common , as it is required by the add-apt-repository command, and then we’ll add the repository:

Now update your package index:

And install PHP7.1 and related modules:

After this, we’ll adjust some PHP defaults by editing /etc/php/7.1/fpm/php.ini.

Then search and adjust the following lines accordingly ( you can change some values depending on your requirements):

Do keep in mind to also uncomment cgi.fix_pathinfo by removing the ; from the start of the line.

Step 4 – Creating the Database for Moodle

Now that we’ve got MariaDB installed and configured on our server, we need to create a database so Moodle can store and manage data.

First log into MySQL, and enter your MySQL password when prompted.

Once logged in, we’ll create the database. We’ll call it moodle but you can call it whatever you want.

Now we’ll create the Moodle user and assign it a password. We’ll call it moodle_admin and assign it M00dle_p@ssw0rd, but you can replace the user and password with whatever you prefer.

Exit MySQL when you’re done:

Step 5 – Download & Install Moodle

Before installing Moodle, we’ll have to download the latest release.

To do this, retrieve the download link for the latest Moodle release, by visiting the Latest Release Download Page in your browser, and retrieving the latest .tgz.

The latest version at the time of writing is Moodle 3.6.2+, and the link looks like this:

We’re assuming that you’re on a server and have access only to command line, so to download the package we’ll use wget. That link is not a direct download link, however. To obtain the direct download link, we’ll add direct/ after download.php/. The final link will be the following:

Now we’re ready to download Moodle to our Ubuntu machine.

We’ll now change our current directory to /tmp, to keep things clean when downloading temporary files, and then downloading Moodle using wget:

Next, we’ll unzip the downloaded archive into our web document root. Most likely it’s /var/www/html. If your web document root is different, then replace /var/www/html with yours.

Run the following commands to modify the directory owner and permissions:

We’ll also create a directory for Moodle to store all the course related data. By default, the data directory is stored in the web root, but it’s more secure to store it out of it so it cannot be accessed directly from a browser:

Then set the ownership to www-data and change the permissions for the directory so only the owner has full permissions:

Step 6 – Configure Nginx for Moodle

Now we’ll configure Nginx Server Blocks to serve Moodle. We’ll create a new configuration file:

And add the following contents, replacing the with your domain or server IP:

Save and exit the file when you’re done.

Now enable the site by creating a symbolic link into /etc/nginx/sites-available:

And restart nginx to enable the changes

Step 7 – Finish Moodle Installation in the Browser

To finish up the Moodle installation, we’ll need to do some final configurations in the browser. To do this, navigate to your server’s IP or domain name in the browser.

In my case, I’ll navigate to You’ll be greeted by the initial page where you choose the language and then click Next to proceed to the next step.


Next, we choose the Moodle installation directory and data directory. If you’ve followed this tutorial, set the Moodle directory to /var/www/html/moodle and the data directory to /var/moodledata.


Next, we choose the database driver, which in our case is MariaDB.


Now we provide the Moodle installer with the database details that we set up for it, and leave the others as they are.


The installer will now perform some checks. Scroll down and click Continue.


After you’ve clicked, it’ll take a minute to perform some checks, after which you can continue.

This will lead you to the final step, where you set up your admin account.



That’s it. You’ve successfully installed Moodle on Ubuntu 18.04 using LEMP stack.

You can now start adding your courses.

If you’ve found any issues with this tutorial, then feel free to contact us and we’ll get back to you as soon as possible.

Need Help?

Have a server from a different provider and need help? Hit us up!

We offer various services to assist you in achieving your business goal. Working in the industry, we've gained proficiency various areas related to hosting.

[Proficiencies Include]
  - LAMP Stack
  - LEMP Stack
  - VPN Protocols
  - SMTP
  - Remote Desktop Solutions
  - Linux in general

Hire Us


Tech Support

Leave a Comment


Enter your email below to get 20% OFF on any of our Linux VPS plans and receive weekly deals on our services!