Note: You are currently viewing documentation for Moodle 2.2. Up-to-date documentation for the latest stable version is available here: Step by Step Installation on a Mac OS X Server.

Step by Step Installation on a Mac OS X Server

From MoodleDocs

Overview

This guide shows all steps for the installation of Moodle on a Mac OS X Server. This server is a commercial product. You will find all documentations about the web server on the Apple support pages.

This installation guide can't be useful for an installation on MAMP or XAMPP. If you are looking for an easy way to install Moodle on your local machine please use Complete install packages for Mac OS X 10.4/10.5/10.6 Clients that can be downloaded from http://download.moodle.org/macosx/ ... but if you are planning to set up a Moodle internet server on a Mac then you should think about some more security as the ever local package could give.

Please feel free to add your ideas and wishes to the discussion page for this article. You may also write a complete chapter if you tried the facts yourself on your own Mac Server. I am most interested to make the things better.

System requirements

+ Apple Computer 
+ Mac mini, Mac Pro or Xserve
+ Processor:  Intel Core 2 Duo, Intel Core i3/i5/i7
+ RAM: 2 GB or better
+ Hard Disk: 500 MB free
+ System Software: Mac OS X Server 10.5 or 10.6

Configure PHP for your Moodle installation

Mac OS X 10.6 Server - No PHP installation needed

The Mac OS X 10.6.5 Server (SnowLeopard) comes with PHP 5.3.3 and a lot of PHP extensions. This would be the best choice for Moodle 1.9.x and for Moodle 2.0 on a Mac OS X Server. Please forget everything you read about the missing GD Library! The PHP installation is totally complete for Moodle. You only have to switch on the PHP module and to control if the file /etc/php.ini sets the right values for Moodle.

Server-admin-106.png

Mac OS X 10.5 Server - Install PHP 5.3.0 and the GD Library

The Mac OS X 10.5.8 Server (Leopard) comes with PHP 5.2.6 ... this is correct for Moodle 1.9.x. But you have to add the missing GD Library support to get Moodle running on your server. For Moodle 2.0 the server must have PHP 5.2.8 (or better) and some more PHP extensions ... in this case you need to get the better PHP version. These instructions are helpful in both cases.

To see which PHP version and extensions are installed on your server you should edit the file /Library/WebServer/Documents/info.php. You must activate the function call phpinfo() by deleting the both slashes // at the start of the function line. After saving the file you can get all PHP informations in your browser. Please look at http://your-server-address/info.php ... you will not find any GD library support ... bad thing for Moodle!!

<?php
// You can use Server Admin to enable the Apache PHP module; it's disabled by default.
// You can uncomment the phpinfo() directive below to provide a default PHP info page
// but note that this displays information about your host's configuration.
phpinfo();
?>


The easiest way to get the GD library support and to get a better PHP version would be the installation of the complete PHP 5.3.0 package from http://www.entropy.ch/software/macosx/php/. Marc Liyanage precompiled this package to use it on Mac clients and Mac servers. Please get the package and install it by following the instructions on the download page. The installer does everything for you ... it copies PHP into the correct folder /usr/local/php5 and changes its owner to root automatically. You will find the file php.ini inside the new package folder. Open the file /usr/local/php5/lib/php.ini and edit some settings for Moodle.

Note: If you want to install Moodle 1.8.x on the server you need to get the Entropy PHP-5.2.9-7.pkg instead. Moodle 1.8.x does not run with PHP 5.3.0. (MDL-20128)

Now the Apache web server must get knowledge that you want to use the new PHP library instead of the old. Open the application Server Admin to switch to the new library. Go to the web server settings and find the entry php5_module. The normal place for PHP the Mac server is libexec/apache2/libphp5.so. Please change to /usr/local/php5/libphp5.so and save the settings.

Server-admin.png

PHP settings in your php.ini

The next thing is to configure the file php.ini. Most of the settings are okay but not all of them. To communicate to the MySQL database with PHP you have to set the default socket name for local MySQL connects. The default socket name for local MySQLi connects is needed for Moodle 2.0.

If you want to upload any file to your Moodle you should add a little bit more upload size in php.ini. If your server can't use more than 1 GB RAM you should set the memory_limit to a value less than 128M ... but it should have more than 48M for Moodle 1.9 and Moodle 2.0. Note that these sections are not likely to be consecutive in the php.ini file; the quickest way to find each one is search on the initial term (such as 'mysql.default_socket').

; Default socket name for local MySQL connects.  
; If empty, uses the built-in MySQL defaults.
mysql.default_socket = /var/mysql/mysql.sock

