Skip to content
Follow
CMS

How to install Moodle with Nginx on Ubuntu 24.04

Richard
Written by
Richard
Jun 1, 2024 Updated Sep 15, 2026 7 min read
Moodle featured image
Moodle featured image

Installing Moodle with Nginx on Ubuntu 24.04 sets up a fast online learning site for schools and classes. Moodle is a free online classroom program, and Nginx is a web server that loads web pages quickly on Ubuntu 24.04 servers.

Advertisement

Pairing these tools helps your site handle many students at once without lagging. You only need a clean Ubuntu 24.04 server and a bit of time to follow these setup steps.

⚡ Quick Answer

Install Nginx and MariaDB using apt, create a Moodle database and user in MariaDB, then install PHP-FPM. These steps set up the necessary web server, database, and scripting environment for Moodle.

Advertisement

Install Nginx HTTP server on Ubuntu Linux

To install Nginx on Ubuntu 24.04 for your Moodle site, open the terminal and update your package list, then run the installation command. This web server handles incoming visitor traffic and serves your web pages. Run sudo apt update followed by sudo apt install nginx to get started.

To do that, open the Ubuntu terminal and run the commands below to install the Nginx web server.

sudo apt update
sudo apt install nginx

Once Nginx is installed, the commands below can start, stop, and enable the Nginx web server to start automatically when your server boots up.

sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl enable nginx

You test that the Nginx web server is running by opening your web browser and browsing to the server’s localhost or IP address.

Advertisement

http://localhost

Nginx default welcome page displayed after successful installation on Ubuntu 24.04
Nginx default welcome page displayed after successful installation on Ubuntu 24.04

When you see the "Welcome to nginx!" it means the Nginx HTTP server is successfully installed.

Additional help on installing Nginx on Ubuntu is in the link below.

How to install Nginx on Ubuntu

Advertisement

Install MariaDB database server on Ubuntu Linux

To install MariaDB on Ubuntu 24.04 for your Moodle database, open your terminal and run the package installation command. MariaDB stores all your course data, user accounts, and site settings securely on the server. Type sudo apt install mariadb-server to install the database service.

To install and use the MariaDB database server, use the instructions below.

Open the Ubuntu terminal and run the commands below to install the MariaDB database server.

sudo apt update
sudo apt install mariadb-server

Once the MariaDB database server is installed, use the commands below to stop, start, and enable the MariaDB server to start automatically when the server boots.

Advertisement
sudo systemctl stop mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb

Run the following commands to validate and test if the MariaDB database server is installed successfully.

sudo mariadb

Once you run the commands above, it will log you onto the MariaDB console and display a message similar to the one below.

Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 32
Server version: 10.11.2-MariaDB-1 Ubuntu 23.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> 

The message tells you that the server is installed successfully.

Additional help on installing MariaDB.

Advertisement

Create a Moodle database

To create a Moodle database in MariaDB, open the database prompt in your terminal and run SQL commands to set up the database and user account. Moodle needs a dedicated database named moodledb and a user with full permissions to read and write its data.

As part of the setup, we will create a database named 'moodledb 'and a corresponding user account named 'moodledbuser '.

Finally, we’ll grant the moodledbuser full access to the moodledb database.

All the database steps above can be done using the commands below:

Advertisement

But first, log on to the MariaDB database server:

sudo mariadb

Then run the commands below to complete the steps:

CREATE DATABASE moodledb CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER moodledbuser@localhost IDENTIFIED BY 'type_your_password_here';
GRANT ALL ON moodledb.* TO moodledbuser@localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit
⚠️WarningEnsure to replace ‘type_your_password_here‘ with your password.

Install PHP-FPM on Ubuntu Linux

To install PHP-FPM on Ubuntu 24.04 for Moodle, run the apt install command with all required PHP extensions in your terminal. Moodle requires PHP-FPM along with specific modules like intl, mysql, and curl to process its code and connect to your database.

Advertisement

Run the commands below to install PHP.

sudo apt install php-fpm php-intl php-mysql php-curl php-cli php-zip php-xml php-gd php-common php-mbstring php-xmlrpc php-json php-sqlite3 php-soap php-zip

Additional help on installing PHP

How to install PHP on Ubuntu Linux

Download Moodle files

To download Moodle files on your Ubuntu 24.04 server, use the terminal to fetch the latest archive directly into your web root directory. This places the core Moodle source code where the Nginx web server can access and serve it to visitors.

The command block below will download and create a new Moodle folder in the Nginx root directory.

First, create a Moodle folder in the Nginx root directory.

The Moodle files download to the /tmp directory. After unzipping the Moodle archive, move the Moodle content into the Moodle folder previously created within the Nginx root directory.

Rest assured, the final step is to change the permissions. This will allow the Nginx web server to safely interact with the files, ensuring a secure environment for your Moodle installation.

