You are on page 1of 14

White Paper

Installing Moodle on Windows Server 2003


03/2008

Matthias Wachs
wachs@escde.net
Installing Moodle on Windows Server System

Table of contents
1. Abstract ............................................................................................................................... 2
2. Prerequisites ........................................................................................................................ 2
3. IIS 6 Installation .................................................................................................................. 2
4. Microsoft SQL Server Installation ...................................................................................... 3
Configuring SQL Server ........................................................................................................ 4
4.1. Create a moodle database user ..................................................................................... 5
4.2. Setting up database ...................................................................................................... 5
5. PHP5 Installation ................................................................................................................ 6
5.1. Installing PHP5 ............................................................................................................ 6
5.2. Checking the PHP permissions.................................................................................... 9
5.3. Installing FreeTDS ...................................................................................................... 9
5.4. Configuring PHP ....................................................................................................... 10
5.5. Checking the PHP Installation ................................................................................... 11
6. Moodle Installation ........................................................................................................... 11
6.1. Preparations ............................................................................................................... 11
6.2. Installation ................................................................................................................. 12

i
Installing Moodle on Windows Server System

1. Abstract

This document describes in detail how to install the Moodle learning solution on a Windows
Server System including Microsoft SQL Server and the Internet Information Services 6 from
scratch. This whitepaper uses a fresh Windows Server installation and explains step by step
the installation process of Internet Information Services (IIS), Microsoft SQL Server, the PHP
installation and configuration and the Moodle installation. The products used in this
whitepaper are:

 Microsoft Windows Server 2003 R2


 Microsoft Internet Information Services 6
 Microsoft SQL Server 2005
 PHP 5.2.x
 The FreeTDS PHP Extension
 Moodle 1.9

This is an updated version of the original “Installing Moodle on Windows Server 2003”
paper. While the original paper only covers an installation limited to a single and out-of-date
version of PHP, this updated version takes cares about the installation not limited to a special
PHP version. We are using the latest versions of PHP, FreeTDS and Moodle available at the
moment this paper is written.

Furthermore the section taking care of the PHP installation and configuration process is
incredibly improved. So this paper will focus on the installation of PHP as an ISAPI filter,
which provides an incredible boost in speed and security in contrast to the use of the CGI or
FastCGI version. Also the PHP configuration and security issues are much more accentued in
this updated version in respect to the previous paper.

Starting with a clean Windows Server installation, we will begin with the installation of the
Internet Information Services, we will make available. Moodle will be storing its data in a
Microsoft SQL Server 2005, so we will proceed with installing and configuring the database
server. This step will be followed by installing and setting up PHP5, configuring IIS to use it
and modifying PHP’s database extension to get PHP to work with Microsoft SQL Server.
After these goals are accomplished, the Moodle installation will be performed.

2. Prerequisites
To successfully implement a Moodle installation on a Windows Server 2003 System, we start
with a clean installation of the operating system. Please check that the installation was
successful and apply the latest updates and hotfixes available for your operating system using
Windows Update.

3. IIS 6 Installation
First of all we will install the web server which will host Moodle. We will use IIS 6, which is
included in Windows Server 2003 R2. You can install this component by starting the
“Manage your Server”-wizard in the start menu and choosing “Add or remove a role”.

After your system is successfully inspected for the required components, select “Application
Server (IIS, ASP.NET)” to add the application server component to your system. In the

2
Installing Moodle on Windows Server System

following wizard screens “Application Server Options” and “Summary of Selections” you can
simply proceed by clicking “Next”. Frontpage and ASP.NET extensions do not have to be
installed. At the end you will get a dialogue displaying a success message.

Fig. 1: Select „Application Server“ as role to add Fig. 2: Frontpage and ASP.NET do not have to be
installed

4. Microsoft SQL Server Installation


After successfully installing the Internet Information Services, the next step to fulfill is to get
your database server running. To install the Microsoft SQL Server 2005 just insert the
installation disc into your drive and wait for autorun to execute. At the startup-screen select
“Install Server components, Tools, Books Online, and samples”.

Fig. 3: SQL System Configuration Check Fig. 4: SQL Components to install