; Default socket name for local MySQL connects.  
; If empty, uses the built-in MySQL defaults.
mysqli.default_socket = /var/mysql/mysql.sock

; Maximum amount of memory a script may consume (128MB)
memory_limit = 128M     

; Maximum allowed size for uploaded files.
upload_max_filesize = 128M

; Maximum size of POST data that PHP will accept.
post_max_size = 128M

; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = 'Europe/Berlin';

That's all ... save the file php.ini and restart the web server. Now you should look at http://your-server-address/info.php again. I hope that everything will be okay. You will find the version number PHP 5.3.x and the running GD library support. Congratulations ... the first step for Moodle on your Mac server is done!

phpinfo.png


phpinfo2.png

Configure the MySQL database for your Moodle installation

In standard case the database MySQL is installed on the Mac OS X Server but it is not running yet. Please make sure that you start the MySQL database server.

Use the graphical way

Sorry ... there are some more installations and a lot of clicks to configure MySQL in a graphical way.

First of all start the Server Admin. You will find this program by the way Applications > Server > Server Admin. Activate MySQL on the local server. You must set the password for the user root before you can start MySQL.

For the next you must download the MySQL database administration tool phpMyAdmin from http://www.phpmyadmin.net . Move the folder to the web server documents as /Library/WebServer/Documents/phpMyAdmin.

Add the security phrase to the file config.inc.php in between the single quotes on the line $cfg['blowfish_secret'] = ; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Now you will be able to start http://your-server-address/phpMyAdmin/ in your browser and to log into the database as the user root. Add a database moodle19. Add a database user moodle to the server localhost. Don't forget to set a secure password. The database user moodle should be allowed to administrate the database moodle19 only. It is a bad way to set root to administrate the database moodle19. If you want to install also Moodle 2.0 dev please add a second database moodle20 and use the same database user for it.

phpMyAdmin is a nice thing to look into the database while Moodle is running for some time. It's much easier to see in the graphical interface than in the command line tools. The image shows the database after Moodle 1.9 and Moodle 2.0 were already installed on this server.

phpmyadmin.png

Use the Terminal

If you want a quick installation then don't fear to use the Terminal. It's easier to tell you all the commands for the right way with the Terminal than showing you all the pictures to do the same with graphical tools. There are only a few commands to do everything I told you before.

Start the Terminal. You will find this program by the way Applications > Tools > Terminal. You will see that we must do the same steps as before but you can read them in a text form.

First of all you need to set the root password. If you didn't this before then use the first command line. If you want to change an existing password then use the second one.

Server:~ $ mysqladmin -u root password 'secret'
Server:~ $ mysqladmin -u root -p password 'topsecret'

The next steps are creating a new database moodle19 with correct character set and setting up a database user moodle, with an assigned password (IDENTIFIED BY), to administrate the new database ... and if you want, then do the same for moodle20.

Server:~ $ mysqladmin -u root -p create moodle19
Server:~ $ mysql -u root -p

mysql> ALTER DATABASE moodle19 CHARSET 'utf8';
mysql> GRANT ALL PRIVILEGES ON moodle19.* TO moodle@localhost
   -> IDENTIFIED BY 'moodle!';
mysql> quit

Server:~ $

That's really all with the Terminal. You are just ready!

Use InnoDB with Moodle 2.0

For Moodle 2.0 you should setup the support for InnoDB in your MySQL database.

Open the file /etc/my.cnf an delete every # in all lines beginning with innodb. This uncomments the InnoDB settings. Please save the file and restart your MySQL database.

# Uncomment the following if you are using InnoDB tables
innodb_data_home_dir = /var/mysql/
innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
innodb_log_group_home_dir = /var/mysql/
innodb_log_arch_dir = /var/mysql/ 
# You can set .._buffer_pool_size up to 50 - 80 % 
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 384M
innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 100M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

Copy the Moodle files to the web server

The documents for the web server are saved in the folder /Library/WebServer/Documents/. You will place your Moodle folder here after you got it from http://download.moodle.org. Download the standard package MOODLE_19_WEEKLY because this is the best choice for new servers. Set the owner _www for the moodle folder ... this is the user for the web server. The folder permissions should be 755 before the installation and 555 after it's done ... please remember to set this later!

You also need the moodledata folder outside of the Documents folder ... so please make one. Go to the folder /Library/WebServer/ and add the folder moodledata. Because I want to install Moodle 1.9.x and Moodle 2.0 dev together on the same Mac server I add two folders moodle19 and moodle20 inside the moodledata folder. Please set the owner _www for both folders moodle19 and moodle20 and the folder permissions to 755.

