Moodle Docs: Installation

## Installing Moodle

This guide explains how to install Moodle for the first time. It goes into some detail about some of the steps, in order to cover the wide variety of small differences between web server setups, so this document may look long and complicated. Don't be put off by this - I usually set Moodle up in a few minutes!

Take your time and work through this document carefully - it will save you time later on.

Sections in this document:

1. Requirements
2. Download
3. Site structure
4. Create a data directory
5. Create a database
6. Check web server settings
7. Edit config.php
8. Go to the admin page
9. Set up cron
10. Create a new course

### 1. Requirements

> Moodle is primarily developed in Linux using Apache, MySQL and PHP (also sometimes known as the LAMP platform), but is also regularly tested with PostgreSQL and on Windows XP, Mac OS X and Netware 6 operating systems

> The requirements for Moodle are as follows:

> 1. Web server software. Most people use Apache, but Moodle should work fine under any web server that supports PHP, such as IIS on Windows platforms.
> 2. PHP scripting language (version 4.1.0 or later), with the following settings:
>    - GD library turned ON, with support for JPG and PNG formats
>    - zlib library turned ON (if you want to use backup/restore on Windows)
>    - Sessions support turned ON
>    - File uploading turned ON
>    - Safe Mode must be turned OFF (see the forums on moodle.org for problems caused by Safe Mode)
> 3. a working database server: MySQL or PostgreSQL are completely supported and recommended for use with Moodle 1.1. All other databases will be supported fully in the next release.

> Most web hosts support all of this by default. If you are signed up with one of the few webhosts that does not support these features ask them why, and consider taking your business elsewhere.

> If you want to run Moodle on your own computer and all this looks a bit daunting, then please see our guide: Installing Apache, MySQL and PHP. It provides some step-by-step instructions to install all this on most popular platforms.

### 2. Download

> There are two ways to get Moodle, as a compressed package and via CVS. These are explained in detail on the download page: http://moodle.org/download/

> After downloading and unpacking the archive, or checking out the files via CVS, you will be left with a directory called "moodle", containing a number of files and folders.

> You can either place the whole folder in your web server documents directory, in which case the site will be located at http://yourwebserver.com/moodle, or you can copy all the contents straight into the main web server documents directory, in which case the site will be simply http://yourwebserver.com.

### 3. Site structure

> Here is a quick summary of the contents of the Moodle folder, to help get you oriented:

> > config.php - the ONLY file you need to edit to get started
> > version.php - defines the current version of Moodle code
> > index.php - the front page of the site

> > - admin/ - code to administrate the whole server
> > - auth/ - plugin modules to authenticate users
> > - course/ - code to display and manage courses
> > - doc/ - help documentation for Moodle (eg this page)
> > - files/ - code to display and manage uploaded files
> > - lang/ - texts in different languages, one directory per language
> > - lib/ - libraries of core Moodle code
> > - login/ - code to handle login and account creation
> > - mod/ - all Moodle course modules
> > - pix/ - generic site graphics
> > - theme/ - theme packs/skins to change the look of the site.
> > - user/ - code to display and manage users

### 4. Create a data directory

> Moodle will also need some space on your hard disk to store uploaded files, such as course documents and user pictures.

> Create a directory for this purpose somewhere. For security, it's best that this directory is NOT accessible directly via the web. The easiest way to do this is to simply locate it OUTSIDE the web directory, otherwise protect it by creating a file in the data directory called .htaccess, containing this line:

> >     deny from all

> To make sure that Moodle can save uploaded files in this directory, check that the web server software (eg Apache) has permission to write to this directory. On Unix machines, this means setting the owner of the directory to be something like "nobody" or "apache".

> On many shared hosting servers, you will probably need to restrict all file access to your "group" (to prevent other webhost customers from looking at or changing your files), but provide full read/write access to everyone else (which will allow the web server to access your files). Speak to your server administrator if you are having trouble setting this up securely.

### 5. Create a database

> You need to create an empty database (eg "moodle") in your database system along with a special user (eg "moodleuser") that has access to that database (and that database only). You could use the "root" user if you wanted to, but this is not recommended for a production system: if hackers manage to discover the password then your whole database system would be at risk, rather than just one database.

> Example command lines for MySQL:

>        # mysql -u root -p
>        > CREATE DATABASE moodle;
>        > GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTER ON moodle.*
>                TO moodleuser@localhost IDENTIFIED BY 'yourpassword';
>        > quit
>        # mysqladmin -p reload

> Example command lines for PostgreSQL:

>        # su - postgres
>        > psql -c "create user moodleuser createdb;" template1
>        > psql -c "create database moodle;" -U moodleuser template1
>        > psql -c "alter user moodleuser nocreatedb;" template1

> (For MySQL I highly recommend the use of phpMyAdmin to manage your databases - you can do all this via a web interface).

