This tutorial concerns building PHP before 7.2. To build PHP 7.2+, please refer to the newer documentation.
Building PHP on Windows will require three things
PHP officially supports building with Microsoft's Visual C++ compilers. MinGW and other compilers are NOT supported or even known to work. The free Express and Developer editions can also be used. For more information and how to get the compiler see the supported versions. The following VC versions are supported:
If using VC9, you will also need the Windows SDK 6.1 (see this page for additional info on the SDK)
Each version of Visual Studio (or Windows SDK) provides a command prompt environment for compiling (available from the Start Menu group).
setenv /x86 /xp /release
All commands in the rest of this document should be run in the appropriate command prompt.
deps-<php version>-<vc version>-<architecture>.7z
deps-5.6-vc11-x86.7z
This should be done only once before building PHP.
c:\php-sdk
bin
, script
and share
cd c:\php-sdk\
buildtree
batch script which will create the desired directory structure: bin\phpsdk_buildtree.bat phpdev
buildtree
script hasn't been updated for newer versions of VC++ so:C:\php-sdk\phpdev\vc9
to C:\php-sdk\phpdev\vc11
C:\php-sdk\phpdev\vc9
to C:\php-sdk\phpdev\vc14
C:\php-sdk\phpdev\vc##\x##
, where:vc##
is the compiler version you are using (vc9
, vc11
or vc14
)x##
is your architecture (x86
or x64
)C:\php-sdk\phpdev\vc11\x86\php-5.6.4-src
deps
directory. Here you will need to extract the libraries required to build PHP, which you downloaded in the perevious step (the deps-*.7z
archive).cd c:\php-sdk\
bin\phpsdk_setvars.bat
cd C:\php-sdk\phpdev\vc11\x86\php-5.6.4-src
buildconf
configure --help
configure --disable-all --enable-cli --enable-$remains
nmake
nmake snap
nmake clean
buildconf --force
configure --disable-all --enable-cli --enable-$remains
nmake
Many PECL extensions already have prebuilt DLLs which can be downloaded from the extension page on the PECL web site. For example, on the APCu extension page, there are *DLL* links next to the release archive link. They lead you to a page where you can download the compiled extension for your desired PHP version and architecture.
To build a PECL extension (for example APCu):
pecl
on the same level as your PHP source directory, e.g. C:\php-sdk\phpdev\vc11\x86\pecl
pecl
directoryC:\php-sdk\phpdev\vc11\x86\pecl\apcu
apcu-4.0.7
setvars
script, and enter your PHP source directorybuildconf
configure --help
should now contain an option to enable APCu --enable-apcu Whether to enable APCu support
configure --disable-all --enable-cli --enable-apcu
nmake
php -m
command, to make sure APCu is loadedAt this point, your compiled extension will be located in the release directory.
Additional Links:
fatal error C1900: [] mismatch between 'P1' version '200801116' and 'P2' version '20070207'
If you are using Visual Studio 2008 Express and Platform SDK 6.1 make sure you have the latest versions and check for version incompatibilities. There are known issues with old versions of VS 2008 Express and Platform SDK 6.1.
The order in which you install the Visual Studio 2008 Express Edition and Platform SDK 6.1 is important due to the issue reported in Windows SDK for Windows Server 2008 and .NET Framework 3.5 Overview, Windows SDK for Server 2008 (v6.1) overwrites VS2008 SP1 CRT files and Installing Windows SDK for Server 2008 (v6.1) after VS2008 SP1 causes conflicts with Security Update (KB971092). Install the SDK first, with any of its service packs and security updates before installing Visual Studio 2008 Express Edition.
Make sure that you are running setenv /xp /x86. For example, setenv /xp /x64 or setenv /vista /x64 causes the above error message even if you are using Visual Studio 2008 Express SP1 and Platform SDK 6.1 (60001.18000.367) on a Vista 64bit system.
Utility to show dependency information and other assembly information from a DLL. For instance, it shows which version of the Visual C++ Runtime the DLL was linked against.
Get it here: http://angusj.com/resourcehacker/