• Get In Touch
July 3, 2016

How to Install Moodle on CentOS 7

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

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.

Requirements

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.

Installing Moodle

Installing LAMP

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.

    mysql_secure_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!

Creating Database

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.

    MariaDB [(none)]>

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 moodle_data.

    grant all privileges on moodle_data.* to 'moodle_user'@'localhost';
    flush privileges;

To exit from MySQL prompt, run exit command.

Downloading Moodle

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.

    cd /var/www/html

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.

    wget https://download.moodle.org/download.php/direct/stable31/moodle-latest-31.tgz

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
Using git

If you want you can also download the installation files using git. git gives you flexibility to install any version of Moodle. You will be able to easily update the software using git.

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 moodle.

    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.

    git pull

No matter which method you choose to download the files, installation is same for Moodle from this point.

Installing Moodle

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.

    mkdir /var/www/moodledata

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.

    nano /var/www/html/config.php

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

In database $CFG->dbtype change pgsql to mariadb. In $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';

or

    $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.

    http://Your-Server-IP
    http://your-domain.com

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.

HP_NO_IMG/data/uploads/users/2a78e75d-343a-47ce-9d84-14a6ba54abbc/361129004.png” alt=”” />

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.

HP_NO_IMG/data/uploads/users/2a78e75d-343a-47ce-9d84-14a6ba54abbc/657129919.png” alt=”” />

Click Continue button to proceed further, installer will now start building tables and you should see a lot of success messages. Click Continue button.

HP_NO_IMG/data/uploads/users/2a78e75d-343a-47ce-9d84-14a6ba54abbc/1370170277.png” alt=”” />

In this interface you will need to provide administrative username, email and password. Click on Update profile button.

HP_NO_IMG/data/uploads/users/2a78e75d-343a-47ce-9d84-14a6ba54abbc/606192843.png” alt=”” />

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.

HP_NO_IMG/data/uploads/users/2a78e75d-343a-47ce-9d84-14a6ba54abbc/342364618.png” alt=”” />

Moodle is now installed in your server.

Conclusion

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.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]