Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Offline Moodle Create Environment

From MoodleDocs
Warning: This page is no longer in use. The information contained on the page should NOT be seen as relevant or reliable.

Creating an Offline Moodle Environment

This article is designed to help you replicate the Offline Moodle Environment that is being used within Offline Moodle. Currently we have focused on distributing to machines using the Windows operating system. In time we expect to add advice for other operating systems. We have tried to cover everything that's required to setup the entire environment so that this process it as simple as possible.

Source files

The environment comprises the following libraries Xampp: xampplite-win32-1.6.6.exe obtained from:

Create the Environment

First of all you need to create an environment that meets the basic requirements of Moodle. This includes:

  • A web server: To server internet files
  • A database server: To handle data records
  • A PHP distribution: Moodle runs under php so you need this installed.

Install The Architecture

I could say install xampp because that's what we'll be doing but it's important to remember that xampp is simply a web server, database server and php distribution, among other things, that is freely available and works on different operating systems. There are other solutions you could use and we've worked to ensure you could switch it to these instead of xampp if you so desired.

Since we're using xampp the install is very simple. Just run the exe and chose where to unzip the files. No registry settings should be changed and no other operating system changes will be made. This is important to the overall concept of Offline Moodle in that it can be run from the folder it is unzipped to. All that you need to do is reconfigure xampp to recognise it's new location, thankfully a handle utility setup_xampp.bat does this for you so you just need to click it. Then start xampp with xampp_start.exe and xampp should start. If you're using windows xp you may notice firewall warnings. This is what firewalls do, basically xampp starting means a database and web server start. Each on needs to access the network and provide data over the network. That's why your firewall asks if this is ok with you. So just choose unblock when prompted.

When prompted chose where to unzip the xampp files to. We'll choose c:\offline for this tutorial but I normally nest it much further where I'm used to keeping project files.

Start the Architecture

This should be as easy as explained above reconfigure xampp to recognise its new location using setup_xampp.bat and then start it using xampp_start.exe. When you want to stop it just use the corresponding xampp_stop.exe file.

You'll get a black command prompt window pop up telling you xampp and it's services starting. Now open a web browser on your machine and type http://localhost into the address bar and press enter. You should be taken to the xampp home page. If you're not then wait a short while and try again in case xampp was still starting. If xampp won't start then check the xampp site for advice on how to fix the error. My main problem was forget to reconfigure it when I move the xampp folder or install it.

So there you go. There is another way to get xampp running using the xampp-control.exe but I'll levave you to play around with that. At this point we're not planning to promote use of this in our Offline Moodle installs simply because it presents the webserver and database as separate applications. Which while correct we don't want users to have to worry about this complexity. We just want them to start and stop Offline Moodle as they would any application.

Secure XAMPP

We have taken some small steps to secure the database and web server directories using standard approaches. Xampp makes this simple by providing a form to enter the required details. to reach this form choose security from the left hand menu then half way down the page should be a link http://localhost/security/xamppsecurity.php. Follow the link and enter the necessary values.

we have left the default values in place and added passwords to the root accounts both for the database and web server directories. This won't affect access to the htdocs folder itself where Moodle runs from. It simply protects the xampp configuration that's accessible through a browser with the password you've set. This protects your xampp installation from malicious users.

Install Moodle

Now that we have a web server and database architecture working we need to install Moodle to get a VLE up and running.

Create the Database and Assign a User

First we have to create a database within the database server for Moodle to reside in and then create a user with access to this database.

I'll assume you know how to run sql commands against the database to follow the next points.


Run the following sql on the database

Creates the moodle database

  create database `moodle` character set utf8;

Creates the User and assigns permission to the database

  grant all on `moodle`.* to 'moodle'@'localhost' IDENTIFIED BY 'm00dl3';

Unzip Moodle

Unzip the Moodle installation to the folder c:\offline\htdocs\moodle create the folder c:\offline\moodledata so Moodle knows where to store its data

Create the config file

The first part of installing Moodle creates the configuration file which tells Moodle where it is on your device and what it can do.

There are two ways to do this. We recommend the first step as it creates a file that references files relative to your moodle installation. The wizard unfortunately uses paths that are absolute. They point exactly to the location Moodle is installed. This means that if you copy the xampp folder to another machine you will have to change these paths in the config.

if you do use the wizard then simply replace part of the file path for $CFG->dirroot and $CFG->dataroot with dirname(__FILE__) to let php determine where Moodle is installed and make it easy to move Offline Moodle around.

the two processes are described here.


1) Create the file directly create a file using the following values in the root of the moodle directory called config.php

<?php /// Moodle Configuration File

unset($CFG);

$CFG->dbtype = 'mysql'; $CFG->dbhost = 'localhost'; $CFG->dbname = 'moodle'; $CFG->dbuser = 'moodle'; $CFG->dbpass = 'm00dl3'; $CFG->dbpersist = false; $CFG->prefix = 'mdl_';

