How to Install WordPress on Windows Server 2016
Please share with your friends...
  • 1
  • 1
  •  
  •  
  • 1
  • 1
  •  
  •  
  •  
  •  
    4
    Shares


⇐ BackPageNext ⇒
PHP

PHP

PHP (Hypertext Preprocessor – a recursive backronym) is a server-side scripting language, coded as a mix of HTML, or in combination with various templating engines and web frameworks. PHP code is implemented as a Common Gateway Interface (CGI) executable, and the resulting output is then sent to the client in form of a generated web page.

There are three main components that comprise our PHP installation on Internet Information Server (IIS):

To begin, change into the Downloads directory using the following PowerShell command:

cd ~\Downloads

Versions

While WordPress is compatible with PHP 5, it it highly recommended that you use PHP 7 or later whenever possible.

The latest versions of PHP can be found here. You may need to update the filenames listed in the following section if newer versions have become available.

PHP 5

You should only consider using PHP 5 when installing or migrating WordPress systems that cannot otherwise be upgraded to PHP 7. This might be due to the use of legacy plugins or custom themes that are not compatible with later versions of PHP.

The Windows binaries for PHP 5 are 32-bit x86, Non Thread Safe (NTS), which are suitable for FastCGI. While there are 64-bit x64 builds of PHP 5 available, they are classed as experimental and do not provide 64-bit integer or large file support.

The Windows Cache Extension for PHP 5 is version 1.3, and is also a 32-bit x86 binary.

Microsoft Visual C++ 2012 Redistributable

PHP 5 and Windows Cache Extension 1.3 both require the Microsoft Visual C++ 2012 Redistributable (x86) to be installed.

Download and install the Visual C++ 2012 Redistributable, using the following PowerShell commands:

Invoke-WebRequest "https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x86.exe" -OutFile "vc_redist_2012_x86.exe"
.\vc_redist_2012_x86.exe /Q
PHP 5.6

PHP 5.6 is the final release branch of PHP 5, and continues to receive support through until 31 December 2018. If you have a requirement to use PHP 5, it is highly recommended that you use PHP 5.6.

Set temporary variables to be used during the PHP 5.6 and WinCache 1.3 installation, using the following PowerShell commands:

$PHP_ZIP = "php-5.6.34-nts-Win32-VC11-x86.zip"
$PHP_PATH = "${env:ProgramFiles(x86)}\PHP\v5.6"
$PHP_DATA = "$env:ProgramData\PHP\v5.6"
$WINCACHE = "wincache-1.3.7.12-dev-5.6-nts-vc11-x86"
[_/su_spoiler]
PHP 7

The current release is PHP 7, which includes numerous improvements over PHP 5 such as huge performance gains, more compact code structures, and migration to a just-in-time (JIT) compiler, all while retaining near-complete language compatibility.

The Windows binaries for PHP 7 are 64-bit x64, Non Thread Safe (NTS), which are suitable for FastCGI.

The Windows Cache Extension for PHP 7 is version 2.0, and is also a 64-bit x64 binary.

Microsoft Visual C++ 2015 Redistributable

PHP 7 and Windows Cache Extension 2.0 both require the Microsoft Visual C++ 2015 Redistributable (x64) to be installed.

Download and install the Visual C++ 2015 Redistributable, using the following PowerShell commands:

Invoke-WebRequest "https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe" -OutFile "vc_redist_2015_x64.exe"
.\vc_redist_2015_x64.exe /Q
[_su_accordion]
PHP 7.0

PHP 7.0 is the initial release branch of PHP 7, and continues to receive support through until 3 December 2018. However, unless you are aware of specific compatibility issues with WordPress plugins or other components, it is highly recommended that you use PHP 7.1 instead.

Set temporary variables to be used during the PHP 7.0 and WinCache 2.0 installation, using the following PowerShell commands:

$PHP_ZIP = "php-7.0.28-nts-Win32-VC14-x64.zip"
$PHP_PATH = "$env:ProgramFiles\PHP\v7.0"
$PHP_DATA = "$env:ProgramData\PHP\v7.0"
$WINCACHE = "wincache-2.0.0.8-dev-7.0-nts-vc14-x64"
[_/su_spoiler]
PHP 7.1

PHP 7.1 is the second release branch of PHP 7, and continues to receive support through until 1 December 2019. If you are building a new WordPress server, this is the version of PHP to use!

Set temporary variables to be used during the PHP 7.1 and WinCache 2.0 installation, using the following PowerShell commands:

