Table of Contents

Build your own PHP on Windows

This tutorial concerns building PHP with the new php-windows-builder tooling, it also uses the PHP SDK 2.0 under the hood, so can be used to build PHP 7.0 and above. To build PHP prior to 7.0, or if you experience issues building PHP lower than 7.2 with this, please refer to older documentation.

Before you Begin

Building PHP on Windows will require three things.

  1. A properly set up build environment, including the compiler, git and the PHP SDK
  2. Prebuilt libraries and headers for third party libraries that PHP uses in the correct location
  3. The PHP source

The advantage of using php-windows-builder tooling is that it can set up all of it under the hood.

Requirements

PHP officially supports building with Microsoft's Visual C++ compilers. The following VC++ versions are supported and can be set up before you build, or it will be installed on the first run:

Always keep your installed Visual C++ up to date. Otherwise build errors may occur due to dependencies built with newer versions.

Support for a certain Visual Studio version means only support for its default platform toolset; building PHP with a non-default platform toolset (such as 14.16 with Visual Studio 2019) may work, but is not recommended.

Setup

Building PHP

To build PHP locally, you can install the BuildPhp powershell module from the PowerShell Gallery:

You'll need at least PowerShell version 5, which is available by default on Windows 10 and later. It is recommended to use PowerShell 7 or later. If you have an older version, you can install the latest version following these instructions.

All commands in the rest of this document should be run in an elevated PowerShell session (Run as Administrator).

Install the BuildPhp Package

Compile

Building PHP extensions

To build the PHP extensions locally, you can install the BuildPhpExtension PowerShell module from the PowerShell Gallery:

Install the BuildPhpExtension Package

Compile

Invoke-PhpBuildExtension -ExtensionUrl https://github.com/xdebug/xdebug `
                         -ExtensionRef 3.4.5 `
                         -PhpVersion 8.4 `
                         -Arch x64 `
                         -Ts nts `
                         -Libraries "zlib" `
                         -Args "--with-xdebug"