internals:windows:stepbystepbuild

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

  1. A properly set up build environment, including a compiler with the right SDK's and some binary tools used by the build system
  2. Prebuilt libraries and headers for third party libraries that PHP uses in the correct location
  3. 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.

Requirements

  • 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

Setup

Quick 'n' easy
  1. get visual studio 2008 (no matter what version - express, pro or others; all should work) and install it
  2. get and install windows sdk 6.1
  3. get a php 5.3 snapshot (do not extract yet!)
  4. create the folder “c:\php-sdk“
  5. 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“
  6. open the “windows sdk 6.1 shell” (it’s available from the start menu group) and execute the following commands in it:
    1. PHP 5.2, 5.3 and 5.4:
      setenv /x86 /xp /release
    2. PHP 5.5+:
      setenv /x86 /2008 /release
  7. cd c:\php-sdk\
  8. bin\phpsdk_setvars.bat
  9. bin\phpsdk_buildtree.bat php53dev
  10. 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
  11. 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)
  12. run in the windows-sdk-shell:
    cd C:\php-sdk\php53dev\vc9\x86\php5.3-xyz
  13. buildconf
  14. to get an overview of the compiling flags:
    configure --help
  15. 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)

  16. nmake
  17. if you want the resulting php to be zipped (comes handy for redist, believe me!), run after this also:
    nmake snap
  18. 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).
Recompile after you've done some changes
  1. clean up old compiled binaries
    nmake clean
  2. if you need to update config
    buildconf --force
  3. create your configure command: see release
    configure --disable-all --enable-cli --enable-$remains
  4. compile
    nmake
Adding PECL extensions (using 'dbase' as an example)
  1. cd C:\php-sdk\php53dev\vc9\x86
  2. get the dbase extension code through Subversion
  3. svn co http://svn.php.net/repository/pecl/dbase/trunk pecl/dbase
  4. cd php5.3-xyz
  5. buildconf
  6. executing
    configure --help

    should now contain a dbase option

  7. configure --enable-cli --enable-dbase
  8. nmake
  9. test the binary with a
    php -m

    command, to make sure dbase exists

LDAP Support Notes
  1. add “--with-ldap” to your configure
  2. 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

Pitfalls

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.

Utilities

Resource Hacker

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/

internals/windows/stepbystepbuild.1360579086.txt.gz · Last modified: 2017/09/22 13:28 (external edit)