In the next step you have to accept the License Agreement. Continue until “Microsoft SQL
Server Installation Wizard” is displayed and select “Next”. Now a system configuration check
will be performed, inspecting your system to meet all requirements to install SQL Server. If
this check is successful, you can proceed to the components selection, where you can specify
which components you want to install. As a minimum, you should select the “SQL Server
Database Services” and “Workstation components, Books Online and development Tools”. In
the next dialogue, you have to select the SQL instance which should be used. The default
selection “Default Instance” is the right choice. After that, you have to define the service
account SQL server runs under. It is suggested to use a domain user account with minimal
rights for security reasons. In the following step you can configure the possible authentication

3
Installing Moodle on Windows Server System

modes with which you can authenticate against your SQL server. Please choose the “Mixed
Mode” and define a password for the database administrator account “SA”. The following
dialogues can be accepted by clicking “Next” and finally “Install”. Now the installation
routine performs the installation which should finish successfully.

Fig. 5: Define under which user SQL should run Fig. 6: Select “Mixed Authentication” and set up
administrator password

After a successful installation please run Windows Update to get the latest updates and
service packs for SQL Server.

Configuring SQL Server


After successfully installing Microsoft SQL Server, you should check if the TCP/IP
communication is enabled for the IP address used to connect to your SQL server. Start the
“SQL Server Configuration Manager” and select TCP/IP and properties from “SQL Server
2005 Network Configuration  Protocols for MSSQLSERVER”. The IP addresses used
should be marked as active. You can increase the SQL server’s security by disabing your
external address by selecting “Active=No” and just leave the local loopback ip “127.0.0.1” as
active. If you perform these changes, you have to restart the sql server in “SQL Server 2005
Services”-section by restarting the service “SQL Server (MSSQLSERVER)”.

Fig. 7: Check TCP/IP Configuration

4
Installing Moodle on Windows Server System

4.1. Create a moodle database user

To increase the security in your Moodle installation, you should not use the database
administrator account “sa” to access your database with PHP. For this reason we will now
create new user with limited permissions to access the moodle database.

Open the "SQL Server Management Studio" in the “Microsoft SQL Server 2005” folder in the
start menu and log on with the database administrator credentials you defined during the SQL
Server installation in section 0 or your normal windows credentials. If you choose “Windows
Authentication” please log on with your common local administrator credentials. If you
choose “SQL Server authentication”, your credentials are, as defined in Section 0, the “SA”
account with the password you defined.

In the left window, named object explorer, please navigate to the “Security -> Logins” folder.
Right-click on “Logins” and select “New Login…”. Enter your desired login name,
“moodle_db” for example. Select “SQL Server authentication” and enter a secure and
complex password. Please deselect the “User must change password at next login” option.

Fig. 8: Login with database administrator credentials Fig. 9: Create a moodle SQL user

4.2. Setting up database

In the next step you have to set up the database used by Moodle to store its data. Create a new
empty database by right-clicking “Databases” and select “New Database”. Choose a database
name, e.g. Moodle and select the previously created moodle_db-user as owner. Click on the
“…”-button on the right of the “Owner” textbox, “Browse…” in the next window and then
select the moodle_db user in the next window.

Configure the following settings in the “Options”-Tab:

 ANSI NULLS Enabled = true


 Quoted Identifiers Enabled = true

5
Installing Moodle on Windows Server System

Fig. 10: Create an empty database for Moodle Fig. 11: Define the database owner

At last please go back to the “Login”-folder, choose the properties of the moodle_db user by
right-clicking on it, and change “default database” to “moodle”.

After doing this, your database is ready to be used and we can proceed in the installation
process.

5. PHP5 Installation

This is an updated version of the original paper. In the original paper it was recommended to
uses an old PHP version originating from the PHP 5.1.x branch. This was motivated by the
reason that the precompiled FreeTDS extension, allowing access to Microsoft SQL Server,
was known to work only with PHP Versions from 5.1.x branch. This behaviour has changed
and precompiled FreeTDS versions for PHP 5.2.x, 5.1.x and even PHP 6 are available.

The first step is to install PHP5 in order to be able to process PHP files in IIS. You have three
possibilities to activate PHP in IIS. You can use the ISAPI-Filter, the CGI- or FastCGI-
component. The most performant way is to use the ISAPI-Filter. When you use the CGI
version, every time a PHP page is requested a single instance of PHP is started, taking up to
0.5 seconds to start up. In contrast to that, ISAPI filters are multithreaded and need less
resources. Therefore we will use it in this paper. There is an existing automated installer for
PHP5. This installer automatically configures IIS for PHP usage. So it is highly recommended
to use this automated installer.

