Setup Moodle on Ubuntu Tutorial

I have done several Moodle installs on RedHat, CentOS, and Ubuntu Server. By far I like Ubuntu the most. Ubuntu Server is simple to setup and use, plus it is a much lighter weight server then the others and boots much faster. I also usually have fewer issues with setting up Moodle on Ubuntu. Don’t get me wrong RedHat and CentOS (which are the same thing) are great operating systems and are not difficult either, it is just hard to beat Ubuntu.

This tutorial may seem long and difficult but don’t get discouraged. It is a lot more simple then is seems.  I have included all the Ubuntu Server commands you should need.  At the end of this post I have included some Linux commands that I have found useful when using Ubuntu Server. A note about Ubuntu, often you need to run a command as root or administrator. This is knows as the super user and is accomplished by prefixing the command with sudo. Example: sudo apt-get install package

Here are the overall steps you need. Look below for the details on each step.

  1. Setup a  LAMP server (Linux, Apache, MySQL, PHP server)
  2. Setup a database in MySQL
  3. Upload the Moodle package and install it

Setup a LAMP Server – Vanilla install of Ubuntu with Apache, MySQL, PHP

Start with the Ubuntu Install on a virtual machine

  • Start Installing Ubuntu Server and follow the prompts
  • Write down username and password and login
  • Install VMware Tools
    sudo apt-get install open-vm-tools
  • Install Apache, MySQL and PHP
    sudo apt-get install tasksel
    sudo tasksel install lamp-server
    Write down the username and password you choose for MySQL
  • Install SSH for remote administration
    sudo apt-get install openssh-server
  • Install and setup vsftpd (https://help.ubuntu.com/10.04/serverguide/ftp-server.html)
    sudo apt-get install vsftpd
    sudo nano /etc/vsftpd.conf
    • local_enable=YES
    • write_enable=YES

sudo /etc/init.d/vsftpd restart

  • Install text/image tools:
    • sudo apt-get install latex (use texlive instead)
    • sudo apt-get install ghostscript
    • sudo apt-get install convert
    • sudo apt-get install dvips
    • o    sudo apt-get install texlive-full
    • sudo apt-get install imagemagick
    • sudo apt-get install mimetex
    • Install various PHP extentions:
      • sudo apt-get install php5-ldap
      • sudo apt-get install php5-curl
      • sudo apt-get install php5-ldap
      • sudo apt-get install php5-gd
      • sudo apt-get install php5-intl
      • sudo apt-get install php5-xmlrpc
      • sudo /etc/init.d/apache2 restart
      • Optional Install Clam Antivirus: sudo apt-get install clamav
      • Optional Install Spell Checker: sudo apt-get install unzip zip aspell-en aspell-fr aspell-de aspell-es

Setup a Database in MySQL

You now need a database for moodle to save data to. You installed the MySQL service in the pervious steps but you might not have creaed a database for the data to be saved in yet. If this MySQL installations is only holding Moodle data then you can just use the same username and password for the moodle database as the MySQL administrator otherwise it is a good security idea to create seporate users for each database MySQL will be hosting. Please that once you login to MySQL all  statements will need to end with a ;

Login to MySQL (skip the second setp if only one database administor will be used)

  • Optional change the password (only needed if you didn’t set a good password during install)
    • mysqladmin -u root password yourownpassword
    • mysqladmin -u root -h localhost password yourownpassword
    • Optional create a separate user and create the permissions for that users for the moodle database using the using the set permissions script Type:  mysql_setpermission and follow the prompts to create a new users and assign them permissions on the moodle database.
    • Login to MySQL as the administrator:
    • mysql -u root –p
      type in the password
    • Create a database for Moodle to use: CREATE DATABASE moodle Default Character Set;
    • Logout of MySQL: exit;

 

Upload The Moodle Package and Install It

Moodle needs to folders:  “moodledata” and “moodle”
The “moodle” holds the actual moodle files that actually run moodle. This folder will need to be in a place accessible by the internet.
The “moodledata’ holds user files and temp files and needs read, write, execute permissions. This folder should not be accessible by the internet directly.
The “moodle” needs read and execute to run Moodle but during the install it will need write access as well because it creates a config.php file. You can create and set permissions in two ways, either via the command line in Ubuntu or via an FTP client program.

  • Option 1 – Use FTP to create and set permissions of the Moodle folders
    • FTP to the server and navigate to the web directory usually: /var
    • create the directory: /var/moodledata  and  /var/www/moodle
    • use your FTP client to change the permissions for the two folders to 777
    • Option 2 – Use Ubuntu command line to create and set permissions of the Moodle folders
      • mkdir -p /var/www/moodle
      • chmod -R 777 /var/www/moodle
      • mkdir -p /var/moodledata
      • chmod -R 777 /var/moodledata

Now you need to upload the moodle files and install Moodle.

  • Download the Moodle package from moodle.org and unzip/extract the package
  • Use your FTP client to upload the moodle package to your newly created moodle directory.
  • You should have already set up the domain name or IP address you will be using to access Moodle and it should point to your Ubuntu server. This will be the IP address or domain name everyone will be using to access Moodle.
    • http://192.168.1.10/moodle or  http://mydomain.com/moodle
    • It will ask you for the language of your choice. Choose EN for English
    • Now it will ask you for the installation settings of your server.
      • Data folder will be: /var/moodledata
      • Database Type: MySQL
      • Database will be: moodle
      • Database User: use the username you used for your MySQL database
      • Database Password: password you used for your MySQL database
      • Table Prefix can be anything as long as no other program will be using it in your database. If your database is only used for Moodle you can call it anything. I use mdl_
  • If the moodle directory has write access the installation will write the config.php file there using the settings you just chose. If not you will need to create the file by copying the code Moodle provides during the install and uploading it in a file called config.php to your moodle directory.
  • You should be good to go at this point. Just follow the prompts and set the settings what work for your environment. If you are unsure the default settings usually are a good start.

 

Other Useful Linux Ubuntu commands:

  • Reboot Server: sudo shutdown -r now
  • Shutdown Server: sudo shutdown -h now
  • To install a package: sudo apt-get install PackageName
  • To uninstall a package: sudo apt-get remove PackageName
  • To update package indes: sudo apt-get update
  • To update installed packages: sudo apt-get upgrade
  • To update Ubuntu to the latest distro: sudo apt-get dist-upgrade
  • To delete a directory and all subfolders and files: rm -rf DirectoryName
  • Make a copy of moodledata directory for a backup before updateing
    • mkdir moodledata_backup
    • cp -r /var/www/moodledata/* /var/www/moodledata_backup
  • Restart Apache: /etc/init.d/httpd restart
  •  Start vsftpd: /sbin/service vsftpd start
  •  Stop vsftpd: /sbin/service vsftpd stop
  • Restart vsftpd: /sbin/service vsftpd restart
  • MySQL Backup: mysqldump -u root -p -C -Q -e -a moodle > moodle-backup.sql
  • MySQL Restore: mysql -u root -p moodle < moodle-backup.sql

 

This entry was posted in Computers & Technology, Uncategorized. Bookmark the permalink.