Installing Moodle in Different Environments
From InstallationWiki
| Official Page |
| Project Documentation |
| Download |
|
Contents |
[edit] Installation in a LAMP Environment
Moodle is developed in Linux using Apache, MySQL, and PHP (also known as the LAMP platform). If you have a choice, this is the preferred environment to be used.
[edit] Downloading Moodle
Go to http://download.moodle.org to download Moodle. As you can see, there are quite a number of distributions to choose from:
For the current version of Moodle, there are two releases:
- Latest stable build
- Latest official release.
The latest stable version is created weekly (every Wednesday) and is the best choice for a new server.
The latest official release contains the stable build as well as new fixes, but the version will not have gone through the weekly code review and might contain unresolved issues.
Versions that are older than the current one are maintained by the Moodle development team, and bug fixes are back-ported. Sometimes newly added functionality is back-ported. Currently, the oldest supported version is 1.6, but this will certainly change in the future. For older versions, a stable build and the last release are made available.
Moodle (that is http://download.moodle.org) also offers you to download beta releases of the software (if available) and also the latest development release. These should only be downloaded for testing or development purposes, and never used in production environments.
Each version is made available in two compressed formats TGZ (use the tar command to uncompress) and ZIP (requires unzip). You can either download them by clicking on the respective link or, if you have (secure) shell access, retrieve the file directly using the wget command:
wget http://download.moodle.org/stable19/moodle-weekly-19.zip
Once you have moved the file to the location where you want to install it on your web server (dirroot), extract the file using the unzip command (or tar zxvf if you downloaded the TGZ version). In a hosted environment, you might have to use the uncompressing method provided by the web administration interface (CPanel, Plesk, or any customized system).
If you place the entire folder in your web server documents directory, the site will be located at http://www.yourwebserver.com/moodle. To access your site from http://www.yourwebserver.com, copy the contents directly into the main web server's documents directory.
This screenshot is taken from a secure shell (SSH) in a hosted environment. Four commands were used:
-
Pwd: To make sure we are in the correct path -
wget: To download Moodle -
ls la: To verify that the file had been downloaded correctly -
tar xvfz: To unpack the archive.
Once this is successful, you have to create the database that Moodle uses to store its data.
[edit] Creating the Moodle Database and the Data Directory
Moodle requires a database where it stores information. While it is possible to share an existing database, it is highly recommended to create a separate MySQL database for Moodle. This can either be done via a web interface as provided for hosted servers or via the Unix command line.
[edit] Using a Hosted Server
Most hosting providers provide a dedicated web interface to carry out basic database operations. Alternatively, you can use phpMyAdmin, an open-source software that allows you to manage MySQL databases over the Web. It is a part of most Linux distributions, and also a part of many control panels such as CPanel or Plesk. (phpMyAdmin is often configured to stop new databases from being created. If this is the case, you have to create the database from the database manager in CPanel or Plesk).
Once you have started phpMyAdmin, go to the Database section and create a new database using the UTF collation. You don't need to create any tables; Moodle will be populating the database during the installation process.
While you can use an existing database user account, it is good practice to create a dedicated user for the Moodle database. This step is carried out in the Privileges section.
phpMyAdmin allows you to perform both steps creating a database and adding a new user in a single action, which is shown in the following screenshot. We create a user tutorial and also a database with the same name granting all privileges:
[edit] Using the Command Line
If you don't have access to a web interface to create MySQL databases and user accounts, or if you prefer to use a Linux shell, you can perform the steps via the command line:
1. Start the database command line tool: mysql u root p and enter the password at the prompt
2. Create a database (here called book): CREATE DATABASE book; (all mysql commands have to be completed with a semicolon)
3. Set the default character set and collation order to UTF8: ALTER DATABASE tutorial DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
4. Create a user and password (here both are book) and grant database access permissions:
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON book.* TO book@localhost IDENTIFIED BY 'book';
5. Exit the mysql command tool: QUIT
It is necessary to reload the grant tables using the following command line:
mysqladmin -u root -p reload
You have now completed the database setup. All we have to do now is to create Moodle's data directory before we are ready to start the installation of Moodle per se.
[edit] Creating the Moodle Data Directory
Moodle stores most of its information in the database you have just created. However, any uploaded files such as assignments or pictures are stored in a separate directory. This data directory in Moodle is usually referred to as moodledata.
Later on, the Moodle installer will attempt to create this directory, but in some setups this is not possible due to security restrictions. To be on the safer side, it is better to create moodledata manually or via a web-based file manager as provided by systems such as CPanel and Plesk.
1. Create the directory: mkdir moodledata
2. Change permissions recursively: chmod R 0770 moodledata (if you use 0777, then everybody on the server will have access to the files)
3. Change user of the directory to that of your web server (usually Apache or www-data): chown R apache moodledata
4. Change the group of the directory to that of your web server (usually nobody or www-data): chgrp R nobody moodledata
It is important to create moodledata on your server where it cannot be accessed publicly, that is, outside your web directory! If you don't have permissions to create the data directory in a secure location, create the .htaccess file in your home directory containing the following two lines:
- order deny,allow
- deny from all
This will protect any files from being accessed without having permissions to do so.
[edit] Running the Installer Script
The installer script performs two main actions: populating the database and creating the configuration file config.php. The Moodle installer is initiated by entering the URL of the wwwroot (the location where you copied Moodle) into your web browser. The installer will recognize that Moodle hasn't been installed yet and will start the process automatically.
The Moodle installer has to set a session cookie. If your browser has been configured to trigger a warning, make sure you accept that cookie. The first installation screen lets you choose the language to be used during the installation. This is not the locale used for Moodle, but only the installation:
Before the Moodle installer continues, it checks that all your PHP settings are correct. If any of the tests are not passed, it is important that you go back to the software prerequisites section, resolve any problems, and restart the installation process after the issues have been fixed:
The next screen displays the expected values for the Web address of the site (wwwroot), the Moodle Directory (dirroot), and the Data Directory (dataroot). You might have to modify the data directory entry if the location of your moodledata differs:
If dataroot cannot be located or does not have the correct permissions, the following error message will be displayed:
"The 'Data Directory' you specified could not be found or created. Either correct the path or create that directory manually."
If that is the case, go back to the Data Directory section to check for any problems.
The next screen deals with the configuration of your database, which we set up earlier:
| Setting | Description |
|---|---|
| Type | This specifies the database type. The default is MySQL, which is used in this installation. If you use another database, select the appropriate choice. |
| Host Server | The default is localhost (or 127.0.0.1), which is correct if the database is located on the same server as the web server. If it is located on a separate server, specify the IP address (preferably unresolved to improve performance). |
| Database | The database name you entered when you ran the mysql command. |
| User | The username you entered when you ran the mysql command. |
| Password | The database password you entered when you ran the mysql command. |
| Tables prefix | All tables the Moodle installer is going to create will be prefixed with mdl_. This should only be changed if you run multiple Moodle installations using the same database.
|
Once you are through the database details screen, the Moodle installer checks to see if a number of components are installed. Not all modules are compulsory (see the section on Prerequisites in this tutorial).
The next screen allows you to install additional language packs that are required if you want to support languages other than the one selected for the installer.
You will see in the next screen that the Moodle configuration file config.php has been successfully created. If the creation of the configuration file fails, the installer will let you download config.php. You will have to copy the text from the screen and paste it into a file called config.php in your dirroot:
Before Moodle can proceed with the installation, you have to agree to the GPL (General Public Licence) agreement. You will find the full license text at http://docs.moodle.org/en/License:
This screen is followed by the current release information that includes the version and built to be installed as well as a link to the current release notes.
Once this screen has been confirmed, the Moodle installer will create all tables in the database. If you untick the Unattended operation option, each screen will have to be confirmed. Unless this is your first installation or you have encountered problems with previous installations, it is usually not necessary to run the rest of the installation in attended operation mode:
Once the table creation and population have been concluded, you will see the screen to set up the administrator account. The default username is admin, which can be changed. The self-explanatory fields you have to fill in are password, First name, Surname, Email address, City/town, and country.
The last screen of the installation script asks you to enter some Front Page settings, namely the Full site name, the Short name of your site, and a Site description and these front page settings can be modified later.
Once this information has been entered and the screen has been confirmed, you are ready to start using Moodle. However, it is recommended to finalize the installation and to set up the execution of the Moodle maintenance script.
[edit] Finalizing the Installation
To make sure that Moodle is running without problems, go to Notifications in the Site Administration block. Your installation has been successful if the following screen is displayed:
Moodle provides some statistics about its usage on http://moodle.org/stats. To be included in these figures, you have to register your Moodle site. Registration is optional and free, and you decide which information will be made public. You will get occasional notices from moodle.org, for example about advance security alerts.
Moodle states that once you are registered the Moodle Registration button will be removed, which is not the case. The fact that the button remains actually makes sense, as it is used to change any of your registration details at a later stage:
The settings of the registration screen are as follows:
| Field | Description |
|---|---|
| URL | URL of your Moodle site. |
| Current version | Moodle version and build. |
| Country | Select the country in which your organization is located. |
| Public directory | You have the options to:
|
| Contact from the public | By default, Moodle creates a form for other Moodle users to contact you, which can be turned off. |
| Statistics | Some statistics regarding the number of courses, users, role assignments, teachers, forum posts, questions, and resources. This information will not be displayed to the public. |
| Administrator | Your name. |
| Email address | Your email address. |
| Email notifications | By default, Moodle emails you important information such as upgrades and security issues. |
[edit] Setting up the Cron Process
Moodle has to perform a number of background tasks on a regular basis. The script that is performing these tasks is known as a cron script, which is executed by the so-called cron process. An entire page has been dedicated in the Moodle documentation and you can find it at http://docs.moodle.org/en/Cron. It is important that you set up the cron process. Otherwise, any timed Moodle features such as scheduled backups, sending forum notifications, statistics processing, and so on will not work.
The script cron.php is located in the admin directory and can be triggered manually through a web browser (unless your security settings have been changed). Once executed, the output from the script (http://yoursite/admin/cron.php) is shown on screen and you have to navigate back to your Moodle system manually.
Most control panels allow you to set up scheduled tasks via their interface. The following is a screenshot from the widely used Plesk system that executes the script every 5 minutes:
There are a number of ways to call the cron script. wget q O /dev/null http://<yoursite>/admin/cron.php is the most popular option in a Linux environment (see Command in the preceding screenshot). However, if this does not suit your environment, check out http://docs.moodle.org/en/Cron for alternatives.
The above interface creates an entry in the crontab, a file located in the /etc directory that contains all system-wide cron entries. This file can also be added manually using crontab -e, but be careful to get the syntax right.
This concludes the entire installation process of Moodle. If you have come across any problems that have not been covered in these instructions, or your setup differs from the one described, go to http://docs.moodle.org/en/Installing_Moodle where more installation details are provided along with exceptions covered in great detail.
[edit] Installation in a Windows Environment
XAMPP is a free Apache distribution that contains MySQL and PHP (as well as Perl). It exists for a number of operating systems. The Moodle distribution for Windows makes full use of XAMPP, and is located at http://download.moodle.org/windows. The installation works on Windows XP, Windows Vista, and Windows Server 2003.
Once downloaded, follow these steps:
1. Copy the distribution to a directory on your PC and unzip the archive in your directory of choice.
2. Make sure any software that uses port 80 (such as Skype) is not running or change it to use an alternative port.
3. Double-click on Start Moodle.exe.
4. If you have a firewall installed, allow the database service mysqld.exe to be executed.
5. A command line window will appear, which has to stay open. You can minimize the window, but do not close it.
6. Go to your web browser and enter http://localhost to your address bar.
7. You will see an installer being launched, which is the same one described for the LAMP environment. All values have already been populated; all you have to do is navigate through all the screens until you see the familiar Setup administrator account. This process will take a few minutes.
8. Enter the administrator details and select Update Profile.
9. Enter the Front Page settings for your site.
10. Check that no warnings are displayed in the Notifications area in the Site Administration block.
That's it! Your Moodle system is now up and running. You are now able to use Moodle locally or from a web browser on another machine as long as your IP address is accessible via the network you are in.
The XAMPP-based Moodle distribution is only suitable for servers with a small number of users. For larger Windows installations, you have to install Moodle manually or with Microsoft IIS (check out http://download.moodle.org/windows for details).
To stop using Moodle, double-click on Stop Moodle.exe. If you have a firewall installed, allow myadmin.exe to be executed.
Instead of starting and stopping Moodle manually, you can start Apache and MySQL automatically as Windows services. In the server directory of your Moodle system you find an executable called service.exe, which you have to run with the -install parameter as administrator, for example:
C:/moodle/server/service.exe -install
[edit] Installation in a Mac OS X Environment
MAMP is a free distribution that contains Apache, MySQL, and PHP for Mac OS X. The Moodle distributions for Mac OS X (10.4 or higher) are available as Intel and PPC versions, located at http://download.moodle.org/macosx. Once downloaded, follow these steps:
1. Double-click on the downloaded DMG file to start the installation. This will open a screen explaining the rest of the installation process.
2. Drag the MAMP folder on this screen onto the Applications icon, which will copy the Moodle system and its required components.
3. Open the MAMP folder in Applications where you will find two relevant icons.
4. Double-click on the MAMP icon to start Apache and MySQL. There is also a MAMP Control Widget in the same directory, which you might want to install.
5. Double-click on the Link to Moodle icon, which opens http://localhost:8888/moodle on your default web browser.
And that's it! An installation cannot be easier than that. You don't even have to go through the installation process. Moodle is pre-configured and you are ready to go.
The default password for the admin account is 12345. You should change this in the user profile.
The directory also includes a shell script called UpdateMoodle19.sh (requires CVS to be installed). When you double-click on the file, the script will be executed that downloads the latest version of Moodle and installs it on your Mac. On all other operating systems you will have to go through a more cumbersome update process, which is described next:
[edit] Additional References
- For instructions on advanced techniques for Customizing Moodle, click here
- For instructions on installing Moodle, click here
- For instructions on Theming Moodle, click here
- For instructions on Customizing Moodle Front Page,click here
- For instructions on Updating Moodle,click here
- For instructions on Configuring Moodle 1.9 for multimedia,click here
[edit] Source
The source of this content is Chapter 2: Moodle Installation of Moodle Administration by Alex Büchner(Packt Publishing, 2008).
