Moodle is a robust, free, and open-source Learning Management System (LMS) built with PHP. It empowers educators to create comprehensive online courses for students on a secure and integrated platform with features like wikis, grading tools, assignment submissions, online quizzes, and discussion boards. Widely used by educational institutions and organizations globally, Moodle enhances the learning experience through a customizable dashboard that provides access to current, past, or forthcoming courses and monitors pending tasks.
This guide demonstrates how to install Moodle using the Nginx web server and secure it with Let’s Encrypt SSL on an Ubuntu 20.04 server.
Prerequisites
- A server running Ubuntu 20.04.
- A valid domain name pointing to your server’s IP.
- Root access configured on the server.
Getting Started
First, ensure your system packages are up-to-date by running:
apt-get update -y
Once updated, proceed to the installation steps.
Install LEMP Stack
Install Nginx, MariaDB, PHP, and required PHP libraries by executing:
apt-get install nginx mariadb-server php-fpm php-common php-mysql php-gmp php-curl php-intl php-mbstring php-soap php-xmlrpc php-gd php-xml php-cli php-zip unzip git curl -y
Then, modify the PHP configuration by editing the php.ini file:
nano /etc/php/7.4/fpm/php.ini
Adjust the following settings:
memory_limit = 256M cgi.fix_pathinfo = 0 upload_max_filesize = 100M max_execution_time = 360 date.timezone = America/Chicago
Save the changes and restart PHP-FPM to apply them:
systemctl restart php7.4-fpm
Create a Database for Moodle
Moodle requires a database. Use MySQL or MariaDB to create one:
Access the MySQL shell:
mysql
Set up a database and user:
CREATE DATABASE moodledb; CREATE USER 'moodle'@'localhost' IDENTIFIED BY 'password';
Grant the necessary privileges:
GRANT ALL ON moodledb.* TO 'moodle'@'localhost' WITH GRANT OPTION;
Flush privileges and exit the MySQL interface:
FLUSH PRIVILEGES; EXIT;
Adjust the MariaDB configuration file for Moodle:
nano /etc/mysql/mariadb.conf.d/50-server.cnf
Add the following under [mysqld]:
[mysqld] innodb_file_format = Barracuda innodb_file_per_table = 1 innodb_large_prefix = ON
Restart MariaDB:
systemctl restart mariadb
Install Moodle
Download Moodle into the web directory:
cd /var/www/html git clone -b MOODLE_38_STABLE git://git.moodle.org/moodle.git moodle
Edit Moodle’s configuration file:
nano /var/www/html/moodle/config.php
Replace the database type as follows:
$CFG->dbtype = 'mariadb';
Create a Moodle data directory and set permissions:
mkdir -p /var/www/html/moodledata chown -R www-data:www-data /var/www/html/moodle chmod -R 755 /var/www/html/* chown www-data:www-data /var/www/html/moodledata
Configure Nginx for Moodle
Create an Nginx virtual host configuration file:
nano /etc/nginx/conf.d/moodle.conf
Add the following server block:
server { listen 80; root /var/www/html/moodle; index index.php index.html index.htm; server_name moodle.example.com; client_max_body_size 100M; autoindex off; location / { try_files $uri $uri/ =404; } location /dataroot/ { internal; alias /var/www/html/moodledata/; } location ~ [^/].php(/|$) { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
Test the Nginx configuration for syntax errors:
nginx -t
If successful, restart Nginx:
systemctl restart nginx
Access Moodle’s Web Interface
Launch your web browser and navigate to http://moodle.example.com to start the Moodle installation process. Follow the on-screen instructions to set up Moodle.
Secure Moodle with Let’s Encrypt SSL
Install Certbot to obtain and configure Let’s Encrypt SSL for Nginx:
apt-get install python3-certbot-nginx -y
Run Certbot to obtain the SSL certificate:
certbot --nginx -d moodle.example.com
Follow the prompts to complete the SSL configuration and choose to redirect HTTP to HTTPS to ensure secure connections.
Conclusion
Congratulations! You’ve successfully installed Moodle with an Nginx web server and secured it with Let’s Encrypt SSL on Ubuntu 20.04. Start building your online education platform with ease.
FAQs
Can I install Moodle on other Linux distributions?
Yes, Moodle can be installed on various Linux distributions using similar steps. Make sure to use equivalent package management commands for your specific distribution.
How do I update Moodle after installation?
Moodle updates can be handled by running Git commands in the Moodle directory. Always refer to Moodle’s official documentation for detailed update procedures.
What if my Moodle setup doesn’t work as expected?
Ensure all prerequisites and installation steps have been followed accurately. Check logs for errors and consult Moodle’s community forums for assistance.
How can I change the default PHP settings for Moodle?
PHP settings can be modified in the php.ini file and require restarting PHP-FPM for changes to take effect. Ensure any changes align with Moodle’s system requirements.