Moodle is an open-source course management system that works great for professionals, businesses, and colleges who want to run and manage their courses or training materials online securely. It is probably the best and most popular open-source learning management platform available today. However, if you’re going to be setting up Moodle in your environment, make sure to run it over HTTPS. This setup might take a while to complete and the process below should work on other Linux platforms as well. To get started with installing Moodle on Ubuntu Linux with Apache and Let’s Encrypt, follow the steps below.

How to setup your domain

If you’re going to be using Let’s Encrypt, you should then make sure your domain is configured correctly. This setup assumes that your domain name is called example.com and is pointing to your server with IP address 192.168.1.2 Don’t forget to also make sure www CNAME is pointing to the domain name. Should look like something below:

How to install Apache on Ubuntu Linux

As mentioned above, we’re going to be using the Apache web server to run Moodle. Moodle requires a web server to function, and Apache is one of the most popular open-source web servers available today. To install Apache on Ubuntu, run the commands below: After installing Apache, the commands below can be used to stop, start and enable Apache services to always start up every time your server starts up. To test whether Apache is installed and functioning, open your web browser and browse to the server’s IP address or hostname. If you see the above page in your browser, then Apache is working as expected.

How to install MariaDB on Ubuntu Linux

A database server is required for Moodle to function. Moodle stores its content in a database, and MariaDB is probably the best database server available to run Moodle. MariaDB is fast, secure and the default server for almost all Linux servers. To install MariaDB, run the commands below: After installing MariaDB, the commands below can be used to stop, start and enable MariaDB services to always start up when the server boots. Next, run the commands below to secure the database server with a root password if you were not prompted to do so during the installation. When prompted, use the guide below to answer: To verify and validate that MariaDB is installed and working, log in to the database console using the commands below: You should automatically be logged in to the database server since we initiated the login request as root. Only the root can log in without a password, and only from the server console. If you see a similar screen as shown above, then the server was successfully installed. Next, run the commands below to open the MariaDB default config file… Then add the highlighted lines below and save. Restart MariaDB after that.

How to install PHP on Ubuntu Linux

As we also mentioned above, we’re installing PHP on Ubuntu since Moodle requires it. PHP packages are added to Ubuntu repositories. The versions of the repositories might not be the latest. If you need to install the latest versions, you’ll need to add a third-party PPA repository. To a third-party repository with the latest versions of PHP, run the commands below. At the time of this writing, the latest PHP version is 7.4. Next, run the commands below to install PHP 7.4 and related modules. Next, you’ll want to change some PHP configuration settings that work great with Moodle. Run the commands below to open the PHP default configuration file. Then change the line settings to be something like the lines below. Save your changes and exit.

How to create Moodle database on Ubuntu

At this point, we’re ready to create Moodle database. As mentioned above, Moodle uses databases to store its content. To create a database for Moodle, run the commands below: Then create a database called moodle Next, create a database user called moodleuser and set a password Then grant the user full access to the database. Finally, save your changes and exit.

How to download and install Moodle on Ubuntu Linux

To get Moodle’s latest release you may want to use the GitHub repository. Install Curl and other dependencies to get started. After installing git and curl above, change into the Apache2 root directory and download Moodle packages from Github. Always replace the branch number with the latest branch. The current major version is 36. Then run the commands below to set the correct permissions for Moodle to function.

How to configure Apache for Moodle

Next, configure the Apache site configuration file for Moodle. This file will control how users access Moodle content. Run the commands below to create a new configuration file called example.com.conf Then copy and paste the content below into the file and save it. Replace the highlighted line with your domain name and directory root location. Save the file and exit. Now that the example.com configuration file is created, run the commands below to enable it. At this stage, Moodle is ready and can be launched by going to the server’s IP or hostname. However, we want to make sure our server is protected with Let’s Encrypt free SSL certificates. So, continue below to learn how to generate a Let’s Encrypt SSL certificate for websites.

How to setup Let’s Encrypt for Moodle

We have written a great post on how to generate and manage Let’s Encrypt SSL certificates for Apache web servers. You can use that post, to apply it here for your Moodle website. To read the post on how to generate Let’s Encrypt SSL certificates for a website, click on the link below: How to Setup Let’s Encrypt on Ubuntu Linux with Apache – Website for Students If you were successful in generating a Let’s Encrypt SSL certificate, you should then reopen the server block for our Moodle website by running the commands below. The new Moodle server block configurations should look similar to the line below. Take notes of the highlighted lines.

The first server block listens on port 80.  It contains a 301 redirect to redirect HTTP to HTTPS. The second server block listens on port 443. It contains a 301 redirect to redirect www to the non-www domain.

Save the file above, then restart Apache and PHP using the commands below. Finally, if everything went as planned, you should be able to start Moodle setup wizard by browsing to the server hostname or IP address over HTTPS. Then follow the on-screen instructions and select the installation language here. Next, select the MariaDB connection driver and continue. On the next screen, enter the database connection info you created above and continue. Then create an admin account and the Moodle site info and finish the installation. On this page, you should configure your main administrator account which will have complete control over the site. Make sure you give it a secure username and password as well as a valid email address. You can create more admin accounts later on. Log in and begin configuring your Moodle website. In the future when you want to upgrade to a newly released version, simply run the commands below to upgrade.

How to upgrade Moodle on Ubuntu Linux

First, stop the web server… For students and new users who already have Moodle installed and wish to upgrade, assuming that you followed the steps above to install, run the commands below to backup your old Moodle folder… Then change into the web server root directory and download the latest version of Moodle from Github…. always change the version number to the current (latest) Next, copy Moodle config file, theme, and data folder… If you updated your themes… theme content should be there…. If you also installed additional modules… you should find them in the /mod directory… copy them to the new Moodle folder…. After that, update the web server permissions. Restart your web server. The last step is to trigger the upgrade processes within Moodle…. If you put your site into Maintenance mode earlier; take it out now! Once you browse to the server IP or hostname, Moodle should prompt you to begin upgrading your database… After upgrading the database, login to Moodle and go to: Administration > Site administration > Notifications. Moodle will automatically detect the new version and perform all the SQL database or file system upgrades that are necessary. If there is anything it can’t do itself (very rare) then you will see messages telling you what you need to do. Assuming all goes well (no error messages) then you can start using your new version of Moodle and enjoy the new features! That should do it! Conclusion: This post showed you how to install Moodle on Ubuntu Linux with Apache and Let’s Encrypt. If you find any error above or have something to add, please use the comment form below.