Installing Moodle on Debian based distributions
Installing Moodle as a Debian package
Moodle used to be included as a Debian package. However, it has not been included in recent releases. There is talk of it being included again in the Jesse release but now, follow the instructions below to install Moodle on Debian.
Installing moodle from .tgz(.tar.gz) or .zip file
Step 1: Install required packages
After installing your Debian distro, install these packages (if you've not already done so). See Installing Apache, MySQL and PHP or refer to the respective user manuals. Using apt-get, aptitude or synaptic you can install these very easily.
- Web Server (Apache highly recommended)
- Database Server (MySQL or PostgreSQL recommended)
- PHP, PHP-MySQL mod (or mod for your database)
- Various PHP modules necessary for Moodle
LAMP in Debian
Setting up a LAMP in Debian is very easy. Once you get used to Debian administration including installation and configuration are much simpler compared to other linux distros. The following describes how to install apache, php and mysql on the Debian distribution.
For installation of the necessary packages the easiest option to use apt-get through the command line interface. Debian has easy access to a Root Terminal
Use the following command to install apache2, php5 and mysql
apt-get install apache2 php5 mysql-server php5-mysql libapache2-mod-php5 php5-gd php5-curl php5-xmlrpc php5-intl
The mentioned packages are installed along with the dependencies depending on what was already installed on your Debian system.
Now you may fire up a browser and type localhost to check whether the apache2 default page is shown,
If you are familiar with apache settings, you can edit the apache configuration files using the text editor gedit or nano by typing:
However, for a basic install, you should not need to mess with this file.
Now we must make a few changes in the php5 configuration file. Open it using
add the entries
Sometimes these entries are provided as example lines being commented out . You can remove the commenting to activate the entries. Then make the following changes (adjust to your preference) This will allocated more memory and allow files to be uploaded up to 80MB. This should be enough for most multi-media files. Hard drive space is cheap and the default is only 2MB. It is recommended that you change the settings to the following values:
memory_limit = 40M post_max_size = 80M upload_max_filesize = 80M
To test the php installation, you can create a text file named phpinfo.php with the contents <?phpinfo()?> and save it at /var/www. Restart apache with the command below. Now access this file through the browser localhost/phpinfo to check the installation of php.
You can restart apache 2 by
Step 2: Setup MySQL Database
Set a secure root password for the database (you might have already done this in the initial install process)
mysqladmin -u root password "mySecurePassword"
Note that on a secure production server, you will want to create a different user than root to access the database.
Now log in
mysql -u root -p
Enter your password
Create the Moodle database
mysql> CREATE DATABASE moodle;
Then ensure that the database is set to UTF8 which is required by later distributions of Moodle
mysql> ALTER DATABASE moodle charset=utf8;
Then exit the database
You can restart mysql by
Step 3: Download moodle
Download moodle from http://download.moodle.org/?lang=en.
Step 4: Unpack file
- For zip file, use unzip <your_file>. For tgz(tar.gz), use tar -zxvf <your-file>. You can also use any of the GUI front-ends such as file-roller or ark or just let Debian unzip it with Archive Manager. You will get a folder moodle (or moodle-2.8.1 or something similar). It will probably be located in your Downloads folder unless you told the Archive Manager or the Download utility to save it somewhere else. We will presume it is in your Download folder.
From terminal type
mv moodle /var/www
You can also copy instead of moving it in case you want a backup of the code on your machine.
cp -R moodle /var/www
You will probably need to do this as root (no problem if you are using the Root Terminal!)
Step 5: Create a data directory and set Moodle directory permissions
Switch to the correct directory
Create a directory for user and course files
Set ownership and permissions so that Apache can access the files
chown -R www-data:www-data moodle chown -R www-data:www-data moodledata
chmod -R 755 moodle
chmod -R 755 moodledata
On a production server, you may want to tighten up privileges.
Step 6: Change Apache to use Moodle as the web site
Note that the server comes with Apache running and looking at the /var/www directory. But there is nothing in that folder, so one just gets a redirect. Edit as follows to have it point at Moodle instead:
gedit /etc/apache2/sites-available/default or
On about line 4, change DocumentRoot "/var/www" to
On about line 10, change <Directory "/var/www/"> to
Around line 17, comment out the line for the default page:
# RedirectMatch ^/$ /apache2-default/
You can change other values like ServerAdmin if appropriate. For all changes, you should restart Apache for the new settings to take effect.
Step 7: Finally install
- Go to http://localhost/moodle and follow the instructions.
Step 8: Setup Moodle
If you are only going to test Moodle on your internal network, just enter the local IP address as the web address. You can find the local IP address under DHCP by typing
If you have a web address that points to your server, use that instead.
From a browser on another machine, enter
http:// ----- your web address -----
- For the database user, enter root
- For Password, enter the password for the database that you created earlier
Continue through the dialogs until installed.
Moodle needs a periodic call to do maintenance work like sending out emails, cleaning up the database, updating feeds, etc. To run the cron every 10 minutes, do the following
crontab -u www-data -e
Add this line and save.
*/10 * * * * /usr/bin/php /var/www/moodle/admin/cli/cron.php >/dev/null
Use CNTL-X to save