5.1. Installing PHP5


Please download your desired PHP installer package. The most recent packages can be found
under http://www.php.net/downloads.php

There are two packages available: a zip-package and an automatic installer package using
windows installer. In this paper we will use the installer package. The most recent version
available at the moment this paper is written, was version 5.2.5 released on 15th November,
2007.

The packages of the 5.2 branch are using a new installer different from the installer used in
version 5.1, not working completely correct. After downloading the package, execute the
installer and follow the prompted instructions. You can leave the default setting “C:\Program

6
Installing Moodle on Windows Server System

Files\PHP\” for the destination folder. In the next section you have to select “IIS ISAPI
module” as the web server component of choice. You have to install the following extension
in the next window:

 MSSQL
 GD2
 Curl
 Multi-Byte String
 OpenSSL
 XML-RPC

Fig. 12: Select IIS ISAPI module as web server Fig. 13: Select the extensions to install

Expand the “Extensions” node and choose the extensions mentioned above to install. The
MSSQL will supply the sql functionality and the GD2 extension provides image manipulation
functions. Now you can proceed by clicking “Next” and “Install” in the following window. In
the end you will get a success message saying: “Completed the PHP 5.2.5 Setup Wizard”.

Since the installer is buggy at the moment, you have to correct the installation in one point.
Please start the IIS Management Console, select the website you want PHP to run and open
the website’s properties. Select the “Home Directory”-tab and click “Configuration…” in the
“Application Settings”-section. In the “Applications Extensions” section scroll down to
“.php”-entry and click “Edit…”. As you can see the filename pointing to the ISAPI-Filter-
DLL is misconfigured. Click “Browse” and navigate to the PHP installation directory and
select the correct file php5isapi.dll. Because the path contains spaces you have to put
quotation marks around the complete path.

7
Installing Moodle on Windows Server System

Fig. 14: Correct the path to the ISAPI-DLL in the Application Configuration Settings

To get PHP-pages served automatically as index pages, you just have to add the “index.php”-
files to the website’s index documents. This can be achieved in IIS Manager by selecting the
“Documents” tab in the website properties and adding “index.php” to the list of index
documents. Now you have to add a mime type for the PHP pages.

Fig. 15: Adding PHP files as index page Fig. 16: Add the PHP mime type

Select the “HTTP Headers”-tab, click “MIME Types” and then select “New…”. In the
“Extension”-box you should enter “.php” and in the “MIME type”-box “text/html”.

After this few simple steps, you have correctly installed PHP and got IIS to serve PHP pages.
The last step concerning PHP is to configure PHP itself correctly.

8
Installing Moodle on Windows Server System

5.2. Checking the PHP permissions

In all my test installations, the PHP installer configured the permission for PHP correctly. But
in the case of errors, please check if the following permissions are set up correct.

The IIS user (usually IUSR_<MACHINENAME>) needs permission to read various files and
directories, such as

 The PHP configuration: C:\Windows\php.ini


 The docroot: C:\inetpub\wwwroot
 The session temp directory: C:\Program Files\PHP\sessions

5.3. Installing FreeTDS


After installing PHP you have to install the PHP database extension FreeTDS in order to be
able to connect to Microsoft SQL Server. Please download FreeTDS for Windows as
precompiled DLL from one of the following links

Precompiled FreeTDS DLL for PHP 5.1


Precompiled FreeTDS DLL for PHP 5.2

and save it to your PHP Extension directory, in our case “C:\Program Files\PHP\ext”.

FreeTDS requires the .NET Framework v1.1 to be installed. You can download it from the
Microsoft website along with its service pack. By using Windows Server 2003 R2 the NET
1.1 Framework is already preinstalled.

Please set the file permissions for php_dblib.dll to the same file permissions assigned to
php5ts.dll in the PHP directory. Normally the permissions should be automatically inherited.

Now edit your PHP.ini in C:\Windows and add this line in the [extensions]-section:

extension=php_dblib.dll

Fig. 17: Set file permissions Fig. 18: Setting PHP Extensions directory