> As of version 1.0.8, Moodle now supports table prefixes, and so can safely share a database with tables from other applications.

### 6. Check your web server settings

> Firstly, make sure that your web server is set up to use index.php as a default page (perhaps in addition to index.html, default.htm and so on).

> In Apache, this is done using a DirectoryIndex parameter in your httpd.conf file. Mine usually looks like this:

> >     DirectoryIndex index.php index.html index.htm

> Just make sure index.php is in the list (and preferably towards the start of the list, for efficiency).

> Secondly, if you are using Apache 2, then you should turn on the AcceptPathInfo variable, which allows scripts to be passed arguments like http://server/file.php/arg1/arg2. This is essential to allow relative links between your resources, and also provides a performance boost for people using your Moodle web site. You can turn this on by adding these lines to your httpd.conf file.

> >     AcceptPathInfo on

> Thirdly, Moodle requires a number of PHP settings to be active for it to work. On most servers these will already be the default settings. However, some PHP servers (and some of the more recent PHP versions) may have things set differently. These are defined in PHP's configuration file (usually called php.ini):

> >     magic_quotes_gpc = 1    (preferred but not necessary)
> >     magic_quotes_runtime = 0    (necessary)
> >     file_uploads = 1
> >     session.auto_start = 0
> >     session.bug_compat_warn = 0

> If you don't have access to httpd.conf or php.ini on your server, or you have Moodle on a server with other applications that require different settings, then don't worry, you can still OVERRIDE all of the default settings.

> To do this, you need to create a file called .htaccess in Moodle's main directory that contains definitions for these settings. This only works on Apache servers and only when Overrides have been allowed.

> >     DirectoryIndex index.php index.html index.htm

> >     <IfDefine APACHE2>
> >          AcceptPathInfo on
> >     </IfDefine>

> >     php_flag magic_quotes_gpc 1
> >     php_flag magic_quotes_runtime 0
> >     php_flag file_uploads 1
> >     php_flag session.auto_start 0
> >     php_flag session.bug_compat_warn 0

> You can also do things like define the maximum size for uploaded files:

> >     LimitRequestBody 0
> >     php_value upload_max_filesize 2M
> >     php_value post_max_size 2M

> The easiest thing to do is just copy the sample file from lib/htaccess and edit it to suit your needs. It contains further instructions. For example, in a Unix shell:

> >     cp lib/htaccess .htaccess

### 7. Edit config.php

> Now you can edit the configuration file, config.php, using a text editor. This file is used by all other files in Moodle.

> To start with, make a copy of config-dist.php and name it config.php. We do this so that your config.php won't be overwritten in case you upgrade Moodle later on.

> Edit config.php to specify the database details that you just defined (including a table prefix - notice that this is REQUIRED for PostgreSQL), as well as the site address, file system directory and data directory. The config file itself has detailed directions and examples.

> Once you have done this the rest of the installation is via a web interface. For the rest of this installation document we will assume your site is at: http://example.com/moodle

### 8. Go to the admin page

> The admin page should now be working at: http://example.com/moodle/admin. If you try and access the front page of your site you'll be taken there automatically anyway. The first time you access this admin page, you will be presented with a GPL "shrinkwrap" agreement with which you must agree before you can continue with the setup.