$PHP_ZIP = "php-7.1.15-nts-Win32-VC14-x64.zip"
$PHP_PATH = "$env:ProgramFiles\PHP\v7.1"
$PHP_DATA = "$env:ProgramData\PHP\v7.1"
$WINCACHE = "wincache-2.0.0.8-dev-7.1-nts-vc14-x64"
[_/su_spoiler] [_/su_accordion]

Installation

The following instructions are used to install PHP on Windows Server 2016 using PowerShell.

  1. Download and install PHP, using the following PowerShell commands:
    Invoke-WebRequest "http://windows.php.net/downloads/releases/$PHP_ZIP" -OutFile "$PHP_ZIP"
    Expand-Archive "$PHP_ZIP" "$PHP_PATH"
    Copy-Item "$PHP_PATH\php.ini-production" "$PHP_PATH\php.ini"
  2. Download and install WinCache, using the following PowerShell commands:
    Invoke-WebRequest "https://nchc.dl.sourceforge.net/project/wincache/development/$WINCACHE.exe" -OutFile "$WINCACHE.exe"
    Start-Process "$WINCACHE.exe" "/Q /C /T:""$env:USERPROFILE\Downloads\$WINCACHE""" -Wait
    Copy-Item "$WINCACHE\php_wincache.dll" "$PHP_PATH\ext\php_wincache.dll"
    Remove-Item "$WINCACHE" -Recurse -Force
  3. Download and install PHP Manager for IIS, using the following PowerShell commands:
    Invoke-WebRequest "http://www.technologist.site/wp-content/uploads/0000/PHPManagerForIIS-1.4.0-x64.msi" -OutFile "PHPManagerForIIS-1.4.0-x64.msi"
    Start-Process "msiexec.exe" "/i PHPManagerForIIS-1.4.0-x64.msi /qn" -Wait

Configuration

The following instructions are used to configure PHP on Windows Server 2016 using PowerShell.

  1. Add the PHP Manager PowerShell Snap-In, using the following PowerShell command:
    Add-PsSnapin PHPManagerSnapin
  2. Register PHP with Internet Information Services (IIS), using the following PowerShell command:
    New-PHPVersion "$PHP_PATH\php-cgi.exe"
  3. Configure various PHP extensions, using the following PowerShell commands:
    Set-PHPExtension php_wincache.dll Enabled
    Set-PHPExtension php_mysql.dll Disabled
  4. Configure various PHP settings, using the following PowerShell commands:
    Set-PHPSetting date.timezone UTC
    Set-PHPSetting upload_max_filesize 20M

    You may need to vary these settings to suit your own preferred configuration.

  5. Relocate the PHP "Logs" directory, using the following PowerShell commands:
    $PHP_LOGS = "$PHP_DATA\Logs"
    New-Item $PHP_LOGS -ItemType Directory | Out-Null
    Set-PHPSetting error_log "$PHP_LOGS\php_errors.log"
  6. Relocate the PHP "Upload" directory to address potential media permission issues, using the following PowerShell commands:
    $PHP_UPLOAD = "$PHP_DATA\Upload"
    New-Item $PHP_UPLOAD -ItemType Directory | Out-Null
    Add-NTFSAccess $PHP_UPLOAD IUSR Modify
    Add-NTFSAccess $PHP_UPLOAD IIS_IUSRS Modify
    Set-PHPSetting upload_tmp_dir "$PHP_UPLOAD"

Testing

The following instructions are used to test the PHP installation on Windows Server 2016.

  1. Create a simple PHP Information page, using the following PowerShell command:
    Set-Content "$env:SystemDrive\inetpub\wwwroot\index.php" "<?php phpinfo(); ?>"
  2. Use a web browser to connect to your server, using either the Hostname or IP Address. The PHP Information Page will be displayed.
    PHP 7.1.3 Information Page
    PHP 7.1.3 Information Page
  3. Scroll down the page until you find the WinCache Extension section.
    WinCache Extension 2.0.0.8
    WinCache Extension 2.0.0.8

PHP is now installed and configured to run on Windows Server 2016.

⇐ BackPageNext ⇒

How to Install WordPress on Windows Server 2016

Please share with your friends...
  • 1
  • 1
  •  
  •  
  • 1
  • 1
  •  
  •  
  •  
  •  
    4
    Shares
Tagged on:                                                 