💡TipStay up-to-date with Moodle's latest version.

Get it from the official download page and replace the link with the new version to ensure you benefit from the latest features and security updates.

cd /tmp/
wget https://download.moodle.org/download.php/direct/stable404/moodle-4.4.zip
sudo unzip -d /var/www moodle-*.zip
sudo mkdir -p /var/www/moodledata
sudo chown -R www-data:www-data /var/www/moodledata/
sudo chown -R www-data:www-data /var/www/moodle/

Once you have completed all the above steps, continue below to configure the Nginx web server to serve the Moodle content.

Run the commands below to create a Nginx virtual host file for Moodle.

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

Then, copy and paste the content block below into the Nginx server block.

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

location / {
try_files $uri $uri/ =404;
}

location /dataroot/ {
internal;
alias /var/www/moodledata/;
}

location ~ [^/].php(/|$) {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

Save the file.

The Nginx server block configuration for Moodle requires activation to process website traffic correctly. Run `sudo ln -s /etc/nginx/sites-available/moodle /etc/nginx/sites-enabled/` to create a link, then run `sudo systemctl restart nginx` to restart the Nginx server and apply the new Moodle configuration.

sudo ln -s /etc/nginx/sites-available/moodle.conf /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service

Setup Let’s Encrypt SSL/TLS for Moodle

To set up Let's Encrypt SSL for Moodle on Ubuntu 24.04, install Certbot and configure your Nginx security certificates. This enables HTTPS encryption, protecting user passwords and login data as they travel between browsers and your server.

Please read the post below for additional resources on installing and creating Let’s Encrypt SSL certificates for Nginx.

How to set up Let’s Encrypt SSL certificate for Nginx on Ubuntu Linux

Once you have restarted the Nginx web server, open your browser and browse to the server hostname or IP address defined in the Nginx server block.

http://moodle.example.com

A Moodle installation wizard page should appear. Select the installation language and continue to the next page.

Moodle installation setup screen showing language selection options for new users
Moodle installation setup screen showing language selection options for new users

Confirm the installation paths and continue.

Moodle installation wizard confirming web address and directory paths for setup
Moodle installation wizard confirming web address and directory paths for setup

Next, choose a database driver (MariaDB) and continue.

Selecting MariaDB database driver during the Moodle installation process on Ubuntu
Selecting MariaDB database driver during the Moodle installation process on Ubuntu

On the next page, type in the database name, username and password created above and continue.

Configuring database connection settings for Moodle installation on Nginx server
Configuring database connection settings for Moodle installation on Nginx server

Confirm all requirements are met and continue.

If you get an error message that "max_input_vars" must be at least 5000, run the command below to fix it. Ensure that it is applied to the correct PHP version installed.

sudo sed -i "s/;max_input_vars = .*/max_input_vars = 5000/" /etc/php/8.3/fpm/php.ini
sudo systemctl reload php8.3-fpm
Moodle installation server requirements check screen showing successful environment validation
Moodle installation server requirements check screen showing successful environment validation

Next, set up your admin account and continue.

Creating the Moodle administrator account during the initial software setup
Creating the Moodle administrator account during the initial software setup

Your Moodle site should be set up and ready to use.

Final Moodle installation complete screen confirming successful setup on Ubuntu server
Final Moodle installation complete screen confirming successful setup on Ubuntu server

That should do it!

Conclusion:

  • As this guide outlines, setting up a Moodle site with Nginx support on Ubuntu 24.04 can significantly enhance performance and scalability, making it an ideal choice for educational institutions.
  • Leveraging Nginx's low memory usage and high concurrency, combined with the powerful MariaDB database and PHP-FPM, ensures a highly responsive user experience for Moodle.
  • Step-by-step instructions encompass the installation of Nginx, MariaDB, and PHP-FPM, followed by the seamless downloading and configuration of Moodle files.
  • Let’s Encrypt SSL/TLS implementation for Moodle further strengthens security and data protection, culminating in a fully operational Moodle site ready for use.
  • Continuous updates and improvements from the Moodle community ensure that users can benefit from the latest features and security enhancements.

How to install Moodle locally?

Next. It will then ask me for these i'll leave it as is everything as is. And then I'll click on.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

📚 Related Tutorials

Ultimate Guide: Install Moodle on Windows WSL
CMS Ultimate Guide: Install Moodle on Windows WSL
How to Install Nginx on Ubuntu Linux
Ubuntu Linux How to Install Nginx on Ubuntu Linux
How to Start, Stop, and Restart Services in Windows 11
Windows How to Start, Stop, and Restart Services in Windows 11
How to Install FossBilling with Nginx on Ubuntu Linux
CMS How to Install FossBilling with Nginx on Ubuntu Linux

No comments yet — be the first to share your thoughts!

Leave a Comment

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