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.
Building PHP on Windows will require three things.
The advantage of using php-windows-builder tooling is that it can set up all of it under the hood.
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.
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-Module -Name BuildPhp -Repository PSGallery -Force
Install-Module -Name BuildPhp -Repository PSGallery -Force -Scope CurrentUser
7.4.25
, 8.0.12
, etc., or master
for the master branch of php-src
.x64
and x86
.ts
and nts
.Invoke-PhpBuild -Version 8.4.11 -Arch x64 -Ts nts
To build the PHP extensions locally, you can install the BuildPhpExtension PowerShell module from the PowerShell Gallery:
Install-Module -Name BuildPhpExtension -Repository PSGallery -Force
Install-Module -Name BuildPhpExtension -Repository PSGallery -Force -Scope CurrentUser
ExtensionUrl
input. It supports a git repository URL as value.ExtensionRef
input. It supports a git reference, e.g., a tag or a branch as value.PhpVersion
input. It supports values in major.minor format, e.g., 7.4, 8.0, etc.Arch
input. It supports values x64
and x86
.Ts
input. It supports values ts
and nts
.Libraries
input. It supports a comma-separated list of library names.configure
script, you can use the Args
input. It supports a string value.Invoke-PhpBuildExtension -ExtensionUrl https://github.com/xdebug/xdebug ` -ExtensionRef 3.4.5 ` -PhpVersion 8.4 ` -Arch x64 ` -Ts nts ` -Libraries "zlib" ` -Args "--with-xdebug"