Setting up PHP build environment on Windows

One of the things I have done many times in the past year is setting up a build environment for PHP on Windows. I have been using a simple script to do this which I am releasing today with this blog. Here is the zip file contains the script winbuild.bat along with essential tools (wget and unzip) which the script requires. Before you run winbuild.bat, make sure Visual Studio (or VC9 expression edition) and TortoiseSVN are installed on the machine. If you do not have these already installed, you can install VC9 express edition from http://www.microsoft.com/express/downloads/ (select visual studio 2008 express) and TortoiseSVN from http://tortoisesvn.net/downloads. Installation of TortoiseSVN might require a reboot. Once machine is ready, download the attached zip, unzip files in a folder, say c:\winbuild, launch visual studio command prompt and then run c:\winbuild\winbuild.bat. By default this script will setup PHP 5.3 build environment in %systemdrive%\php\php_sdk\php_53_dev folder. If you want to choose a different branch and folder location, open winbuild.bat, change variable values on top of the script before running it. This script does the following for setting up the build environment.
 
·         Create folder structure recommended here.
·         Download and unzip binary tools package.
·         Download and unzip all dependency libraries.
·         Download php source code from http://svn.php.net.
·         Run buildconf and configure commands.
 
After the script is complete, PHP root will be set to c:\php\php_sdk\php_53_dev\vc9\x86\PHP_5_3. If you change branch/folder locations in the script, this will be different. With the build environment set, you can now run “nmake snap” to build PHP in the PHP root folder. If you want to change configure options, open config.nice.bat (present in PHP root), change the options and run it. Running “nmake snap” will now build PHP using new configure options. Once the build is complete, release binaries will be under the release folder under php root.
 
Hope this makes setting PHP build environment much simpler. If you run into a bug in winbuild.bat, let me know by leaving a comment. Feature suggestions are also welcome.

Download script here.
 

Thanks.
Kanwal

25 thoughts on “Setting up PHP build environment on Windows

  1. Pingback: Webby Scripts Setting up PHP build environment on Windows « Kanwaljeet Singla

  2. Pingback: Setting up PHP build environment on Windows « Kanwaljeet Singla « php

  3. Pingback: Setting up PHP build environment on Windows « Kanwaljeet Singla

  4. Pingback: Setting up PHP build environment on Windows « Kanwaljeet Singla

  5. Pingback: Setting up PHP build environment on Windows « Kanwaljeet Singla : : windows

  6. Pingback: Adding a PECL extension to your PHP build environment « Kanwaljeet Singla

  7. Pingback: PHP PGO build for maximum performance on Windows « Kanwaljeet Singla

  8. bjoern

    Hi,
    I have somehoe a Problem with bison. Any clue?
    C:\php_sdk\php_53_dev\vc9\x86\PHP_5_3>nmake snap
    Microsoft (R) Program Maintenance Utility, Version 9.00.30729.01
    Copyright (C) Microsoft Corporation.  All rights reserved.

            bison.exe --output=Zend/zend_ini_parser.c -v -d -p ini_ Zend/zend_ini_pa
    rser.y
    C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\bison.exe: c:/usr/loca
    l/lib/bison.simple: No such file or directory
    NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio 9.0\
    VC\BIN\bison.exe"": Rückgabe-Code "0x2"
    Stop.

  9. Kanwaljeet Singla Post author

    Hi,

    Everytime you launch Visual studio command prompt, you need to run c:\php_sdk\bin\phpsdk_setvars.bat. This will add c:\php_sdk\bin folder to path. This folder has bison.exe which is required for building PHP. I will add this detail in my blog.

    Thanks,
    Kanwal

  10. Pingback: Anonymous

  11. Pingback: Tune Up Your PC » Post Topic » This Week’s Link List (May 21, 2010)

  12. Pingback: Work items collected from Tek-X « Kanwaljeet Singla

  13. Acalord

    Hi,
    I noticed something in your winbuild.bat script: After I ran it, things seems going well, but I saw a "phpsdk_servars.bat not found" likely message, and finally a "bison.exe not found" message.
    Looking into the code I found at line 110 this instruccion: CALL phpsdk_servars.bat
    I changed it by: CALL "%PHPROOT_BIN%\phpsdk_setvars.bat"
    Then re-ran the batch and all things went smooth.
    Regards.

  14. Hans Stråhle

    Running winbuild.bat I get the following errors:
    "WHERE" is not regognized as an internal or external command …
    "cl.exe" not found. Please install Visual Studio …

  15. Mark Foster

    This script was incredibly helpful.  Thank you Kanwaljeet for taking the time to post it.
    For those VS2008 newbies such as myself it is worth noting that when building on a Windows 7 64-bit OS, the shell you use when you set up and compile will determine if the PHP build is 64-bit or 32-bit.  If it is 64-bit you need to modify the script to go grab the 64-bit extensions.  In my case I wanted a 32-bit PHP build because I am targeting to a set of 32-bit servers.  I attempted to use the "CMD Shell" shortcut under the Microsoft Windows SDK v6.1 programs menu.  Using this shell gave me a 64-bit version of the PHP (assuming I didn't attempt to include any 32-bit extensions).  The "Visual Studio 2008 Command Prompt" command prompt shortcut under "Microsoft Visual C++ 2008 Express Edition"->"Visual Studio Tools" allowed me to build for 32-bit.
    Thanks again!
    -Mark

  16. Pingback: Rev it up with PHP and IIS | Josh Holmes

  17. charper

    Tried this after struggling with getting al my dependencies in order.  I get error "your build will be incomplete" "you do not have a snapshot template".  Any ideas?

  18. cindy

    I tried your build, but no matter what I do, I still have the problem I had when I tried downloading all the various parts and dependencies myself.  I get a "ordinal 57 not found in dynamic link library zlib1.dll" when I run php or php-cgi.exe.  Any suggestions?

  19. deciacco

    where you made this — CALL "%PHPROOT_BIN%\phpsdk_setvars.bat" — there is a typo. you have servars instead of setvars with a "t".
    also, since your script zilb was updated from 1.2.3 to 1.2.5 in the libroot folder
    thanks for the script

  20. Jacky

    If i understand this correctly, I do not need Windows SDK 6.1 to compile PHP?
    I'm sory i know im a noobie on this one, but since i've started trying to compile my own php (with my own add-ons, modules loaded as static) I've kept getting some compiler errors. From weird to version mismatch etc., every thing i searched up on google didnt work out =) Im going to give your script a try, but i have a positive thought so far !

    Anyway back to original question, since official php windows instructions tell you to get SDK, is it required at all?

  21. Jacky

    Common error I'm getting: Command line error D8040 : error creating or communicating with child process
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\
    VC\Bin\cl.exe"' : return code '0×2'

    Any ideas? Sorry for double post by the way =(

  22. GB

    There is a typo in setvar.dat. Second, the links for library downloads needs to be updated. The set up does not complete. Setting up manually. Please let me know when you update winbuild.dat. It will be nice for future versions. 

  23. Pingback: Installing PHP « Carra Lucia Ltd. Blog

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>