How to Install Moodle on NixOS Latest

Moodle is an open-source platform used to create and manage online learning environments, such as websites for educational courses, training and development programs, and other online educational resources. NixOS is a Linux distribution that provides a reliable and secure operating system, with advanced package management capabilities.

In this tutorial, we will guide you step-by-step through the process of installing Moodle on NixOS Latest.

Prerequisites

Steps to Install Moodle on NixOS Latest

Step 1 - Install Required Packages

Before installing Moodle, we need to install some required packages that are needed to run the application. Run the following command to install necessary packages.

sudo nix-env -iA nixos.nginx php php-fpm mariadb

Step 2 - Install Moodle

  1. First, you need to create a directory to install Moodle. Run the following command to create a new directory named "moodle".

    sudo mkdir /var/www/moodle
    
  2. Download the latest stable version of Moodle from the official website using the following command.

    sudo curl -o /var/www/moodle/moodle.tar.gz -L https://download.moodle.org/download.php/direct/stable310/moodle-latest-310.tgz
    

    Replace the version number with the latest stable release number.

  3. Extract the downloaded package using the following command.

    sudo tar xzf /var/www/moodle/moodle.tar.gz -C /var/www/moodle/
    
  4. Rename the extracted directory to "moodle".

    sudo mv /var/www/moodle/moodle-* /var/www/moodle/moodle
    
  5. Change the ownership of the Moodle directory to the nginx user.

    sudo chown -R nginx:nginx /var/www/moodle/moodle
    

Step 3 - Configure Nginx

  1. To configure Nginx, create a new file for Moodle virtual host.

    sudo nano /etc/nginx/conf.d/moodle.conf
    
  2. Add the following content to the file.

    server {
        listen 80;
        server_name example.com;
    
        root /var/www/moodle/moodle;
    
        index index.php;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
    

    Replace "example.com" with your domain name or IP address.

  3. Verify that the configuration file is valid with the following command.

    sudo nginx -t
    
  4. If the configuration file is valid, restart the Nginx service.

    sudo systemctl restart nginx
    

Step 4 - Configure MariaDB

  1. To configure MariaDB, start the service.

    sudo systemctl start mariadb
    
  2. Create a new database for Moodle.

    mariadb -u root -p
    MariaDB [(none)]> CREATE DATABASE moodle;
    MariaDB [(none)]> GRANT ALL PRIVILEGES ON moodle.* TO 'moodleuser'@'localhost' IDENTIFIED BY 'moodlepassword';
    MariaDB [(none)]> FLUSH PRIVILEGES;
    MariaDB [(none)]> exit;
    

    Replace the "moodleuser" and "moodlepassword" with your desired username and password.

  3. Open the Moodle configuration file.

    sudo nano /var/www/moodle/moodle/config.php
    
  4. Change the following settings to match the MariaDB database settings.

    $CFG->dbtype = 'mysqli';
    $CFG->dbhost = 'localhost';
    $CFG->dbname = 'moodle';
    $CFG->dbuser = 'moodleuser';
    $CFG->dbpass = 'moodlepassword';
    $CFG->prefix = 'mdl_';
    

    Replace the "moodleuser" and "moodlepassword" with your desired username and password.

Step 5 - Open Moodle Installation Page

  1. Open a web browser and navigate to your domain name or IP address.

    http://example.com
    

    Replace "example.com" with your domain name or IP address.

  2. Follow the instructions to complete the Moodle installation process.

Conclusion

Congratulations! You have successfully installed Moodle on NixOS Latest. You can now start creating your online learning resources within your newly installed Moodle instance.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!