9
Installing Moodle on Windows Server System

Now you need to create a configuration file for FreeTDS. Create a file called C:\freetds.conf
using a text editor with the following content:

[global]
host = 127.0.0.1
port = 1433
client charset = UTF-8
tds version = 7.0
text size = 20971520

Fig. 19: Enable FreeTDS as database extension Fig. 20: Create the FreeTDS configuration file

5.4. Configuring PHP

At the moment no PHP configuration file will be loaded. Please copy the php.ini file located
in folder “C:\Program Files\PHP” to the directory “C:\WINDOWS”.

You have to edit certain entries in the php.ini to configure your PHP installation correct.
Please open the php.ini in an editor and change at least the following entries:

 doc_root = “C:\inetpub\wwwroot\”
 extension_dir = “C:\Program Files\PHP\ext”

Furthermore you have to configure the location where PHP saves the session data. Create a
directory “C:\Program Files\PHP\sessions” with read and write permissions for the IIS user
IUSR_<MACHINENAME> and set the following php.ini entry:

 session.save_path=”C:\Program Files\PHP\sessions”

You should at least have three activated extensions:

 The MSSQL extension: extension=php_dblib.dll


 The FreeTDS extensions: extension=php_mssql.dll
 The GD2 extension: extension=php_gd2.dll
 The Curl extension extension=php_curl.dll
 The MB String extension extension=php_mbstring.dll
 The OpenSSL extension extension=php_openssl.dll

10
Installing Moodle on Windows Server System

 The XML RPC extension extension=php_xmlrpc.dll

5.5. Checking the PHP Installation

Now restart your IIS by right-clicking the computer name in the IIS Manager, select “All
Tasks” and click “Restart IIS…”. Please check if PHP is running by using an index file
index.php with the following content:

<html>
<head>
<title>PHP test</title>
</head>
<body>
<?php
phpinfo();
?>
</body>
</html>

Copy this file to C:\inetpub\wwwroot\ and browse to http://localhost/index.php. Now you


should see detailed information about your PHP installation. Please pay special attention to
the entry “Loaded configuration the file”, which should have the value “php.ini” and the
section “mssql”, showing that the mssql extension was successfully loaded.

Fig. 21: Adding PHP files as index page Fig. 22: The PHP 5 “about page”

6. Moodle Installation
6.1. Preparations
Now the Moodle installation finally takes place. Please download the latest Moodle packages
available at http://downloads.moodle.org. Extract the files to the desired directory
“C:\inetpub\wwwroot\moodle”.

Please check that this directory is writeable to the IIS user IUSR_<MACHINENAME>.
Please give this user write permissions to moodle directory by right-clicking the directory,
selecting properties, changing to the “Security” tab and adding the “modify” permission for
IUSR_<MACHINENAME>.

11
Installing Moodle on Windows Server System

Please also create a moodle data directory “C:\inetpub\moodledata” readable and writeable for
IUSR_<MACHINENAME> by just adding the “modify” permission as mentioned above.

6.2. Installation

Now you can start the installation process by opening: http://localhost/<Moodle-directory>/.


Please follow the instructions and configure Moodle as desired for your environment. You
will have to configure the language you wish to use and the web address Moodle is available.
Here you have to configure the writeable Moodle data directory “C:\inetpub\moodledata”.
Now you get to the database configuration.

Fig. 23: Moodle language selection

Fig. 24: Configuring installation pathes

The most important part of this whitepaper is the database configuration. In the fourth
installation step select “SQL*Server (mssql)” as database server type. Select the server host
address “127.0.0.1” for security reasons and the database “moodle_db” you created in section
4.2. Enter “moodle_db” as username and the password chosen during the installation of SQL
server.

Fig. 25: Moodle database configuration Fig. 26: Moodle environment check

In the next step your environment will be checked whether all requirements are fulfilled. After
that, you have the possibility to download language packs if further languages are needed. If

12
Installing Moodle on Windows Server System

Moodle does not have the possibility to write to the www directory, you will be asked to
create the needed Moodle configuration file and paste the given content into it. In the next
steps the databases and tables will be created. Then the installation is complete and you are
about to configure your user preferences.

Now you can complete the installation with your own preferences and start to use Moodle
hosted on a Windows Server.

13

You might also like