Internet Information Services

From MoodleDocs

Internet Information Services (IIS) is the web server software bundled with Windows Server, as well as certain client versions of Windows. Please note Apache web server has much better community support and there are usually fewer problems when running Moodle on Apache. Windows OS is not suitable for large installations, please consider using Linux or other unix-like operating systems instead.

IIS installation steps (Windows 11 and some earlier versions)

Turn Windows features on or off
  1. Open the Windows Settings in Windows 11. Search for "Control Panel" and open the app. In earlier versions of Windows, this app may be located elsewhere.
  2. In the Control Panel at the top right hand side of the window, search for "Programs" and you will find "Programs and Features."
  3. Under this option, click on "Turn Windows features on or off."
  4. Tick "Internet Information Services" and under that submenu also tick "Internet Information Services / World Wide Web Services / Application Development Features / CGI" which appears when you click on the "+" to expand the menus.
  5. In a new browser window on the Windows machine, visiting "localhost" should display the welcome screen for IIS.

Note: The Microsoft Web Platform Installer is no longer supported by Microsoft.

PHP installation

As mentioned above, the official MS Platform installer has been discontinued and is no longer supported. Please follow the steps manually:

  1. Download latest version of PHP Non Thread Safe that is supported by the current Moodle version from http://windows.php.net/download/. In Moodle 4.5, PHP 8.1.0 or higher is required.
  2. Extract the Zip file to a directory such as C:\PHP\
  3. Download the appropriate version of Visual C++ Redistributable for Visual Studio 2015-2022 x64 or x86 version and install it. You may need to restart your computer after installing this software.

Registering FastCGI handler

Settings for adding the PHP-FastCGI handler
  1. Open the Internet Information Service (IIS) Manager. You can find this by clicking on the search icon in the Windows taskbar and typing in "Internet Information Service" in the search bar.
  2. Double click on the Handler Mappings icon.
  3. In the Actions panel on the right side of the window, choose Add Module Mapping... from the list.

Fill in the settings as follows:

  • Request path: Type *.php to handle all PHP files.
  • Module: Choose FastCgiModule from the dropdown.
  • Executable: Find the php-cgi.exe file in the extracted PHP directory. For example, "C:\PHP\php-cgi.exe".
  • Name: Enter a unique name for the handler mapping in the Name box. For example, "PHP-FastCGI".
  • Click Request Restrictions
  • Select Invoke handler only if request is mapped to.
  • Click to select the File or Folder option.
  • Click OK to save the Restrictions.
  • Click OK to save the handler configuration.
  • If you are prompted to create a FastCGI application in the Add Module Mapping dialog box, click Yes.

After saving, go back and 'Edit' the FastCGI application and increase the Activity timeout to at least one hour. This will prevent Moodle scripts from failing during long processes.

PHP configuration steps

  1. In the PHP directory you created, find the php.ini-production file and copy it to php.ini in the same folder.
  2. Edit the copied php.ini file (using Notepad or your favorite editor) and make the following changes:
  • Activate the following extensions by removing the ; at the beginning of the line in php.ini.
  • Uncomment the curl extension.
  • Uncomment the fileinfo extension.
  • Uncomment the gd extension.
  • Uncomment the intl extension.
  • Uncomment the mbstring extension.
  • Uncomment the exif extension.
  • Uncomment the mysqli extension. Use this if your DB is in MySQL.
  • Uncomment the openssl extension.
  • Uncomment the pgsql extension. Use this if your DB is in PostgreSQL.
  • Uncomment the soap extension.
  • Uncomment the sodium extension.
  • Uncomment the zend_extension=opcache line.
  • Uncomment the cgi.force_redirect = 0 and make sure the value is 0.
  • Uncomment the fastcgi.impersonate = 1 and make sure the value is 1.
  • Uncomment the max_input_vars = 1000 line and change the value to at least 5000 which is required by Moodle.

IIS configuration steps

  1. Setup URL rewriting described below
  2. Configure IIS to show detailed error pages.
  3. Set very long CGI timeout - 1 hour or better more.
  4. In IIS Manager add Moodle dirroot directory as a new virtual directory or set it as site directory

Default Document

  1. Make sure to add "index.php" as a Default document.

Slasharguments

The function slash arguments is required for various features in Moodle to work correctly, as described in Using slash arguments.

IIS 7 should support relative path arguments by default. If it does not work try enabling the following in php.ini

cgi.fix_pathinfo = 1

URL rewriting

Rewrite rule - Internet Information Services (IIS) Manager.png

In some versions of IIS, the Rewrite module is not included by default. Download either the x86 or x64 version depending on your version of Windows and install it. You may need to restart IIS and reopen the IIS Manager in order to see the module.

