This blog post will show you how to compile a PHP 7 extension for Windows. We will be using the new Microsoft Visual Studio 2015 Community Edition, which can be downloaded here for free. All directories are relative, it's recommended to use a short path without spaces. You can start in C:.

Installing Visual Studio

If you are choosing the advanced setup be sure to tick Programming Languages -> Visual C++ -> Common Tools for Visual C++ 2015

Installing additional tools

This post assumes you installed 7-zip and git. It also assumes you installed the linux tools that come with git (asked during installation). And added both 7-Zip and Git\bin to your SYSTEM PATH.

Installing PHP binary tools

This step creates a sub-directory in the current path called php7.

curl -O http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip
7z x -ophp7 php-sdk-binary-tools-20110915.zip
cd php7-bt\bin
phpsdk_buildtree.bat phpdev

Installing PHP source code

cd phpdev
cp -r vc9 vc14
cd vc14\x86
git clone -b PHP-7.0.0 --single-branch https://github.com/php/php-src.git .

Installing dependencies

curl -O http://windows.php.net/downloads/php-sdk/deps-7.0-vc14-x86.7z
7z x -odeps deps-7.0-vc14-x86.7z
rm deps-7.0-vc14-x86.7z

Compiling PHP source + Extension

hprose was chosen as example because it's one of the few PHP extensions that are compatible with PHP 7 for the moment. On Windows the buildscript is designed to build PHP itself along side with the extensions. "But on Windows it's different because the script is designed to build PHP itself."

cd ..\..\..\
phpsdk_setvars.bat
cd phpdev\vc14\x86
mkdir pecl && cd pecl
curl -O https://pecl.php.net/get/hprose-1.5.5.tgz
tar -zxvf hprose-1.5.5.tgz
rm hprose-1.5.5.tgz
cd ..
buildconf
configure --enable-debug --enable-phpdbg --enable-hprose
nmake

Tip: If you want to load the C sources from somewhere else try adding --add-modules-dir=path\to\ext to buildconf. The path must have a sub-directory with the actual source!

Tip 2: hprose used the enable and disable flag, other extensions use the with and without flag.

Rebuilding

In you need to rebuild, issue the following commands:

nmake clean
buildconf --force
configure --enable-debug --enable-phpdbg --enable-hprose
nmake

Verification

cd Debug_TS
php -i | grep hprose

Should show:

Configure Command => cscript /nologo configure.js  "--enable-debug" "--enable-phpdbg" "--enable-hprose"
hprose
hprose support => enabled
hprose version => 1.5.5
hprose author => Ma Bingyao
hprose homepage => https://github.com/hprose/hprose-pecl

Static or shared

Most extensions will be compiled statically into the php executable. If you want to share your extensions as dynamic link library (DLL) then put =shared behind the enable flag, like so: --enable-hprose=shared

Writers note

Building the extension on itself should be possible with phpize, so far i have not got this to work yet. Building the entire php core to compile an extension slows down development a lot which is unfortunate. A possible workaround would be to develop the extension on linux and do the final build on windows. The blog will be updated if more information is known.