This is an old revision of the document!
Build your own PHP on Windows
Before you Begin
Building PHP on Windows will require three things
- A properly set up build environment, including a compiler with the right SDK's and some binary tools used by the build system
- Prebuilt libraries and headers for third party libraries that PHP uses in the correct location
- The PHP source
The Build Environment
This is the hardest part of the PHP windows build system to set up and will take up a lot of space on your hard drive - you need to have several GB of space free.
- Microsoft Visual C++, PHP officially supports building with Visual C++ 6.0 or with Visual C++ 9 (also known as Visual C++ 2008 just to be confusing). You can use the Express versions as well. MinGW and other compilers are NOT supported or even known to work. For more information and how to get the compiler see the supported versions
- The correct Windows SDK or Platform SDK to match your compiler. see this page for the supported versions
- Various tools, see http://windows.php.net/downloads/php-sdk/ for binary versions of them
Quick 'n' easy
- get visual studio 2008 (no matter what version - express, pro or others; all should work) and install it
- get and install windows sdk 6.1
- get a php 5.3 snapshot (do not extract yet!)
- create the folder “c:\php-sdk“
- unpack the binary-tools.zip archive (http://windows.php.net/downloads/php-sdk/) into this directory, there should be one sub-directory called “bin” and one called “script“
- open the “windows sdk 6.1 shell” (it’s available from the start menu group) and execute the following commands in it:
setenv /x86 /xp /release
- now extract the snapshot from 3) to C:\php-sdk\php53dev\vc9\x86 with your favourite unpacker (winrar should handle it) so that the following directory gets created: C:\php-sdk\php53dev\vc9\x86\php5.3-xyz
- in the same directory (C:\php-sdk\php53dev\vc9\x86) there is a “deps” folder, extract any of your required libraries inside that folder (see http://wiki.php.net/internals/windows/libs) but make sure their top-level contains /include and /lib (some of them have an extra directory level in there)
- run in the windows-sdk-shell:
- to get an overview of the compiling flags:
- create your configure command:
configure --disable-all --enable-cli --enable-$remains
(warning: some extensions need libraries, header files and helper apps, see libs, fetch the version you need and extract the archive in the deps directory, ie: c:\php-sdk\php53\vc9\x86\deps)
- if you want the resulting php to be zipped (comes handy for redist, believe me!), run after this also:
- the compiled php is now under C:\php-sdk\php53dev\vc9\x86\php5.3-SNAPSHOTTIME\Release_TS, same as the zip file (if you created it).
Adding PECL extensions (using 'dbase' as an example)
- get the dbase extension code through Subversion
svn co http://svn.php.net/repository/pecl/dbase/trunk pecl/dbase
should now contain a dbase option
configure --enable-cli --enable-dbase
- test the binary with a
command, to make sure dbase exists
LDAP Support Notes
- add ”–with-ldap” to your configure
- make sure to package your generated binaries with libsasl.dll, which will not be built through this process - you can find it inside your C:\php-sdk\php53dev\vc9\x86\deps\bin\ folder, or you can download it from one of the PHP official binary packages
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.