$CFG->wwwroot = 'http://localhost/moodle'; $CFG->dirroot = dirname(__FILE__); $CFG->dataroot = dirname(__FILE__).'\\..\\..\\moodledata'; $CFG->admin = 'admin';

$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode

require_once("$CFG->dirroot/lib/setup.php"); // MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES, // RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE. ?>

2) Use the install wizard Got to http://localhost.moodle Enter the values from above as they are requested. Once the config file is created change the values for $CFG->dirroot and CFG->dataroot as shown above to ensure they are dynamic paths that will work as the code is moved around.

Generate the Database tables and load data

Now you're past the point of editing files. Everything from this point should be done through a web browser since php is now running, you have a database setup and Moodle knows where it is and which account to use. In a web browser go to http://localhost/moodle and follow the install process

Here are the initial values we chose if you just want to copy and paste.

Setup up initial data

We've left out some of the compulsory value since you'll want to enter your own Username: Admin Password: m00dl3

Front Page settings

Full site name: Offline Moodle Short name for site: OfflineMoodle Front Page Description: Welcome to Offline Moodle

Setup session handling

So that we don’t conflict with other moodles change the session to be unique. Go to Server> Session Handling. In the Cookie prefix box enter ‘offlinemoodle’ and save changes. You will now have to log back in.

Add a student account

We've left out some of the compulsory value since you'll want to enter your own Username: student Password: testing


Create root support files Pre configured help files Readme.htm system-requirements.htm Help folder and contents

Improve Usability

Now we should have a fully installed and working Moodle environment that can work from any folder you move it to. What we need to do now is make it a little easier for the average user to use. We're technical guys that know how to configure these things but many students and lecturers won't have our technical skills so we want to remove any barriers there are to them just starting there machine, clicking start Offline Moodle and clicking a shortcut that opens Offline Moodle in a browser for them. Basically what are the fewest number of steps that we can achieve this in?

We looked at ways to package up Offline Moodle into one file, create batch files that automate all the processes necessary to configure and start xampp each time and many other options but each, while possible, would require more time, effort and expertise than we currently have to devote. they would also add complexity to the approach we are taking. At this point we just decided to go for the simplest solutions of creating shortcuts and readme files and adding a portable menu since these are very simple to create and degrade gracefully across environments thus ensuring we cater for the lowest common denominator.

Internet Shortcuts

Let's create a couple of shortcuts to save the user the trouble of typing urls. Once made the user just has to click these shortcuts to load a brwoser and see the site. That's two or three steps eliminated.

There are many ways to create shortcuts and feel free to choose your own. I thought I show you how to create a shortcut directly since that's what you'll end up with and you'll have more control this way.

Create a text file with the appropriate name and .url extension and open it in a text editor. Notepad, vim, eclipse, whatever. add the following lines

[InternetShortcut] URL=http://localhost/moodle

Save the file and double click it in the file system. You browser should open and go to the url. It's that simple. Or it is in windows XP. If it's different for other versions of windows then please let me know.

We created the following files Offline Moodle.url, URL=http://localhost/moodle Offline Moodle at the Open University.url, URL=http://www.open.ac.uk/offlinemoodle

The last link we created to give the user context of what Offline Moodle is. You'll probably want to create your own to guide your own users appropriately. Location

Readme Files

Following the practise of many application manufacturers we created an html readme file. this way it's more presentable than a plain text file and matches the web based approach of Moodle.

We added the files readme.htm system-requirements.htm

The full contents of these files are too large to add here and are changing as the project develops. The main contents of readme.htm cover basic points such as

   * Quick Start
   * Run On Another Machine
   * Troubleshooting
   * Improvements
   * Known Issues

Portable Menu

The latest addition to the mix is to provide a portable menu system(Pegtop PStart) that provides easy access to key components of Offline Moodle. Thanks for identifying this feature go to John Attwood and Pete Simson who have been developing his own Portable Moodle application similar to Offline Moodle. You can read more at http://hawk.aos.ecu.edu/moodle/mod/forum/discuss.php?d=141.

Again the xml config file the portable menu creates is too large to add here. The links are extremely easy to create within the menu itself and you'll probably want to customise it to your needs.

The main links we have included so far are:

  • readme: links to readme.htm
  • Offline Moodle: Links to the Offline Moodle.url shortcut created earlier
  • Start Offline Moodle: Links to the file xampp_start.exe
  • Stop Offline Moodle: Links to the file xampp_stop.exe
  • Reconfigure Offline Moodle: Links to the file setup_xampp.bat

We also added a group named 'resources' to contain links to extra components that may come in useful such as:

  • Restart Offline Moodle: Links to the file xampp_restart.exe
  • Is Offline Moodle Running?: Links to the file xampp-portcheck.exe