ssh root@IP_Address -p Port_number<\/pre>\nReplace “root” with a user with sudo privileges or root if necessary. Additionally, replace “IP_Address” and “Port_Number” with your server’s respective IP address and SSH port number.<\/p>\n
We will use ‘root’ in this article when running the shell commands. If you want to use your regular user with sudo privileges to run the commands, make sure to append ‘sudo’ in front of the commands. Next, let’s make sure that we’re on Debian 11.<\/p>\n
# lsb_release -a<\/pre>\nYou should get this as the output:<\/p>\n
Distributor ID: Debian\r\nDescription: Debian GNU\/Linux 11 (bulleseye)\r\nRelease: 11\r\nCodename: bullseye<\/pre>\nThen, run the following command to make sure that all installed packages on the server are updated to their latest available versions:<\/p>\n
# apt update && apt upgrade<\/pre>\n<\/span>Step 2. Install and Configure Apache<\/span><\/h2>\nAccording to Moodle’s documentation about the server requirements, it supports Apache, Nginx, and IIS as the webserver. In this article, we will use Apache and we can install it directly from the default Debian repository.<\/p>\n
# apt install apache2 php<\/pre>\nOn Debian 11, apache will start running upon installation. Now, let’s create an apache virtual host for our Moodle website.<\/p>\n
# nano \/etc\/apache\/site-available\/moodle.yourdomain.com.conf<\/pre>\nThen insert the following into the file.<\/p>\n
<VirtualHost *:80>\r\nServerAdmin admin@moodle.yourdomain.com\r\nDocumentRoot \/var\/www\/html\/moodle\/\r\nServerName moodle.yourdomain.com\r\n\r\n<Directory \/var\/www\/html\/moodle\/>\r\nOptions +FollowSymlinks\r\nAllowOverride All\r\nRequire all granted\r\n<\/Directory>\r\n\r\nErrorLog ${APACHE_LOG_DIR}\/moodle.error.log\r\nCustomLog ${APACHE_LOG_DIR}\/moodle.access.log combined\r\n\r\n<\/VirtualHost><\/pre>\nSave the file then exit.<\/p>\n
Next, we need to enable the rewrite module and the new virtual host we created just now.<\/p>\n
# a2enmod rewrite\r\n# a2ensite moodle.yourdomain.com<\/pre>\nWe also need to edit the max_input_vars value.<\/p>\n
# nano \/etc\/php\/7.4\/apache2\/php.ini<\/pre>\nFind max_input_vars string then modify the value to 7000 or higher then uncomment it.<\/p>\n
max_input_vars = 7000<\/pre>\nLet’s restart apache for the changes to take effect.<\/p>\n
# systemctl restart apache2<\/pre>\n<\/span>Step 3. Install MariaDB<\/span><\/h2>\nMoodle requires a database server to store its data. It supports MySQL\/MariaDB, PostgreSQL, MSSQL, and Oracle; the latter is not recommended. In this step, we are going to install the MariaDB server from the default Debian repository. To install the MariaDB server, invoke this command:<\/p>\n
# apt install mariadb-server<\/pre>\nAfter the installation is completed, the MariaDB server will be automatically running. Now, we can proceed with creating a new database and database user.<\/p>\n
# mysql<\/pre>\nOnce logged in to the MySQL shell, we can run the following commands. You can replace m0d1fyth15 with a stronger password.<\/p>\n
mysql> CREATE DATABASE moodle_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;;\r\nmysql> CREATE USER moodle_user@'localhost' IDENTIFIED BY 'm0d1fyth15';\r\nmysql> GRANT ALL on moodle_db.* to moodle_user@localhost;\r\nmysql> FLUSH PRIVILEGES;\r\nmysql> \\q<\/pre>\n<\/span>Step 4. Install Additional Packages and Download Moodle<\/span><\/h2>\nThere are some additional software packages to install, and since we are going to use git to complete Moodle installation, we also need to install git first.<\/p>\n
# apt install git graphviz aspell ghostscript php7.4-{pspell,curl,gd,intl,mysql,xml,xmlrpc,ldap,zip,soap,mbstring}<\/pre>\nNow, we will set up a local repository and we can copy the moodle core files to our Moodle website’s document root later.<\/p>\n
With the local repository stored in \/opt (you may choose another directory outside the website’s document root), we will be able to prepare and stage any upgrades efficiently. For example, if we want to make changes or add some plug-ins, we can download the plugin and copy it to the local moodle repository we have. After adding the plugin and making any other changes, we would want to edit the file located in \/opt\/moodle\/.git\/info\/exclude, to tell git which files or directories to exclude when it pulls down the updates when we run the next “git pull” command.<\/p>\n
Let’s create a local repository in \/opt.<\/p>\n
# cd \/opt\r\n# git clone git:\/\/git.moodle.org\/moodle.git\r\n\r\n<\/pre>\nNow, let’s check the list to see the branches.<\/p>\n
# cd moodle\r\n# git branch -a<\/pre>\nWe are going to use the latest stable Moodle, so run this command below.<\/p>\n
# git branch --track MOODLE_400_STABLE origin\/MOODLE_400_STABLE<\/pre>\nDo not forget to checkout the Moodle version.<\/p>\n
# git checkout MOODLE_400_STABLE<\/pre>\nNext, we can copy the local repository to the domain’s document root we specified earlier when creating the apache virtual host.<\/p>\n
# cp -R \/opt\/moodle\/ \/var\/www\/html\/moodle\/<\/pre>\nWe would also need to create a Moodle data directory to store the data, make sure it’s created outside of the website’s document root then give the correct permission.<\/p>\n
# mkdir \/var\/www\/moodledata\r\n# chmod -R 777 \/var\/www\/moodledata\/\r\n# chown -R www-data. \/var\/www\/moodledata\/ \/var\/www\/html\/moodle\/<\/pre>\n