cd /Library/WebServer/
mkdir moodledata
mkdir moodledata/moodle19
mkdir moodledata/moodle20
sudo chown -R _www moodledata
sudo chmod -R 755 moodledata

If you'd like to put the moodledata folder on another volume (not a bad idea if you think you'll have a substantial amount of data within the moodle), note that you cannot simply reference it using the /Volumes/<volume_name>/folder syntax during the moodle setup. Instead, you'll need to create the folder (assigning the user and permissions), then create a link to it within the /Library/WebServer folder. To create the link, use the following command in a terminal window, substituting your data volume and folder name:

cd /Library/WebServer
ln -s /Volumes/Data_Volume/moodledata moodledata

Run the Moodle installation

The installation on the Mac server is the same like the installation on every other server. Open a web browser to http://your-server-address/moodle/install.php to begin the installation process. On the screen picture and in the shown config.php you see the web address your-server-address ... it's only a placeholder for a real address or url ... please set yours. Also a user 'moodle' with a password 'moodle' would be very unsafe settings for your installation.


moodle-install1.png


moodle-install2.png


The installer generates the config.php automatically and saves it in the folder /Library/WebServer/Documents/moodle19. Please edit the config.php with a text editor and add the line date_default_timezone_set('UTC');. You may change UTC to your own timezone ... this is needed for PHP 5.3.0. In case you don't know all the relevant time zone identifiers by heart, there is a list available online.

<?php  /// Moodle Configuration File 

unset($CFG);

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

$CFG->wwwroot   = 'http://your-server-address/moodle19';
$CFG->dirroot   = '/Library/WebServer/Documents/moodle19';
$CFG->dataroot  = '/Library/WebServer/moodledata/moodle19';
$CFG->admin     = 'admin';

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

date_default_timezone_set('Europe/Berlin'); // timezone for PHP 5.3.0
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.
?>

After this, the web-based installation component will walk you through several screens worth of database configurations and updates, for most of which you'll just click the continue button. You'll set up an admin user and give the site a basic configuration (title, description, etc). When the installation is ready you should change the folder permission for /Library/WebServer/Documents/moodle19 to 555 so the web server is not able to write into this folder again.

Download the language packages

Moodle is running ...

moodle-on-macosx-server.png

How to setup the cron job with launchd

It's really important to start the cron job every 5 minutes. The cron job assists most of Moodle's modules to perform tasks on a scheduled basis. For example, the discussion forums can only mail out copies of new posts to all subscribers if the cron job tells Moodle to do this.

In Mac OS X you will find the system daemon launchd for this service. This daemon offers a standardized interface to any user and all programs started automatically by the system. Please look at http://developer.apple.com/macosx/launchd.html for more information about the configurations and all parameters.

In our case the service should get the web page http://your-server-address/moodle19/admin/cron.php every 5 minutes. The configuration will be done by the file named moodle4mac.cron.plist which must be placed in the system folder /Library/LaunchDaemons/ ... surely you can use any other file name but it should say something about the function of the service. The extension must be .plist. After any reboot of your Mac server the cron service will start automaticly because the file is placed in the correct system folder.

Use the graphical way

You can use Lingon to add a new daemon plist or to edit one. It produces the same text as you can write in your text editor. http://sourceforge.net/projects/lingon/files/

macosx-lingon.png

Use a text editor

Please use a text editor to write the needed file. You can open the Terminal and use the system editors vi or pico. But you can also write the text file with any GUI text editor ... I mostly use TextWrangler ... but do NOT take an editor for formatted texts like Microsoft Word or OpenOffice Writer. You must get pure text!

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" 
     "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key><false/>
<key>Label</key><string>moodle4mac.cron</string>
<key>ProgramArguments</key>
<array>
     <string>curl</string>
     <string>-s</string>
     <string>http://your-server-address/moodle19/admin/cron.php</string>
</array>
<key>RunAtLoad</key><true />
<key>StartInterval</key><integer>300</integer>
<key>StandardErrorPath</key><string>/dev/null</string>
<key>StandardOutPath</key><string>/dev/null</string>
</dict>
</plist>

The label string must be the same as the file name is but without the extension .plist. Save the text file /Library/LaunchDaemons/moodle4mac.cron.plist. The owner of the file must be set to the system user root. That's all, really!

How to start and stop the cron service

You can start the new cron service in the Terminal.

sudo launchctl load /Library/LaunchDaemons/moodle4mac.cron.plist

