Installing a Ubuntu Server for Moodle

I have written this post, not as a replacement for the very good documentation that is available over on the Moodle Docs site, but as a way for myself to refer back to the process I carry out when installing Moodle.

I am using Ubuntu Server 14.04 for my operating system, so these steps will specific to that distribution. They may well translate into Debian without any editing but I have not tested that. If you are using a different operating system then your steps will vary somewhat.

The reason for choosing Ubuntu 14.04 for my OS is not only that it is the latest LTS version of Ubuntu, but also that it comes with PHP version 5.5.9 in it’s package repository. Ubuntu 12.04 only comes with PHP version 5.3.10. In PHP version 5.4 support for LDAP Paged results was introduced which means that if you have more than 1000 users in any of your MS AD LDAP containers PHP will be able to retrieve them all.

Set up your LAMP Server ready for Moodle

  1. Install Ubuntu Server 14.04
  2. Select language and keymap
  3. Detect keyboard layout
  4. If required configure your network with a static IP address
  5. Choose user name and password for your server
  6. Choose if you want your homedrive encrypted
  7. Select correct timezone
  8. Partitioning – Chose what fits your server best (For testing just go with “Guided – use entire disk”)
  9. Select which disk
  10. Check changes to partition table and accept
  11. Enter proxy information if required
  12. Select your upgrade option
  13. At “Software Selection” window, tab to continue without highlighting any selection
  14. Say “Yes” to install GRUB to MBR
  15. Select “Continue” when installation completes
  16. When server reboots log in with user name and password you defined in step 5
  17. sudo apt-get update
  18. sudo apt-get dist-upgrade
  19. sudo reboot
  20. When server reboots log in with user name and password you defined in step 5
  21. sudo apt-get install ssh molly-guard

Now we can do the rest through Putty or which ever ssh client you are using!

  1. Install Apache2 and PHP5 and required extensions:
    sudo apt-get install php5-gd php5-curl php5-intl php5-xmlrpc php5 mysql-server mysql-client apache2 php5-mysql php5-json php5-ldap
  2. When prompted enter a strong password for the MySQL Server’s root account and record it somewhere safe!
  3. Create a PHP Info page as follows:
    1. Type:
      sudo nano /var/www/info.php
    2. Type:
      <?php phpinfo(); ?>
    3. Press Ctrl + O, Enter then Ctrl + X to save and quit nano
  4. Visit http://yourservername/info.php and check that Apache and PHP are running
  5. Check that all the PHP extensions listed here: are loaded in your PHP info page

Install Moodle

So now we have a LAMP server configured ready for Moodle; it is time to get Moodle installed. I will briefly list the install steps I am carrying out for the Moodle set up, but the official Moodle docs should always be your first port of call!

  1. Head over to and click the “Download tgz” link location for the latest version (at the time of writing this Moodle 2.7.2+)
  2. When the download starts, cancel the download and copy the link location for the “click here to download manually” link.
  3. Start and SSH session to your Moodle server and type (replacing the download link with what you copied in step 2):
    sudo -s
    cd ~
  4. Now we are going to download the MD5 hash to check we have a good download. Back on the Moodle download page, copy the location of the “MD5” link directly under the “Download tgz” link you clicked in step 1
  5. Back on your SSH session type the following (replacing the link with what you copied in step 3!):
    md5sum -c moodle-latest-27.tgz.md5
  6. If the md5sum command does not return “OK”, your download was incomplete; try again!
  7. Extract the tgz file as follows (you may want to change the output directory depending on your setup):
    tar zxvf moodle-latest-27.tgz -C /var/www/html
  8. Secure the files so that the web server user can not write them:
    chown -R root /var/www/html/moodle
    chmod -R 0755 /var/www/html/moodle
    find /var/www/html/moodle -type f -exec chmod 0644 {} \;
  9. Now we need to create our database for Moodle. Type the following on your server (watch out for line breaks and replace “yourpassword” with a strong password which you record securely; you will need it soon!):
    mysql -u root -p
    mysql> CREATE DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
    mysql> exit
  10. Now we need to create the data directory where Moodle will store all the files uploaded to it. This MUST be outside the web root and not accessible from the Internet. Type the following:
    mkdir /var/www/moodledata
    chmod 0777 /var/www/moodledata
  11. Now we can start the Moodle install! Visit http://yourserver/moodle to begin the installation.
  12. Follow the steps in your web browser ensuring the path to the data directory is correct
  13. When prompted for your database details enter them as you set them up in step 9. You can leave “Database port” and “Unix socket” empty
  14. Copy the provided PHP code for the configuration file and then back on your SSH session type the following:
    nano /var/www/html/moodle/config.php
    (Paste the code copied from the web browser at this point. If you are using Putty for your SSH session just right click to paste)
    "Ctrl + O"
    "Ctrl + X"
  15. Back on your web browser click the “Next >>” button
  16. Click through the license, server checks and remaining installation pages until you are presented with the admin user configuration page. Set a password and email address for your admin user and click “Update profile” (make sure you have recorded this password too!)
  17. Give your site a name, short name and summary and click “Save changes”

You now have a basic Moodle install running, all you need to do now is configure your LDAP settings email and probably a whole lot more! Happy Moodling 😉

2 thoughts on “Installing a Ubuntu Server for Moodle

Leave a Reply

Your email address will not be published. Required fields are marked *