Nano Server: Deploying PHP 7.0.6 on Internet Information Services (IIS) Web Server
1. Introduction
In this article, we will demonstrate deploying PHP capabilities to Internet Information Services (IIS) on a Windows Server 2016 Technical Preview 4 Nano Server and allowing Nano Server to host PHP 7.0.6 application.
2. Deploying PHP with Web Server (IIS) on Nano Server Requirements
You will need the followings to host PHP 7.0.6 application on Nano Server;
- Microsoft-NanoServer-IIS-Package
- Microsoft-OneCore-ReverseForwarders-Package (Not required since Windows Server 2016 GA/RTM)
- PHP 7.0.6 Non Thread Safe x64
- Visual C++ Redistributable for Visual Studio 2015 x64
3. Getting Started with PHP with Web Server (IIS) on Nano Server
In order to publish an PHP 7.0.6 application, we will require the Nano Server to have Internet Information Services (IIS) capability and you can refer to the following article on below;
3.1. Deploying a new Nano Server with ReverseForwarder and Web Server (IIS) packages
For those who want to start a fresh Nano Server, the PowerShell example in creating a Nano Server with the basic package requirements below:
# Import New-NanoServerImage PowerShell Module for Technical Preview 4
Import-Module `
-Global C:\NanoServer\NanoServerImageGenerator.psm1 ;
# Create New Basic NanoServer Image with IIS for Technical Preview 4 with IIS and ReverseForwarders Package
New-NanoServerImage `
-MediaPath "Z:" `
-BasePath "C:\NanoServer\Base" `
-TargetPath "C:\NanoServer\WS16TP4NSIIS1\WS16TP4NSIIS1.vhd" `
-EnableRemoteManagementPort `
-Language "en-us" `
-GuestDrivers `
-DriversPath "C:\NanoServer\VMware-Drivers" `
-Packages "Microsoft-NanoServer-IIS-Package, Microsoft-OneCore-ReverseForwarders-Package" `
-Ipv4Address "192.168.100.25" `
-Ipv4SubnetMask "255.255.255.0" `
-Ipv4Gateway "192.168.100.3" `
-DomainBlobPath "C:\NanoServer\WS16TP4NSIIS1.djoin" `
-AdministratorPassword (ConvertTo-SecureString -String "Password" -AsPlainText -Force) ;
3.2. Deploying ReverseForwarders package for Web Server (IIS) on existing Nano Server
If you already have an existing Nano Server with Internet Information Services (IIS) package but are missing the ReverseForwarders package, you can follow the example starting from here below:
# Establish a remote PowerShell Session to the Nano Server
Enter-PSSession `
-ComputerName 192.168.100.24 `
-Credential (New-Object `
-TypeName System.Management.Automation.PSCredential `
-ArgumentList "192.168.100.24\Administrator", `
(ConvertTo-SecureString `
-String "Password" `
-AsPlainText `
-Force) `
) ;
3.2.1. Create the Packages folder to contain the ReverseForwarder Packages
Firstly, we will need to create the Packages folder structure to contain the CAB files.
# Create a Packages folder in Nano Server
New-Item `
-Path "C:\Packages" `
-Type directory ;
# Create an en-us language folder for Packages folder in Nano Server
New-Item `
-Path "C:\Packages\en-us" `
-Type directory ;
Now, we need to exit the current PSSession from your remote Nano Server so that we can copy the CAB files from your mounted Windows Server 2016 Technical Preview 4 ISO image on the management server.
# Exit PowerShell Session
Exit-PSSession ;
Verify you have the PowerShell version 5 on your management server so that you will have the new capability for Copy-Item to copy files using UNC path to the remote Nano Server.
# Show PowerShell version for Copy-Item
$PSVersionTable ;
3.2.2. Copy the Packages from Management Server to Nano Server remotely
With PowerShell version 5, you will be able to using Copy-Item cmdlet to copy the files from your management server to the remote Nano Server using UNC path. You will need to ensure that your remote Nano Server firewall is enabled to allow File and Printer Sharing.
# Copy ReverseForwarders Package from DVD to Nano Server remotely
Copy-Item `
-Path "D:\NanoServer\Packages\Microsoft-OneCore-ReverseForwarders-Package.cab" `
-Destination "\192.168.100.24\C$\Packages" ;
# Copy ReverseForwarders Package from DVD to Nano Server remotely
Copy-Item `
-Path "D:\NanoServer\Packages\en-us\Microsoft-OneCore-ReverseForwarders-Package.cab" `
-Destination "\192.168.100.24\C$\Packages\en-us" ;
3.2.3. Add ReverseForwarder packages to Nano Server
Once we have copied the 2 ReverseForwarders CAB files, you will need to connect to the Nano Server remotely using Enter-PSSession and use DISM to add the package to your existing Nano Server.
# Add ReverseForwarder package to Nano Server
dism /online /add-package /packagepath:C:\Packages\Microsoft-OneCore-ReverseForwarders-Package.cab
Next, you will require to add the en-us language version of ReverseForwarders package.
# Add en-us language ReverseForwarder package to Nano Server
dism /online /add-package /packagepath:C:\Packages\en-us\Microsoft-OneCore-ReverseForwarders-Package.cab
# Restart the Nano Server remotely
Restart-Computer -Force ;
3.3. Deploying PHP on Web Server (IIS) on Nano Server
3.3.1. Download PHP Non Thread Safe x64 from a Management Server
Let's download the PHP 7.0.6 Non Thread Safe to the temporary folder in Management Server so that we can extract the files.
# Create a Temp folder
New-Item `
-Path "C:\Temp" `
-Type directory ;
# Download PHP 7.0.6 Non Thread Safe x64 to C:\Temp
Invoke-WebRequest `
-Uri "http://windows.php.net/downloads/releases/php-7.0.6-nts-Win32-VC14-x64.zip" `
-OutFile "C:\Temp\php-7.0.6-nts-Win32-VC14-x64.zip" ;
# Verify PHP 7.0.6 Non Thread Safe x64 has been downloaded
Get-ChildItem `
-Path "C:\Temp\php-7.0.6-nts-Win32-VC14-x64.zip" ;
3.3.2. Extract PHP Non Thread Safe compressed file content on Management Server
After the download, we will extract the PHP 7.0.6 to a temporary location and copy the content to the Nano Server remotely.
# Extract PHP 7.0.6 Non Thread Safe Compressed Files
Add-Type -Assembly “System.IO.Compression.FileSystem” ;
[IO.Compression.ZipFile]::ExtractToDirectory("C:\Temp\php-7.0.6-nts-Win32-VC14-x64.zip", "C:\Temp\PHP") ;
3.3.3. Copy PHP 7.0.6 Non Thread Safe content to Nano Server remotely
Now, you will copy those PHP 7.0.6 files to the appropriate location on Nano Server.
# Copy the PHP 7.0.6 Non Thread Safe content
# from extracted folder to Nano Server remotely
Copy-Item `
-Path "C:\Temp\PHP" `
-Destination "\192.168.100.24\C$\Temp" ;
3.3.4. Download Visual C++ Redistributable for Visual Studio 2015 from a Management Server
With PHP files copied to Nano Server, you will find that you will not be able to execute php.exe properly because it is missing the vcruntime140.dll file in %WinDir%\System32 folder. Therefore, we will have to obtain the vcruntime140.dll from the Visual C++ Redistributable for Visual Studio 2015 installed on a Management Server and copied the file across to the Nano Server.
# Download Visual C++ Redistributable for Visual Studio 2015 x64 to C:\Temp
Invoke-WebRequest `
-Uri "https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe" `
-OutFile "C:\Temp\vc_redist.x64.exe" ;
# Verify Visual C++ Redistributable for Visual Studio 2015 x64 has been downloaded
Get-ChildItem `
-Path "C:\Temp\vc_redist.x64.exe" ;
# Install Visual C++ Redistributable for Visual Studio 2015 x64 on Management Server
Start-Process `
-FilePath "C:\Temp\vc_redist.x64.exe" `
-ArgumentList "/install /quiet" `
-Wait `
-PassThru ;
# Verify vcruntime140.dll has been installed into Management Server
Get-ChildItem `
-Path "C:\Windows\System32\vcruntime140.dll" ;
# Copy the vcruntime140.dll from Management Server
# to Nano Server remotely
Copy-Item `
-Path "C:\Windows\System32\vcruntime140.dll" `
-Destination "\192.168.100.24\C$\Windows\System32" ;
3.3.5. Verify PHP Non Thread Safe is working on Nano Server
Now that we have vcruntime140.dll copied to the %WinDir%\System32 folder in Nano Server, we can connect to the Nano Server remotely using Enter-PSSession and verify that PHP.exe is able to execute now.
3.3.6. Configure the IIS for PHP
After testing PHP.exe is working, we will have to configure the IIS to work with PHP to handle any PHP requests on the Nano Server using the IIS Administration PowerShell Module for the IIS Cmdlets.
# Import IIS Administration PowerShell Module
Import-Module IISAdministration ;
# Add index.php as default document
Get-IISConfigSection -SectionPath "system.webServer/defaultDocument" | `
Get-IISConfigElement `
-ChildElementName "files" | `
Get-IISConfigCollection | `
New-IISConfigCollectionElement `
-ConfigAttribute @{"value"="index.php"} ;
# Set FastCGI Application InstanceMaxRequests to 10000
Get-IISConfigSection -SectionPath "system.webServer/fastCgi" | `
Get-IISConfigCollection | `
New-IISConfigCollectionElement `
-ConfigAttribute @{"fullPath"="C:\PHP\PHP-CGI.EXE";"maxInstances"=0;"instanceMaxRequests"=10000} ;
# Set FastCGI Application EnvironmentVariables Collection Editor PHP_FCGI_MAX_REQUESTS to 10000
Get-IISConfigSection -SectionPath "system.webServer/fastCgi" | `
Get-IISConfigCollection | `
Get-IISConfigCollectionElement `
-ConfigAttribute @{"fullPath"="C:\PHP\PHP-CGI.EXE"} | `
Get-IISConfigElement `
-ChildElementName "environmentVariables" | `
Get-IISConfigCollection | `
New-IISConfigCollectionElement `
-ConfigAttribute @{"name"="PHP_FCGI_MAX_REQUESTS";"value"="10000"} ;
# Create the FastCGI application process pool
Get-IISConfigSection -SectionPath "system.webServer/fastCgi" | `
Get-IISConfigCollection | `
Get-IISConfigCollectionElement `
-ConfigAttribute @{"fullPath"="C:\PHP\PHP-CGI.EXE"} | `
Get-IISConfigElement `
-ChildElementName "environmentVariables" | `
Get-IISConfigCollection | `
New-IISConfigCollectionElement `
-ConfigAttribute @{"name"="PHPRC";"value"="C:\PHP"} ;
# Register FastCGI module in globalModules
Get-IISConfigSection `
-SectionPath "system.webServer/globalModules" | `
Get-IISConfigCollection | `
New-IISConfigCollectionElement `
-ConfigAttribute @{"name"="FastCgiModule";"image"="%windir%\System32\inetsrv\iisfcgi.dll"} ;
# Add FastCGI module
Get-IISConfigSection `
-SectionPath "system.webServer/modules" | `
Get-IISConfigCollection | `
New-IISConfigCollectionElement `
-ConfigAttribute @{"name"="FastCgiModule"} ;
# Create the Handler Mapping for PHP
Get-IISConfigSection `
-SectionPath "system.webServer/handlers" | `
Get-IISConfigCollection | `
New-IISConfigCollectionElement `
-ConfigAttribute @{"name"="PHP-iisfcgi";"path"="*.php";"verb"="GET,HEAD,POST";"modules"="FastCgiModule";"scriptProcessor"="C:\PHP\PHP-CGI.EXE";"resourceType"="Either";"requireAccess"="Script"} `
-AddAt 0 ;
3.4. Getting Started with a new PHP Web Site on Nano Server
Finally, we will have to create the PHP 7.0.6 site on the Internet Information Services (IIS) in the Nano Server.
# Create a folder
New-Item `
-Path "C:\PHP-Site" `
-Type directory ;
# Create a default PHP page without ConvertTo-Html PowerShell
# Cmdlet because it is not available on Technical Preview 4
"Welcome to PHP on Nano Server by Ryen Tang (MVP) <? phpinfo(); ?>" | `
Out-File `
-PSPath "C:\PHP-Site\index.php" `
-Encoding utf8 ;
# Create a new IIS Website
New-IISSite `
-Name "PHP-on-NanoServer" `
-BindingInformation "*:80:php.nanoserver.naboo.co.nz" `
-PhysicalPath "C:\PHP-Site" ;
4. Conclusion
It is definitely possible to deploy PHP 7.0.6 on IIS in Nano Server with Windows Server 2016 Technical Preview 4.
5. References
- Microsoft TechNet - IIS on Nano Server
- Microsoft Download Center - Visual C++ Redistributable for Visual Studio 2015
- PHP - Microsoft IIS 7.0 and later - Manual
- Microsoft IIS Blogs - Running Wordpress with IIS and WinCache on Nano Server by Jeonghwan
6. See Also
- Nano Server Survival Guide by Ryen Tang
- Microsoft Azure: Managing Nano Server with Server Management Tools by Ryen Tang
- Microsoft Azure: Deploying Windows Server 2016 Nano Server by Ryen Tang
- Windows Nano Server: Virtualization with VMware vSphere by Ryen Tang
- Nano Server: Getting Started with Image Builder by Ryen Tang
- Nano Server: Using New-NanoServerImage with Show-Command to deploy Nano Server by Ryen Tang
- Nano Server: Viewing Application, Security and System Event Logs using WMI by Ryen Tang
- Nano Server: Deploying an Internet Information Services (IIS) Web Server by Ryen Tang
- Nano Server: Deploying ASP.NET 5 site on Internet Information Services (IIS) Web Server by Ryen Tang
- Nano Server: Deploying MySQL Database Server by Ryen Tang
- Nano Server: Deploying Python 3.x interpreter by Ryen Tang
- Nano Server: Getting Started in Container with Docker by Ryen Tang