Installing Moodle on Ubuntu

Moodle on Ubuntu Hero Image

Moodle can be installed on many different operating systems, including Ubuntu. While some programs such as Fantastico or Softaculous use graphical user interfaces that allow users to install software such as Moodle, some users prefer to manually install the software instead. In this article, we will outline the installation process for Moodle on Ubuntu. Please note that these steps require use of a SSH command-line interface to complete the installation. It is recommended that only users familiar with command-line operations attempt to install Moodle in this fashion. 

Topics Include:

Experience unrestricted processing power on state-of-the-art hardware and your preferred operating system with Bare Metal Hosting!

check mark Ubuntu, Debian, OpenSUSE, or Load your own OS check markUnmanaged Hosting check markPerfect for SysAdmins check markDedicated Resources

Bare Metal Servers

Pre-Flight Checklist

  1. Before you can install Moodle, you will need to install a few other technologies. First, install the Apache web server software. Then, install the MySQL database server as well as the requisite version PHP. 
  2. Next, you will need to install the necessary modules for Moodle using the following command:
    sudo apt install graphviz aspell ghostscript clamav php7.4-pspell php7.4-curl php7.4-gd php7.4-intl php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-ldap php7.4-zip php7.4-soap php7.4-mbstring
  3. After these modules have been installed, restart Apache. 
    sudo service apache2 restart
  4. Once Apache has restarted, install git in order to access git repositories. This can be done using the following command:
    sudo apt install git
  5. Once git is installed, change directory into /opt folder with the cd command:
    cd /opt

Installing Moodle

  1. While still in the /opt folder, download the Moodle code using the git command:
    sudo git clone git://git.moodle.org/moodle.git
  2. Once downloaded, change directory into the moodle folder, again with cd:
    cd moodle
  3. To get a list of available git branches, use the following command:
    sudo git branch -a 
  4. Next, tell git which branch to use with the following command:
    sudo git branch --track MOODLE_39_STABLE origin/MOODLE_39_STABLE
  5. Once that is done, check out the current version of Moodle being used with the following command:
    sudo git checkout MOODLE_39_STABLE
  6. Before proceeding to the next steps, first create a database in mysql for your Moodle site.
  7. Once you’ve created the database, copy the Moodle data to the website root folder /var/www/html with the following command:
    cp -R /opt/moodle /var/www/html
  8. Also, make a moodledata folder in the /var/ folder using the mkdir command:
    mkdir /var/moodledata
  9. Once that folder has been created, update its ownership with the following command:
    sudo chown -R www-data /var/moodledata
  10. Next, update the permissions for the moodle and moodledata folder using the chmod command:
    sudo chmod -R 777 /var/moodledata

    sudo chmod -R 0755 /var/www/html/moodle
  11. Before running the installer, update the permissions of your Moodle folder using the following command:
    sudo chmod -R 777 /var/www/html/moodle
  12. In your web browser, go to your domain name followed by /moodle to run the installer. It should then ask you to select a language, specify your web address, and the document root for the site. This document root should be /var/www/html/moodle.

    The installer will also ask you to specify a data directory, which is the /var/moodledata folder we created in step 8. The installer will then ask you to specify which database driver you use (typically MySQL or MariaDB), and then prompt you to input the database information you created in step 6.
  13. Once you’ve finished with this, the installer should prompt you to accept the terms of the installation and then allow you to press Continue to complete the installation. You will then have the opportunity to create an administrator account for Moodle dashboard access. 
  14. Now that the installation is complete, you will want to revert the root directory permissions to their default using the following command:
    sudo chmod -R 0755 /var/www/html/moodle

Congratulations, you have now installed Moodle on Ubuntu!

Want to learn more about Moodle? Check out our getting started guide here!

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!