The following command would stop the service. If you want to activate changes in the cron service you need to unload and then to load the daemon again.

sudo launchctl unload /Library/LaunchDaemons/moodle4mac.cron.plist

Only one service for two servers?

For my server I needed to have a cron service for to instances moodle19 and moodle20 ... no problem ... with the typo moodle[19-20] the server will get a cron service for both instances.

curl -s http://your-server-address/moodle[19-20]/admin/cron.php

To see if the cron service works correctly you should look at the access.log of your web server. The cron.php should be accessed every 5 minutes ... on my server for both Moodle instances moodle19 and moodle20 ... oh yes, it works!!

192.168.0.220 - - [30/Jul/2009:22:10:56 +0200] "GET /moodle19/admin/cron.php HTTP/1.1" 200 1136
192.168.0.220 - - [30/Jul/2009:22:10:57 +0200] "GET /moodle20/admin/cron.php HTTP/1.1" 200 1403
192.168.0.220 - - [30/Jul/2009:22:11:18 +0200] "OPTIONS * HTTP/1.0" 200 -
192.168.0.220 - - [30/Jul/2009:22:15:56 +0200] "GET /moodle19/admin/cron.php HTTP/1.1" 200 735
192.168.0.220 - - [30/Jul/2009:22:15:57 +0200] "GET /moodle20/admin/cron.php HTTP/1.1" 200 964
192.168.0.220 - - [30/Jul/2009:22:20:56 +0200] "GET /moodle19/admin/cron.php HTTP/1.1" 200 1136
192.168.0.220 - - [30/Jul/2009:22:20:57 +0200] "GET /moodle20/admin/cron.php HTTP/1.1" 200 1365

How to install and update Moodle via CVS

CVS is very simple way to install and update your Moodle.

The only software you must have installed on your Mac server is the Xcode Tools package from your system installation media. You also must have an internet connection to get the files from the update server. After you installed both script files on your server desktop it only needs a doubleclick to get the newest Moodle version without downloading the complete installation package. Please remember - before you can update your Moodle via CVS you must install Moodle via CVS at once.

That's all .... really .... it's easy!!

Use the CVS installation script

If your Moodle is already installed via CVS please use the CVS updater (see below). Running the CVS installer will install only the standard version of Moodle on your server.

If you already have a working Moodle on your server then this script copies the file config.php into your new installation but it does not copy your additional modules or plugins or themes. You will find your old moodle folder in same directory and it will be renamed with an additional date stamp.

#! /bin/sh
#
#  CVS installer for Moodle
#  on a Mac OS X Server
# 
#  20100818 - Ralf Krause
#

export CVS_RSH=ssh

### file ~/.cvspass must exist
if ! test -e ~/.cvspass ; then
    touch ~/.cvspass
fi

echo
echo "+--------------------------------------------+"
echo "| CVS installer for the Moodle server "
echo "+--------------------------------------------+"
echo

cd /Library/WebServer/Documents

### get the cvs installation into a tmp folder
if ! test -e tmp ; then
    sudo mkdir tmp
    sudo chmod 777 tmp
fi

echo "Connecting to the CVS server. Download will take a few moments!"
echo "If the CVS update runs too long you may break with <ctrl>-C"
echo

### do the cvs installation
cd tmp
cvs -z9 -d:pserver:anonymous@uk.cvs.moodle.org:/cvsroot/moodle co -P -r MOODLE_19_WEEKLY moodle
cd ..

### copy config.php from your current moodle folder if it exists
if ! test -e moodle/config.php ; then
    cp moodle19/config.php tmp/moodle/config.php
fi

### move the new moodle to the right place
DATE=`date +%Y%m%d-%H%M`
sudo mv moodle19 moodle19-$DATE
sudo mv tmp/moodle moodle19
sudo chown -R _www moodle19

Use the CVS update script

To be able to update Moodle via CVS please check that your Moodle was already installed via CVS (see above).

#! /bin/sh
#
#  CVS updater for Moodle
#  on a Mac OS X Server
# 
#  20100818 - Ralf Krause
#

export CVS_RSH=ssh

echo
echo "+--------------------------------------------+"
echo "| CVS updater for the Moodle server "
echo "+--------------------------------------------+"
echo

cd /Library/WebServer/Documents/moodle19/

### file ~/.cvspass must exist
if ! test -e ~/.cvspass ; then
    touch ~/.cvspass
fi

### login to the cvs server only for the first time
if ! grep "uk.cvs.moodle.org" ~/.cvspass > /dev/null ; then
    echo "CVS password is empty ... please only press <return> to start"
    sudo cvs -d :pserver:anonymous@uk.cvs.moodle.org:/cvsroot/moodle login
    echo
