Moodle is a popular and open-source web-based learning management system (LMS) that is free for anyone to install and use. With Moodle, you can create and deliver learning resources such as courses, readings, and discussion boards to groups of learners. Moodle also allows you to manage user roles, so students and instructors can have different levels of access to materials. Once you install Moodle on your web server, anyone with access to your site can create and participate in browser-based learning.
In this guide, you will install and set up Moodle on your Ubuntu 16.04 server. You’ll install and configure all the software required by Moodle, run through the setup wizard, choose a theme, and create your first course.
Before you begin this guide you’ll need the following:
Moodle relies on a few pieces of software, including a spell-checking library and a graphing library. Moodle is a PHP application, and it has a few additional PHP library dependencies as well. Before we install Moodle, let’s install all of the prerequisite libraries using the package manager. First, ensure you have the latest list of packages:
- sudo apt-get update
Then install Moodle’s dependencies:
- sudo apt-get install aspell graphviz php7.0-curl php7.0-gd php7.0-intl php7.0-ldap php7.0-mysql php7.0-pspell php7.0-xml php7.0-xmlrpc php7.0-zip
Next, restart the Apache web server to load the modules you just installed:
- sudo systemctl restart apache2
Now we are ready to download and install Moodle itself. We’ll use curl
to download Moodle from the official distribution server.
The following command will go to the Moodle website and get the compressed package that contains the entire current, stable version of Moodle into the file moodle.tgz
. The -L
flag tells curl
to follow redirects.
- curl -L https://download.moodle.org/download.php/direct/stable32/moodle-latest-32.tgz > moodle.tgz
Now we can uncompress the file with the tar
program and place the resulting files in the web document root:
- sudo tar -xvzf moodle.tgz -C /var/www/html
Verify that the moodle
directory is in your server’s web root directory:
- ls /var/www/html
You should see the moodle
directory listed:
Outputindex.html moodle
Now view the files within the moodle
directory:
- ls /var/www/html/moodle
You will see all of the Moodle files and directories you just downloaded and uncompressed:
Outputadmin composer.json grade message README.txt
auth composer.lock group mnet report
availability config-dist.php Gruntfile.js mod repository
backup config.php help_ajax.php my rss
badges CONTRIBUTING.txt help.php notes search
behat.yml.dist COPYING.txt index.php npm-shrinkwrap.json tag
blocks course install package.json tags.txt
blog dataformat install.php phpunit.xml.dist theme
brokenfile.php draftfile.php INSTALL.txt pix TRADEMARK.txt
cache enrol iplookup plagiarism user
calendar error lang pluginfile.php userpix
cohort file.php lib portfolio version.php
comment files local PULL_REQUEST_TEMPLATE.txt webservice
competency filter login question
completion githash.php media rating
Now we need to create a directory outside the web root for Moodle to store all the course-related data that will be stored on the server, but not in the database. It is more secure to create this directory outside the web root so that it cannot be accessed directly from a browser. Execute this command:
- sudo mkdir /var/moodledata
Then set its ownership to make sure that the web service user www-data
can access the directory:
- sudo chown -R www-data /var/moodledata
Then change the permissions on the folder so that only the owner has full permissions:
- sudo chmod -R 0770 /var/moodledata
Now that you’ve got Moodle on your server, it’s time to set up the database it’ll use.
We need to create the MySQL database where Moodle will store most of its data. We’ll create the structure that the Moodle code expects, and we’ll create a user that Moodle will use to connect to the database.
But first we need to make a few changes to the MySQL configuration file in order our MySQL installation to be compatible with Moodle. Open the MySQL configuration file:
- sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Then add the following highlighted lines to the ‘Basic Settings’ area, which configure the storage type that new databases should use:
...
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
default_storage_engine = innodb
innodb_file_per_table = 1
innodb_file_format = Barracuda
## Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
...
Save this file and then restart the MySQL server to reload the configuration with the new settings.
- sudo systemctl restart mysql
Now we can create the Moodle database. In order to do this, you’ll interact with the MySQL command-line interface. Execute this command:
- mysql -u root -p
When prompted, supply the root password you set when you installed MySQL.
Once logged in, you’ll see the mysql>
prompt. Run the following command to create the database:
- CREATE DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Then create a Moodle user, so we don’t have to tell the Moodle application what our root password is. Execute this command:
Note: In the next two commands, replace moodler
with your Moodle username and moodlerpassword
with a chosen password.
- create user 'moodler'@'localhost' IDENTIFIED BY 'moodlerpassword';
And give the moodler
user permission to edit the database. This user will need to create tables and change permissions:
- GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO 'moodler'@'localhost' IDENTIFIED BY 'moodlerpassword';
Now exit the MqSQL command-line interface:
- quit;
That takes care of the database configuration. Now we can launch Moodle in a browser and continue the setup there.
To finish configuring Moodle, we’ll bring up the site in a web browser and provide it with some additional configuration details. In order for the web server to save the configuration, we need to temporarily alter the permission for the Moodle web root.
Warning: The permissions open this folder up to everyone. If you are uncomfortable with doing this, simply don’t change the permission. The web interface will provide instructions for you to manually modify the configuration file.
If you do change the permissions, it is very important to undo this as soon as you have completed the setup. That step is included in this tutorial.
- sudo chmod -R 777 /var/www/html/moodle
Now open up a browser and go to http://your_server_ip/moodle
. You’ll see a page like the following.
Follow these steps to configure Moodle:
/var/moodledata
and click Next.Once you’ve done this. you’ll be taken to the dashboard of your new Moodle installation, logged in as the admin user.
Now that your setup is complete, it’s important to restrict permissions to the Moodle web root again. Back in your terminal, execute the following command:
- sudo chmod -R 0755 /var/www/html/moodle
Let’s make one more minor change to improve Moodle’s security. By default, Moodle creates files in the /var/moodledata
folder with world-writeable permissions. Let’s tighten that up by changing the default permissions Moodle uses.
Open the Moodle configuration file in your editor:
- sudo nano /var/www/html/moodle/config.php
Locate this line:
$CFG->directorypermissions = 0777;
Change it to the following:
$CFG->directorypermissions = 0770;
Then save the file and exit the editor.
Finally, reset the permissions on the /var/moodledata
directory itself, as Moodle already created some world-writeable folders and during the installation process:
- sudo chmod -R 0770 /var/moodledata
Now that Moodle is configured, let’s make a few customizations and create a test course to get a feel for the Moodle web interface.
Now that your site is running, one of the first things you night want to do is register your Moodle site. This will subscribe you to the Moodle mailing list which will keep you up to date about things like security alerts and new releases.
To register, click the Site Administration link in the box on the left, and click on Registration. Then fill out the web form with the appropriate details. You can also choose to publish your Moodle site so others can find it.
Next, let’s change the theme for our Moodle site. Select Site Administration, select the Appearance tab, and select Theme selector. You will see a page that looks like the following figure, indicating that you’re currently using the “Boost” theme on the Default device, which refers to a modern web browser:
Click the Change theme button and you’ll be taken to a screen that shows you other available themes. When you click on the Use theme button under a theme name, your Moodle site will use that theme to display all of your site’s content. You can also choose different themes for different devices, like tablets or phones.
Now that you’ve got your Moodle site closer to how you want it to look, it’s time to create your first course. Select Site home from the navigation menu. You’ll see an empty list of courses and an Add a new course button. Click that button to display a form that looks like the following figure:
Fill in the information about your course, including the name, short name, a description, and any other relevant details. Then scroll to the bottom and click Save and display.
Your first Moodle course is now ready to go. You can start adding lessons and activities to the course using Moodle’s interface.
But before you start letting people sign up to take your new course, you should ensure your Moodle installation is ready for production. For starters, you’ll want to set up a TSL/SSL certificate for Apache to encrypt the traffic between your server and clients. To do that, follow the tutorial How To Secure Apache with Let’s Encrypt on Ubuntu 16.04. And to make sure your data is protected, ensure that you back up your MySQL database periodically. You should also back up the files on the server, including the /var/moodledata/
folder. The tutorial How To Choose an Effective Backup Strategy for your VPS offers suggestions for backing up files.
In this article you installed and set up Moodle on an Ubuntu 16.04 server. Moodle is a robust and highly configurable web application. Be sure to consult the Moodle documentation and get in touch with the worldwide community of Moodle users and administrators for ideas about how to make the most of it. Happy Moodling!
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
If you find a problem with installing Moodle dependencies especially for this command:
Check out this URL: https://newbedev.com/shell-e-package-php7-0-curl-has-no-installation-candidate-code-example
buenas , ando termino de instalar moodle y cuando quiero hacer unos cambios me sale que version de mysql requiero es este sin embargo ando usando una mas recien al igual con lo mismo el php unas extensiones y podido insltar y activar pero al final no puedo avanzar
Gracias me funciono perfecto, Saludos!
elearning
Great tutorial! It is really helpful! I have a question. I made the entire site in Moodle, with the purchased theme. But, how to upgrade Moodle installation safely? I currently have version 3.2, but I would like to upgrade to the latest, 3.5.2. P.s. I did not install any additional plugin, except the theme. Thanks in advance!
Excelent tutorial, I just like to mention two things, the first one is in the Moodle documentation said to use utf8mb4 instead utf8, so the script to create a database should be.
And the second one is about cron. It’s important configurate the cron script. For more details: https://docs.moodle.org/34/en/Cron
Thanks for this! You might wanna add “installing Postfix” as a prerequisite so the PHP Mailer can be used.
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-16-04
Cheers!
Great tutorial thank you. However, I can’t get past the configure database part. I return the following message: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’ IDENTIFIED BY ‘my_password’
Would greatly appreciate any guidance you may have. Thanks!
A lot of thanks.
I followed the steps and am now able to access the Moodle directly from the IP Address. However, using the domain it does not point there, though I configured the domain to point to this IP. All it shows is the default message of Apache being installed. Is there any site on moodle I could try to access via the domain, to see if it works?
Great tutorial! Thanks!
Please pardon typos and the hasty skeletal run-through below… in a rush as usual…
I started with the one-click LAMP 16.04 droplet:
512 MB / 20 GB Disk + 1 GB / SFO2 - Ubuntu LAMP on 16.04
then I added a domain “example.com” from namecheap.com to get:
http://example.com
then created sudo user “sammy”
then modified php.ini
sudo nano /etc/php/7.0/apache2/php.ini
to increase execution time and script memory from defaults 30 and 128 to:
max_execution_time = 300
memory_limit = 384M
(only have 512MB on my droplet, I would go higher than 384 on a 2GB server)
sudo a2enmod rewrite
sudo service apache2 restart
sudo apt-get update
sudo apt-get install aspell graphviz php7.0-curl php7.0-gd php7.0-intl php7.0-ldap php7.0-mysql php7.0-pspell php7.0-xml php7.0-xmlrpc php7.0-zip php7.0-mbstring
sudo systemctl restart apache2
sudo cat /root/.digitalocean_password
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04
https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-16-04
follow the tutorial below but use the https accessible domain that you have created:
https://www.digitalocean.com/community/tutorials/how-to-install-moodle-on-ubuntu-16-04
Done!
Works!