> (Moodle will also try to set some cookies in your browser. If you have your browser set up to let you choose to accept cookies, then you must accept the Moodle cookies, or Moodle won't work properly.)

> Now Moodle will start setting up your database and creating tables to store data. Firstly, the main database tables are created. You should see a number of SQL statements followed by status messages (in green or red) that look like this:

> > CREATE TABLE course ( id int(10) unsigned NOT NULL auto_increment, category int(10) unsigned NOT NULL default '0', password varchar(50) NOT NULL default '', fullname varchar(254) NOT NULL default '', shortname varchar(15) NOT NULL default '', summary text NOT NULL, format tinyint(4) NOT NULL default '1', teacher varchar(100) NOT NULL default 'Teacher', startdate int(10) unsigned NOT NULL default '0', enddate int(10) unsigned NOT NULL default '0', timemodified int(10) unsigned NOT NULL default '0', PRIMARY KEY (id)) TYPE=MyISAM

> > SUCCESS

> > ...and so on, followed by: Main databases set up successfully.

> If you don't see these, then there must have been some problem with the database or the configuration settings you defined in config.php. Check that PHP isn't in a restricted "Safe Mode" (commercial web hosts sometimes have safe mode turned on). You can check PHP variables by creating a little file containing <? phpinfo() ?> and looking at it through a browser. Check all these and try this page again.

> Scroll down the very bottom of the page and press the "Continue" link.

> Next you will see a similar page that sets up all the tables required by each Moodle module. As before, they should all be green.

> Scroll down the very bottom of the page and press the "Continue" link.

> You should now see a form where you can define more configuration variables for your installation, such as the default language, SMTP hosts and so on. Don't worry too much about getting everything right just now - you can always come back and edit these later on using the admin interface. Scroll down to the bottom and click "Save changes".

> If (and only if) you find yourself getting stuck on this page, unable to continue, then your server probably has what I call the "buggy referrer" problem. This is easy to fix: just turn off the "secureforms" setting, then try to continue again.

> The next page is a form where you can define parameters for your Moodle site and the front page, such as the name, format, description and so on. Fill this out (you can always come back and change these later) and then press "Save changes".

> Finally, you will then be asked to create a top-level administration user for future access to the admin pages. Fill out the details with your own name, email etc and then click "Save changes". Not all the fields are required, but if you miss any important fields you'll be re-prompted for them.

> > > > > > Make sure you remember the username and password you chose for the administration user account, as they will be necessary to access the administration page in future.

> (If for any reason your install is interrupted, or there is a system error of some kind that prevents you from logging in using the admin account, you can usually log in using the default username of "admin", with password "admin".)

> Once successful, you will be returned to home page of your site. Note the administration links that appear down the left hand side of the page (these items also appear on a separate Admin page) - these items are only visible to you because you are logged in as the admin user. All your further administration of Moodle can now be done using this menu, such as:

> - creating and deleting courses
> - creating and editing user accounts
> - administering teacher accounts
> - changing site-wide settings like themes etc

### 9. Set up cron

> Some of Moodle's modules require continual checks to perform tasks. For example, Moodle needs to check the discussion forums so it can mail out copies of posts to people who have subscribed.

> The script that does all this is located in the admin directory, and is called cron.php. However, it can not run itself, so you need to set up a mechanism where this script is run regularly (eg every five or ten minutes). This provides a "heartbeat" so that the script can perform functions at periods defined by each module.

> Note that the machine performing the cron does not need to be the same machine that is running Moodle. For example, if you have a limited web hosting service that does not have cron, then you can might choose to run cron on another server or on your home computer. All that matters is that the cron.php file is called regularly.

> The load of this script is not very high, so 5 minutes is usually reasonable, but if you're worried about it you can reduce the time period to something like 15 minutes or even 30 minutes. It's best not to make the time period too long, as delaying mail-outs can slow down activity within the course.

> First, test that the script works by running it directly from your browser:

> >     http://example.com/moodle/admin/cron.php

> Now, you need to set up some of way of running the script automatically and regularly.

> #### Running the script from a command line

> You can call the page from the command line just as you did in the example above. For example, you can use a Unix utility like 'wget':

> >     wget -q -O /dev/null http://example.com/moodle/admin/cron.php

> Note in this example that the output is thrown away (to /dev/null).

> The same thing using lynx:

> >     lynx -dump http://example.com/moodle/admin/cron.php > /dev/null

> Alternatively you could use a standalone version of PHP, compiled to be run on the command line. The advantage with doing this is that your web server logs aren't filled with constant requests to cron.php. The disadvantage is that you need to have access to a command-line version of php.

> >     /opt/bin/php /web/moodle/admin/cron.php

> >     (Windows) C:\apache\php\php.exe C:\apache\htdocs\moodle\admin\cron.php

> #### Automatically running the script every 5 minutes

> On Unix systems: Use cron. Edit your cron settings from the commandline using "crontab -e" and add a line like:

> >     */5 * * * * wget -q -O /dev/null http://example.com/moodle/admin/cron.php

> Usually, the "crontab" command will put you into the 'vi' editor. You enter "insert mode" by pressing "i", then type in the line as above, then exit insert mode by pressing ESC. You save and exit by typing ":wq", or quit with saving using ":q!" (without the quotes).

> On Windows systems: The simplest way is to use this little package moodle-cron-for-windows.zip which makes this whole thing very easy. You can also explore using the built-in Windows feature for "Scheduled Tasks".

> On web hosts: Your web-based control panel may have a web page that allows you to set up this cron process. Ask your administrator for details on how it works.

### 10. Create a new course

> Now that Moodle is running properly, you can create a course.

> Select "Create a new course" from the Admin page (or the admin links on the home page).

> Fill out the form, paying special attention to the course format. You don't have to worry about the details too much at this stage, as everything can be changed later by the teacher.

> Press "Save changes", and you will be taken to a new form where you can assign teachers to the course. You can only add existing user accounts from this form - if you want to create a new teacher account then either ask the teacher to create one for themselves (see the login page), or create one for them using the "Add a new user" on the Admin page.

> Once done, the course is ready to customise, and is accessible via the "Courses" link on the home page.

> See the "Teacher Manual" for more details on course-building.

Moodle Documentation

Version: $Id$