fi

echo "Connecting to the CVS server. Download will take a few moments!"
echo "If the CVS update runs too long you may break with <ctrl>-C"
echo

### do the cvs installation
sudo cvs -q update -dP -r MOODLE_19_STABLE
sudo chown -R _www .

Please look at the documentation CVS for Administrators if you want to learn more about Moodle and CVS. There you will also find a list of different CVS servers for Moodle which you may choose for your updates.

The shown update script should be modified in only three things ... first you need to choose the correct folder for the Moodle files, second choose a CVS server near your server place to minimate internet traffic, and third you must input the correct CVS tag for the Moodle version in the last line. The shown script is for updating the version Moodle 1.9

  • Moodle 1.8 uses MOODLE_18_STABLE
  • Moodle 1.9 uses MOODLE_19_STABLE
  • Moodle 2.0 uses MOODLE_20_STABLE
  • Moodle 2.1 uses MOODLE_21_STABLE
  • Moodle 2.2 uses MOODLE_22_STABLE
  • Moodle 2.3dev uses HEAD

Troubleshooting

If CVS does not work on your server please check that the connection port is open.
If you see something like this, make sure that there is no firewall blocking the port (it's port 2401):

$ cvs -d:pserver:anonymous@us.cvs.moodle.org:/cvsroot/moodle login
Logging in to :pserver:anonymous@us.cvs.moodle.org:2401/cvsroot/moodle
CVS password:
cvs [login aborted]: connect to us.cvs.moodle.org(130.212.64.111):2401 failed: Connection timed out

Install Xcode Tools and CVS on your Mac Server

To test if cvs is already on your Mac Server please open the Terminal and type cvs -v. The output of this command should show a version notice of your Concurrent Versions System (CVS). If you get the command not found message then you must search for your Mac OS X 10.5 Server installation media. You will find the Xcode Tools on your installation CD or DVD set.

If you can't find your installation media anymore you also can download the Xcode Tools from the URL http://developer.apple.com/tools/xcode/. It is free but you have to register as a developer. Starting the download then the Xcode package copies a lot of bytes on your harddisk and will need a very few minutes to complete.

After you installed the Xcode Tools in your server system you will get the correct version answer from the Terminal command cvs -v. If you only want to update your Moodle you do not need all these nice developer tools from the inside of the folder. Sorry about this but there is no separate installer for the CVS update process.
 

User administration via LDAP

The following settings will work on 10.5 Server running LDAP - edit them to customize to your own environment. Please note that moodle requires some fields - it is best to have these fields completed in Workgroup Manager on 10.5 Server - otherwise they'll be prompted to enter info into their moodle profile on first login, but the way we've got it set up, moodle can't modify LDAP for security and data integrity. The necessary fields are user name, first name, surname, Email address, City/Town, country, description, ID number.

LDAP SERVER SETTINGS
Host URL = ourserver.example.com
Version = 3
LDAP encoding = utf-8

BIND SETTINGS
Hide passwords = Yes
Distinguished Name = (blank)
Password = (blank)

USER LOOKUP SETTINGS
User type = posixAccount (rfc2307)
Contexts = cn=users,dc=ourserver,dc=example,dc=com
Search subcontexts = Yes
Dereference aliases = No
User attribute = (blank)
Member attribute = (blank)
Member attribute uses dn = (blank)
Object class = (blank)

FORCE CHANGE PASSWORD
Force change password = No
Use standard Change Password Page = No
Password format = Plain text
Password change URL = (blank)

LDAP PASSWORD EXPIRATION SETTINGS
Expiration = no
Expiration warning = 10
Expiration attribute = ""
Grace logins = No
Grace login attribute = (blank)

ENABLE USER CREATION
Create users externally = No
Context for new users = (blank)

COURSE CREATOR
Creators = (blank)

CRON SYNCHRONIZATION SCRIPT
Removed ext user = Keep internal

NTLM SSO 
Enable = No
Subnet = (blank)
First name = givenName (On every login, Never, Locked)
Surname = sn (On every login, Never, Locked)
Email address = mail (On every login, Never, Locked)
Phone 1 = (blank)
Phone 2 = (blank)
Department = (blank)
Address = (blank)
City/Town = l (On every login, Never, Locked)
Country = c (On every login, Never, Locked)
Description = description (On every login, Never, Locked)
ID number = uidNumber (On every login, Never, Locked)
Language = (blank)

See also