Microsoft IIS Administration on Nano Server
One of the driving forces behind the development of the IIS Administration API was Nano Server, a new headless variant of Windows Server 2016. This API allows us to provide a web based management UI. This post will cover the experience of getting IIS Administration up and running on Nano Server.
Enabling IIS
The first step to installing IIS Administration on a Nano machine is to make sure that the server has IIS enabled. We can enable IIS through the use of a package provider. First we must install the package provider, then install IIS, and finally restart the machine. We achieve this with the following PowerShell commands.
# Version of Nano Server used for this demo
[<NanoServerIPAddress>]: PS C:\> [System.Environment]::OSVersion
# Platform Version
# -------- -------
# Win32NT 10.0.14300.0
# https://github.com/OneGet/NanoServerPackage
Save-Module -Path 'C:\Program Files\WindowsPowerShell\Modules\' -Name NanoServerPackage -minimumVersion 1.0.1.0
Import-PackageProvider NanoServerPackage
Install-NanoServerPackage -Name Microsoft-NanoServer-IIS-Package
Start-Service W3SVC
Verify
We can verify that IIS is installed and running on the machine by executing the following command.
Get-Service W3SVC | Select Status
# Status
# ------
# Running
Enable Dependencies
After we have installed IIS, we can enable the IIS components that IIS Administration depends on.
Pitfall: To avoid an issue with enabling IIS components, ensure that all desired components are enabled before making any modifications to the applicationHost.config file.
# Backup applicationHost.config
Copy-Item C:\Windows\System32\inetsrv\config\applicationHost.config C:\Windows\System32\inetsrv\config\applicationHost_BeforeIisAdministration.config
# Enable required features
Enable-WindowsOptionalFeature -Online -FeatureName "IIS-WindowsAuthentication"
Enable-WindowsOptionalFeature -Online -FeatureName "IIS-URLAuthorization"
# Optionally, take the chance to enable all IIS features
# Get-WindowsOptionalFeature -Online | where {$_.FeatureName -match "IIS-" -and $_.State -eq [Microsoft.Dism.Commands.FeatureState]::Disabled} | % {Enable-WindowsOptionalFeature -Online -FeatureName $_.FeatureName}
Installing .NET Core
In order to run IIS Administration, the machine must be set up to host .NET Core applications. There is a tutorial for installing .NET Core tailored specifically for Nano Server available at https://docs.asp.net/en/latest/tutorials/nano-server.html#installing-the-asp-net-core-module-ancm. The relevant sections are “Installing the ASP.NET Core Module (ANCM)” and “Installing .NET Core Framework.”
Copying the ASP.NET Core Module
To make copying the ASP.NET Core Module to the Nano Server machine easier, use the Copy-Item command combined with a PowerShell session.
$s = New-PSSession -ComputerName "<NanoServerIPAddress>" -UseSSL -Credential "<hostname>\Administrator"
Copy-Item C:\windows\system32\inetsrv\aspnetcore.dll -Destination c:\windows\system32\inetsrv\ -ToSession $s
Copy-Item C:\windows\system32\inetsrv\config\schema\aspnetcore_schema.xml -Destination C:\windows\system32\inetsrv\config\schema\ -ToSession $s
Adding .NET Core to Path
At this point .NET Core should be installed on the machine. Next we want to put the dotnet executable on the path so that .NET Core applications can be loaded by IIS without any manual intervention.
Note: Take caution when altering the PATH environment variable. This script stores the old value of the PATH environment variable for safe keeping.
# Assuming dotnet was placed at C:\Program Files\dotnet
$env:Path | Out-File "C:\PathBeforeDotNet.txt"
setx PATH "$($env:Path);C:\Program Files\dotnet" /m
# Restart computer to update path in IIS. Services' environments are not updated until system restart.
Restart-Computer –Confirm
Verify
At this stage we should verify that .NET Core has been added to the path correctly. We can do this by executing the following command.
Get-Command 'dotnet'
# Application dotnet.exe 1.0.1.4500 C:\Program Files\dotnet\dotnet.exe
Then we can ensure that .NET Core is installed correctly by running the dotnet executable. Below is a snippet of the output of dotnet when executed alone.
dotnet
# Microsoft .NET Core Shared Framework Host
# Version : 1.0.1
# Build : cee57bf6c981237d80aa1631cfe83cb9ba329f12
# Usage: dotnet [common-options] [[options] path-to-application]
Opening the Firewall for Remote Administration
We want the API to be accessible by remote machines, therefore we need to allow it through the firewall. The default port is 55539 and we can open it up using PowerShell.
New-NetFirewallRule -Name "IIS Administration" -DisplayName "Allow IIS Administration on TCP/55539" -Protocol TCP -LocalPort 55539 -Action Allow -Enabled True
Visual Studio 2015 C++ Redistributable
To install the VS 2015 runtime libraries on Nano Server, install it on a local machine (x64 required) and then copy it over. This process is similar to the ASP.NET Core Module. The VS 2015 x64 C++ redistributable package can be obtained from https://go.microsoft.com/fwlink/?LinkID=827997. If the VS 2015 runtime is not installed, installation of the API will fail when trying to start the service.
First, on the Nano Server machine, check if the VS 2015 runtime is already installed
Write-Host "Visual Studio 2015 C++ Redistributable already installed?"
Write-Host "$(Test-Path C:\Windows\System32\vcruntime140.dll)"
If it is not installed, install it on the local machine and copy it over
# $s = New-PSSession -ComputerName "<NanoServerIPAddress>" -UseSSL -Credential "<hostname>\Administrator"
Copy-Item C:\Windows\System32\vcruntime140.dll -Destination C:\Windows\System32\ -ToSession $s
Installing the Microsoft IIS Administration API
The API can be obtained as a ZIP archive from https://github.com/Microsoft/IIS.Administration/releases/download/v1.0.36/IIS.Administration.zip. In this format, the API can be installed via a PowerShell script. Run this script to automatically download the archive and extract it to C:\IIS.Adminstration.
Download the Archive
$SourcePath = "https://github.com/Microsoft/IIS.Administration/releases/download/v1.1.1/IIS.Administration.zip"
$DestinationPath = "C:\IIS.Administration"
$EditionId = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name 'EditionID').EditionId
if ($EditionId -eq "ServerDataCenterNano") {
$TempPath = [System.IO.Path]::GetTempFileName()
if (($SourcePath -as [System.URI]).AbsoluteURI -ne $null) {
Invoke-WebRequest -Uri $SourcePath -OutFile $TempPath
}
else {
throw "Cannot copy from $SourcePath"
}
[System.IO.Compression.ZipFile]::ExtractToDirectory($TempPath, $DestinationPath)
Remove-Item $TempPath
}
Install
Once the archive has been downloaded, assuming the default location was used, you can install the IIS Administration API by running the included setup script.
C:\IIS.Administration\setup\setup.ps1 Install –Verbose