Moodle (Modular Object-Oriented Dynamic Learning Environment) is free and open source online learning management system which enables educators, schools, colleges to create their private website to teach multiple courses. Moodle is originally developed by Martin Dougiamas using PHP and it uses a database to store its data. Moodle is very popular and used by many educators all over the world for distance education and e-learning projects.
Although Moodle has uncountable features but few notable are.
- Responsive and easy to use interface, which can be totally customized.
- Easy multimedia integration, file management, simple but powerful text editor.
- Secure authentication and mass enrolment and progress tracking.
- Bulk course creation, easy backup and easy to manage user roles and permission.
- Hundred of Plugins and Themes to add more features and change layout.
- Built In collaborative features and detailed reportings and logs.
- Multilingual interface and regular security updates.
In this tutorial we are going to install latest version of Moodle which is Moodle 3.1 as of now on CentOS 7. Requirements for server are.
- Fresh installation of CentOS 7.x.
- Minimum 5GB of Disk Space.
- Minimum 1GHz Processor, recommended is 2GHz.
- Minimum 512MB RAM, recommended is 1GB or more.
In this tutorial we will be using
root account to run the commands, if you are logged in as non root user, use
sudo command at the start of the commands we are going to run except the queries we will be running in MariaDB prompt.
To install Moodle we will have to install LAMP stack first. LAMP is combination of Apache, MySQL and PHP. To install LAMP run the following command in terminal.
yum -y update yum -y install httpd mariadb mariadb-server php
The above commands will update the installed packages in your system and then it will install Apache web server, MariaDB server and PHP into your system. MariaDB server is a fork of MySQL and it can be used as an alternative to MySQL.
Now we will need to install the required PHP extensions by Moodle. Run the following command to install the required extensions.
yum -y install php-iconv php-mbstring php-curl php-openssl php-tokenizer php-xmlrpc php-soap php-ctype php-zip php-gd php-simplexml php-spl php-pcre php-dom php-xml php-intl php-json php-ldap php-mysql
To start Apache and MariaDB run the following command.
systemctl start httpd systemctl start mariadb
To automatically start Apache and MariaDB on system boot up, run the following commands.
systemctl enable httpd systemctl enable mariadb
To properly setup MariaDB for production environment you must run the following command to secure your MariaDB installation.
You will be asked to provide root password. As we've just installed MariaDB, and we haven't set the root password yet, the password will be blank, so just press enter to proceed further.
Enter current password for root (enter for none): OK, successfully used password, moving on...
Now you will be asked to setup root password to ensures that nobody can log into the MariaDB root user without the proper authorisation. You should not confuse
root password of MariaDB with the
root password of your server, both can be different.
Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. You will be asked if you wish to remove anonymous users. You should remove them before moving into a production environment.
Remove anonymous users? [Y/n] y ... Success!
Now you will be asked to disallow root login remotely. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y ... Success!
By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.
Remove test database and access to it? [Y/n] y Dropping test database... ... Success! Removing privileges on test database... ... Success!
Now you will be asked to reload the privilege tables. Reloading the privilege tables will ensure that all changes made so far will take effect immediately.
Reload privilege tables now? [Y/n] y ... Success!
Once done you will see following output at last.
Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Now that we have LAMP installed in our server, we can create a database to store Moodle's data.
Connect to MariaDB console by running the following command.
mysql -u root -p
You will be asked your root password, enter the password which we have created earlier. Once you are logged in to MariaDB, you will see that your terminal host has been changed to the following.
Now create a database to store your Moodle data using the the following query.
create database moodle_data;
You will see the following output, which shows that the MySQL query executed successfully.
Query OK, 1 row affected (0.00 sec)
Now create a new user, which will have full access to database using the following command.
create user 'moodle_user'@'localhost' identified by 'StrongPassword';
In this tutorial we have used
moodle_data as database, and
moodle_user as database user. You can choose any name for database and user. Replace
StrongPassword to a strong password for your database user.
Now you will need to grant the permissions to user to make various changes to your database. Run the following query to provide
moodle_user, all the permissions over
grant all privileges on moodle_data.* to 'moodle_user'@'localhost'; flush privileges;
To exit from MySQL prompt, run
Using Installer Package
Now that we have created the database to store Moodle data, we can now proceed further with installation. Go to the web root directory of Apache using the following command.
You can always go to Moodle releases page to get the most updated version of software. Download the Moodle package to your server using the following command.
Now extract the package using the following command.
tar -xvf moodle-latest-31.tgz
This will extract the files under a directory named
moodle. Run the following command to move the files to web root directory.
mv /var/www/html/moodle/* /var/www/html/
Now give ownership and appropriate permission to Apache web server to read and execute the files using the following command.
chown -R apache:apache /var/www/html chmod -R 755 /var/www/html
If you want you can also download the installation files using
git gives you flexibility to install any version of Moodle. You will be able to easily update the software using
To download Moodle using
git, you will need to install
git on your server, run the following command.
yum -y install git
Once the git is downloaded, run the following command the clone the software into your server.
cd /var/www/html git clone git://git.moodle.org/moodle.git
The first command will take you to your web root directory, and the next command will clone all the files of repository into your local server, under a directory named
cd moodle git branch -a
The first command will change the directory to the newly downloaded clone of Moodle repository. Next command will show you a list of all the available branches as shown below.
* master remotes/origin/HEAD -> origin/master remotes/origin/MOODLE_13_STABLE remotes/origin/MOODLE_14_STABLE remotes/origin/MOODLE_15_STABLE remotes/origin/MOODLE_16_STABLE remotes/origin/MOODLE_17_STABLE remotes/origin/MOODLE_18_STABLE remotes/origin/MOODLE_19_STABLE remotes/origin/MOODLE_20_STABLE remotes/origin/MOODLE_21_STABLE remotes/origin/MOODLE_22_STABLE remotes/origin/MOODLE_23_STABLE remotes/origin/MOODLE_24_STABLE remotes/origin/MOODLE_25_STABLE remotes/origin/MOODLE_26_STABLE remotes/origin/MOODLE_27_STABLE remotes/origin/MOODLE_28_STABLE remotes/origin/MOODLE_29_STABLE remotes/origin/MOODLE_30_STABLE remotes/origin/MOODLE_31_STABLE remotes/origin/master
As we can see above that the latest version available is Moodle 3.1, Now we will create a new local branch called MOODLE_31_STABLE and set it to track the remote branch MOODLE_31_STABLE from the upstream repository using the following command.
git branch --track MOODLE_31_STABLE origin/MOODLE_31_STABLE
We can now switch to our newly created local repository using the following command.
git checkout MOODLE_31_STABLE
Now we have our files ready for installation, but it is under the directory named
moodle. We will now move all the files to the web root directory using the following command.
mv /var/www/html/moodle/* /var/www/html/
Finally we will need to give the ownership and appropriate permission of Moodle installation directory to Apache using the following command.
chown -R apache:apache /var/www/html chmod -R 755 /var/www/html
You can always update the Moodle installation using the following command.
No matter which method you choose to download the files, installation is same for Moodle from this point.
Now you will need to create a data directory for Moodle in which Moodle will store it's data files, it is recommended to make this directory out of publicly accessible directories.
Change the ownership and permission of the directory to give permissions to Apache using the following command.
chown -R apache:apache /var/www/moodledata chmod -R 755 /var/www/moodledata
Now restart Apache so that changes can take effect immediately.
systemctl restart httpd.service
Now create Moodle configuration file by copying
config-dist.php file to
config-dist.php using the following command.
cp /var/www/html/config-dist.php /var/www/html/config.php
Now edit the configuration file using your favorite text editor, we will be using
nano in this tutorial. You can also use
vim or if you don't have nano installed, you can execute
yum -y install nano to install nano editor.
In configuration file, scroll down to find database settings.
$CFG->dbtype = 'pgsql'; // 'pgsql', 'mariadb', 'mysqli', 'mssql', 'sqls$ $CFG->dblibrary = 'native'; // 'native' only at the moment $CFG->dbhost = 'localhost'; // eg 'localhost' or 'db.isp.com' or IP $CFG->dbname = 'moodle'; // database name, eg moodle $CFG->dbuser = 'username'; // your database username $CFG->dbpass = 'password'; // your database password $CFG->prefix = 'mdl_'; // prefix to use for all table names
$CFG->dbname, put the name of database which we have created earlier. In
$CFG->dbuser, enter username of the database user which we have created earlier, in
$CFG->dbpass, enter the password of the user. After changing the values, it should look like this.
$CFG->dbtype = 'mariadb'; // 'pgsql', 'mariadb', 'mysqli', 'mssql', 'sq$ $CFG->dblibrary = 'native'; // 'native' only at the moment $CFG->dbhost = 'localhost'; // eg 'localhost' or 'db.isp.com' or IP $CFG->dbname = 'moodle_data'; // database name, eg moodle $CFG->dbuser = 'moodle_user'; // your database username $CFG->dbpass = 'StrongPassword'; // your database password $CFG->prefix = 'mdl_'; // prefix to use for all table names
Go further down on the configuration file and you will find Website Location configuration. Edit
$CFG->wwwroot value and insert your domain name. If you don't have your domain setup, you can also use the IP address of your server instead of domain name.
$CFG->wwwroot = 'http://your-domain.com';
$CFG->wwwroot = 'http://Your-Server-IP';
Next you will find Data File location settings, find
$CFG->dataroot replace the path with the path of the directory which we have created earlier to save the data.
$CFG->dataroot = '/var/www/moodledata';
Next you can choose the alias for your Moodle Administrative login. By default it's
admin, but you may also change it to something more secure like,
mymoodleadmin2. Once done making changes, write out the file and exit from editor.
Finally start web installer for Moodle by going to any of the following URL through your favorite browser.
If you enter your server IP, you will probably be redirected to the website address you entered in configuration file, hence make sure that the domain is pointing towards your server, if you put your domain name as Website location in configuration file. You will see a similar page when accessing your website.
Accept the terms and conditions by clicking Continue button.
Now you will be shown a huge list of server requirements, scroll down to see a message, it will let you know if Moodle can be installed in your server or not.
Click Continue button to proceed further, installer will now start building tables and you should see a lot of success messages. Click Continue button.
In this interface you will need to provide administrative username, email and password. Click on Update profile button.
Now you will be asked to provide a Title and short title for your website, Enter the message you wish to display on front page, choose the time zone and choose the option for self registration. If you allow self registration then any student will be able to register himself into the site, otherwise only administrator and educators will be able to create students account. Click Save changes button and you will see the admin dashboard.
Moodle is now installed in your server.
In this tutorial have learnt to install latest version of Moodle in to CentOS 7.x server. You can now successfully download and install Moodle using both the methods, which are either using compressed installer package available on official site of Moodle or using the official
git repository of Moodle.