9 thoughts on “How to Install WordPress on Windows Server 2016

  • 09/03/2018 at 8:58 AM
    Permalink

    Thanks for posting this! I’ve not run the entire script yet, but have a question about what is best to do when an install file is no longer available (or has been moved to an “archive” folder). I think I recall that the original posting was about May 2017. Some of the versions listed in the script are not available, or not where they were originally. Thoughts?

    Reply
    • 10/03/2018 at 2:54 PM
      Permalink

      Hi there!
      I’ve updated the instructions and script to download the latest versions of MySQL (5.7.21) and PHP (7.1.15), plus address an issue with HTTPS downloading in PowerShell. Tested on fully patched versions of Windows Server 2016 (v1607 b14393) and Windows 10 (v1709 b16299) – all good. Also removed PHP 5.5 from the instructions, as this is well out of support now.
      Hope this helps 🙂
      Chris

  • 21/03/2018 at 3:00 AM
    Permalink

    Hello,

    Thanks for posting this great tutorial. I’ve run into an issue midway through and can’t continue. Any suggestions?

    PS C:\Users\webadmin\Downloads> Set-Content $MYSQL_INIT “ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘H*****’;”

    PS C:\Users\webadmin\Downloads> Content $MYSQL_INIT “CREATE DATABASE wordpress;”
    >> Add-Content $MYSQL_INIT “CREATE USER ‘wordpress’@’localhost’ IDENTIFIED BY ‘H******’;”
    >> Add-Content $MYSQL_INIT “GRANT ALL PRIVILEGES ON wordpress.* TO ‘wordpress’@’localhost’;”

    Get-Content : A positional parameter cannot be found that accepts argument ‘CREATE DATABASE wordpress;’.
    At line:1 char:1
    + Content $MYSQL_INIT “CREATE DATABASE wordpress;”
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Get-Content], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetContentCommand

    Reply
  • 14/06/2018 at 12:57 AM
    Permalink

    Is there a script to start from scratch?
    I had some issues and would like to reinstall ist, but how I do it?

    Reply
  • 28/06/2018 at 5:56 AM
    Permalink

    I was having a problem with Windows recognizing the “Install-WindowsFeature” command. I finally saw where someone had said not to use PS x86 for running a different script, so I switched to PS ISE and most of the commands ran without a problem. Or at least what wasn’t being downloaded was not due to running the wrong instance of PowerShell.

    Reply
  • 09/08/2018 at 12:01 PM
    Permalink

    The following is action #3 on Page2, but is missing from the PowerShell Script that has all the commands:

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

    If you don’t include it, there are file downloads that will fail (and the cause might not be obvious). I actually found this command elsewhere, and added it, which made the file downloads work. I happened to start rehearsing the process and saw it was mentioned in 3. I then checked the entire script and I don’t think it is there. If so, I missed it.

    Reply
  • 09/08/2018 at 12:07 PM
    Permalink

    The install went fine and I have a working WP site. But, I wanted a multisite site, so I went through that process, wanting sub sites that are subdirectories. The main site works fine, but the subsite does not show the site theme, nor can you get to the subsite’s Dashboard. I haven’t tracked down the answer yet, but I am thinking it may be something to do with the “rewrites”.

    Reply
  • 07/11/2018 at 3:46 AM
    Permalink

    Great walkthrough. I have been installing an internal WordPress Intranet server/site and it took me a while to get wordpress and HTTPS working with a self-signed cert. I eventually found instructions regarding exporting the server CERT in Base 64 encoded X.509 format and then adding this certificate information to the end of the \wp-includes\certificates\ca-bundle.crt file. This along with downloading the latest bundle of root certs from https://curl.haxx.se/docs/caextract.html helped fix the problem.

    I also found that I had to use the following command to configure IIS – “dism.exe /online /enable-feature /all /featurename:NetFX3 /Source:G:\sources\sxs
    Install-WindowsFeature Web-Server,Web-Common-Http,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-App-Dev,Web-CGI,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor,Web-Security,Web-Filtering,Web-Performance,Web-Stat-Compression,Web-Mgmt-Tools,Web-Mgmt-Service,WAS,WAS-Process-Model,WAS-NET-Environment,WAS-Config-APIs,Net-Framework-Core -IncludeManagementTools”.

    This required including the source option and pointing to the windows DVD/CD drive and also installing NETFX3 as this seemed to be missing from my 2016 server build.

    I hope this might be of use to someone else as there aren’t many sites/articles concerning setting up worpress on IIS.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *