Part 1 - Setup PHP on the web server

Note

Some of the variables in the PHP.INI file are assigned variables of 0 or 1. For us humans 0 = Off and 1 = On;

  1. Download the latest Non-thread-safe version of the PHP zip package under the 'Windows Binaries' heading on the http://www.php.net/downloads.php web site. Don't download the 'PHP 5.2.6 installer' package - if you choose to install PHP using the Windows installer package then this guide won't be all that useful to you. I haven't used or tested the Windows installer method of installing PHP more than once or twice and this guide was not written for the Windows installer. Installing Moodle and PHP the manual way gives you complete control of the whole process and it is the recommended way to do the installation on Windows.
  2. Note

    Most of the PHP setup and installation guides on the Internet will tell you to also download and install the PECL extensions for PHP and then load them into memory by enabling them in the php.inp file. However, it is not necessary to load all these extensions unless you specifically need their functionality. The general Moodle development policy is to make Moodle standalone and independent of the PECL and PEAR extensions. Martin Dougimas, the lead developer of Moodle, explains why in this message on the Moodle General Developer Forum. Where the Moodle developers have used some of the extensions in Moodle they have included them as part of the core Moodle code, so it is not necessary for you to download the whole PEAR archive and load the individual libraries in the Dynamic Extensions section of the php.ini file. The PEAR extensions that are used in the Moodle code are listed in the Moodle Credits.

    Since we are going to be using the FreeTDS library to connect to a Microsoft SQL Server 2005 database we do have to load at least one extension in the php.ini file. But we'll get to that in Part 5.

    What's the difference between PECL and PEAR?

    PECL is a repository of compiled PHP extensions, while PEAR is a repository of PHP classes. They extend the functionality of the core PHP engine. It's like putting mag wheels on your car, but a lot more useful. Extensions are written in C and loaded with the PHP engine when it starts up, while classes are written in PHP and included into your code.

  3. Create a new folder on the web server for the PHP application files. In this guide we'll use C:\PHP.

  4. Note

    You should install PHP in a path that does not contain any spaces, e.g. C:\PHP. There have been reports that using a path that contains spaces (e.g. C:\Program Files\PHP) causes PHP to generate "the specified module could not be found" errors.

  5. Extract the PHP zip archive to the C:\PHP folder. Several sub folders will be created. You should leave these as they are created.
  6. Rename the php.ini-recommended file in C:\PHP to php.ini and make the following changes:
    1. Uncomment the cgi.force_redirect line and set it to 0: cgi.force_redirect = 0
    2. Set the safe_mode variable to OFF: safe_mode = Off
    3. Set the memory_limit variable to a reasonable value. The more the better, but this value is dependant on the amount of memory that you have available on your Moodle server.
    4. Set the session.save_handler variable to variable to FILES: session.save_handler = files
    5. Set the magic_quotes_gpc variable to OFF: magic_quotes_gpc = Off. If you turn this variable on the apostrophe character will be escaped in Moodle, e.g. all instances of 's will be replaced with \'s. This could cause unnecessary confusion among your users who aren't expecting the backslash character and they won't know how to handle it or where it came from. Additionally, magic_quotes is deprecated as of PHP 6 so you should get used to not relying on it for anything. See http://php.net/magic_quotes for more details.
    6. Set the magic_quotes_runtime variable to OFF: magic_quotes_runtime = Off
    7. Set the file_uploads variable to ON: file_uploads = On
    8. Set the session.auto_start variable to OFF: session.auto_start = 0
    9. Set the session.bug_compat_warn variable to OFF: session.bug_compat_warn = 0
  7. Do not enable the doc_root field. When doc_root is disabled each site in IIS will use it own root as the doc_root value for PHP scripts.
  8. Create a session state folder called Sessions in your PHP directory, C:\PHP\Sessions.
  9. Point the session.save_path variable in the php.ini file to this session state folder: session.save_path = "C:\PHP\Sessions"
  10. Set the extension_dir variable to point to the PHP extensions folder: extension_dir = "C:\PHP\ext"
  11. If you are going to be using Active Directory to authenticate your users then you need to enable the php_ldap.dll extension in the php.ini file. To do this add the following line in the Dynamic Extensions section of the php.ini file:
    extension=php_ldap.dll
  12. If you are going to be using Moodle Networking you must also enable the following extensions:
    • extension=php_curl.dll
    • extension=php_openssl.dll
    • extension=php_xmlrpc.dll
    • extension=php_mbstring.dll
  13. Add C:\PHP to the server's PATH environment variable. Click here for more details on how to do this.
  14. Add a new key to the Windows Registry called IniFilePath under the HKEY_LOCAL_MACHINE branch and set the string value to C:\PHP.

    HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath = C:\PHP.

    Notes

    Adding the above Registry key will ensure that PHP is loaded with the correct PHP.INI file. Some computers have various php.ini files hidden away in various Windows or Systems folders. You can run the PHPInfo() function to check which php.ini file is loaded on your server.

    If you are not installing PHP in the C:\PHP path then you must specify the correct path in the IniFilePath assignment.

The remaining steps below are optional and not absolutely necessary if Moodle is the only php application that you are running on your server.

Install browser identification function (browscap.ini)

  1. If you want to use the browser identification features of php then download the php_browscap.ini file from http://browsers.garykeith.com/downloads.asp and save it to the C:\PHP\extras\ folder.
  2. Add the full path to the browscap variable in to the php.ini file: browscap=C:\PHP\extras\browscap.ini

    Note

    Be sure to read and abide by the Browscap Terms of Use. The author has licenced this work under a Creative Commons Attribution Non-Commercial license. If you plan to use it for commercial use, ask him for permission first. The main reason for this is that the author needs to ensure that your usage of the Browscap file won't put a heavy load on his server, and Moodle will not.

Install a PHP Accelerator (Alternative PHP Cache)

  1. Download the Alternative PHP Cache (APC) from the PECL web site.
  2. Enable this APC extension by adding the following line in the Dynamic Extensions section of the php.ini file:
    extension=php_apc.dll

    Note

    APC is a PHP Accelerator. It stores PHP pages in RAM and reduces hard disk activity. This makes a real difference to the performance in Moodle and, according to the Moodle developers, you should be able to achieve a 50% increase in system capacity and your CPU will be 50% less busy. More details on how to install APC are available on docs.moodle.org.

PHP is now installed on the server. You now need to install FastCGI.


Back | Home | Next
Contact