Internet Information Services

From MoodleDocs
(Redirected from IIS)

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 because PHP is limited to 32bit even in 64bit Windows, please consider using Linux or other unix-like operating systems instead.

IIS installation steps (Windows 7 and above)

  1. Go to Control panel, click on Programs and Turn Windows features on or off
  2. Tick "Internet Information Services" and "Internet Information Services / Application Development Features / CGI"
  3. Install Microsoft Web Platform Installer

PHP installation steps

It is strongly recommended to use only the official MS Platform installer, it automatically installs all necessary components and facilitates easy configuration with PHP manager. Manual installation attempts often fail or may not allow Moodle to function properly. Unfortunately MS does not usually distribute up-to-date version of PHP, you may need to download them manually.

  1. Install Microsoft Web Platform Installer
  2. Install latest PHP 7.2.x using Web Platform Installer
  3. [Optional] Install URL Rewrite 2.0 using Web Platform Installer

Optionally you may install the required components manually:

  1. Download PHP manager for IIS and install it
  2. Download latest PHP 7.2.x VC15 x64 Non Thread Safe from http://windows.php.net/download/. On 64bit Windows you should go for x64; otherwise, x86
  3. Extract the Zip file to a directory such as C:\PHP\
  4. Install the Visual C++ Redistributable for Visual Studio 2017 [1] - on 64bit Windows install both x86 and x64
  5. Open the Internet Information Service (IIS) Manager - right click on This computer and select Manage
  6. Click on PHP Manager icon
  7. Register new PHP version - select C:\PHP\php-cgi.exe

Warning: PHP needs to be configured via FastCGI in IIS, older CGI interface is known to have problems with some file names.

PHP configuration steps

  1. Set PHP configuration to values recommended by PHP Manager
  2. Enable required extensions in the PHP manager: php_intl.dll, php_pgsql.dll
  3. Enable OPcache extension
  4. Set your timezone in PHP.ini
  5. Set appropriate memory limits in PHP.ini

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

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

If you can not modify registry as described below you may try manual configuration of rewrite rules, the PHP installation via Microsoft Web Platform Installer installs necessary URL Rewrite 2.0 module.

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


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:

  • Matches the Pattern - Regular Expressions - ^([^\?]+?\.php)(\/.+)$
  • Action - Rewrite - {R:1}\?file={R:2}
  • Append query string - enabled
  • Stop processing of subsequent rules - enabled

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