Add following rewrite rule to enable support for unicode file names in Moodle and to work around internal file length limitation breaking YUI file serving:

  • Use Blank rule to add the new rule.
  • Give the rule a name. For example: Moodle rewrite.
  • Matches the Pattern - Regular Expressions - ^([^\?]+?\.php)(\/.+)$
  • Action - Rewrite - {R:1}\?file={R:2}
  • Append query string - enabled
  • Stop processing of subsequent rules - enabled

Click on Apply in the right hand panel to save the rule and apply it.

Optional UTF-8 file name fix

By default IIS is unable to handle unicode characters in files uploaded into Moodle. This may result in not working JavaScript on Moodle site (impossible to expand navigation, etc.) or broken CSS styles.

See Using UTF-8 Encoding for Server Variables and How to get UTF-8 Encoding support in IIS 7.5 in Windows 7 and Windows Server 2008 R2 with the KB 2277918 hotfix.

Execute: reg add HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\w3svc\Parameters /v FastCGIUtf8ServerVariables /t REG_MULTI_SZ /d REQUEST_URI\0PATH_INFO

CGI timeouts

By default IIS is configured to stop execution of any PHP script after 5 minutes of activity, this interferes with long running Moodle scripts such as upgrade or cron. The timeout should be increased to at least one hour.

Directory permissions

The default IIS account is IIS_IUSRS, make sure it has appropriate access right to Moodle dirroot (read only) and dataroot (read/write) directories.

Handling 40x errors

This enables missing files to be themed by Moodle

1. Open the “Internet Information Services (IIS) Manager” tab. This is located on the Task Bar below “Server Manager,” and then underneath “Tools.”

2. Identify the Moodle website. Go to the “Connections” pane and click the plus sign (+) next to your server name to expand it. Then expand “Sites.” Next, go to Moodle website.

3. Open Error Pages. Double-click the “Error Pages” icon located in the home pane; click “Edit.”

4. Enter the HTTP Status Code. When you see the dialog box “Edit Custom Error Page,” enter “404” underneath “Status Code.”

5. Select “Execute a URL on this Site.” In the same dialog box, select “Execute a URL on this site” so that you can serve your custom page.

6. Enter the URL. Within the text box “URL (relative to the site root),” type "/error/index.php" and then click “OK.”

7. Select “Edit Feature Settings.” Once you hit “OK,” right-click on the 404 error and select “Edit Feature Settings.”

8. Choose “Custom Error Page,” and then click “OK.” After you click this last OK, your new page should be live and ready.

Optional (security enhancement)

You can repeat the same procedure described above for 403 error and redirect it to "/error/index.php?code=404".

This sends any 403 from IIS through to the same page but also overrides the HTTP status with 404 instead for better security.

Hiding internal paths

IIS includes the URL Rewrite module. You can use this extension to provide rules for IIS to rewrite incoming URL requests.

Moodle and many other PHP applications currently ship with rewrite rules as part of their .htaccess file. These rules tell Apache's mod_rewrite how and when to rewrite incoming requests. The IIS URL Rewrite module can read these rules and translate them into URL Rewrite rules.

 
RewriteEngine On
 
RewriteRule "(\/vendor\/)" - [F]
RewriteRule "(\/node_modules\/)" - [F]
RewriteRule "(^|/)\.(?!well-known\/)" - [F]
RewriteRule "(composer\.json)" - [F]
RewriteRule "(\.lock)" - [F]
RewriteRule "(\/environment.xml)" - [F]
Options -Indexes
RewriteRule "(\/install.xml)" - [F]
RewriteRule "(\/README)" - [F]
RewriteRule "(\/readme)" - [F]
RewriteRule "(\/moodle_readme)" - [F]
RewriteRule "(\/upgrade\.txt)" - [F]
RewriteRule "(phpunit\.xml\.dist)" - [F]
RewriteRule "(\/tests\/behat\/)" - [F]
RewriteRule "(\/fixtures\/)" - [F]

To convert these rules to IIS URL rewrite–specific format:

1. Start IIS Manager.

2. On the left, in the Connections pane, select Default Web Site.

3. On the right, in Features View, click URL Rewrite.

4. On the right, in the Actions pane, click Import Rules.

5. Copy the example mod_rewrite rules above and paste them into the Rewrite rules text box.

6. The Tree View tab of the Converted Rules box instantly shows the result of the conversion. You can also click the XML View tab to see how the rules are stored in the Web.config file.

For more information you can check this link: https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/importing-apache-modrewrite-rules

Debugging problems

By default, IIS uses custom error pages that intentionally hide error details on production sites:

IIS default error message

But when you're diagnosing problems in Moodle that's not very useful. You can temporarily disable these default error messages in IIS so that you see a specific Moodle error message. To achieve that set the "existingResponse" setting for Custom Error Pages in IIS to “PassThrough” for your Moodle site. The result will be that Moodle displays a more specific message about the error when a problem occurs:

Useful error message

The generic IIS "404" error message which normally does not reveal any details about the problem will no longer be displayed.

The debugging option in Settings>Site administration>Development>Debugging should also be enabled so that you see the debug messages.

See also