Skip navigation

wow! that was fun.

This is how you do it, using Sara Golemon’s Extending and Embedding PHP as a reference (a fabulous book, by the way).

  1. create a folder on your c drive, like C:\PHPDEV
  2. download php 5.2.6 source from a mirror (this is the current php 5 version, time of this post). Save this tar.gz file into C:\PHPDEV. EXTRACT IT THERE.
  3. download php win32 build extras and save into C:\PHPDEV. EXTRACT IT THERE.
  4. Get pre-built binary packages for bison.exe and flex.exe. Put those on your desktop, or somewhere AWAY from C:\PHPDEV.

    Open both archives and go into their /bin directories. Take flex.exe from the flex archive and bison.exe from the bison archive and put THOSE into C:\PHPDEV.

  5. The next step can get twisted if you don’t have Visual Studio (any version?) installed.

    If you don’t have it, try the express editions, or take a look at ishouldbecoding.com article.

    Assuming you have Visual Studio 2008, FIRST, open C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat.

    The file is about 50 lines long full of @set type statements.

    Find the line that starts with

    @set PATH=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;(goes on)

    Change that line to read

    @set PATH=C:\PHPDEV;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;(leave the rest exactly as it were)

    So all I did there was add C:\PHPDEV; just after the = sign. The reason I did that was so that flex.exe and bison.exe are part of the system path now.

    NOW, go to Start->Microsoft Visual Studio 2008->Visual Studio Tools->Visual Studio 2008 Command Prompt.

  6. switch to C:\PHPDEV\php-5.2.6
  7. type buildconf.bat
    What this does is scan all folders for .w32 files and creates configure.js for you
  8. type:
    cscript /nologo configure.js --without-xml --without-wddx --without-simplexml --without-dom --without-libxml --disable-zlib --without-sqlite --disable-odbc --disable-cgi --enable-cli --enable-debug --without-iconv --disable-ipv6
    

    **** COPY PASTE THE ABOVE LINE. ITS LONGER THAN IT LOOKS.

    what this does is modify configure.js for you. You can get the same effect I guess by going into configure.js and manually setting things to “yes” and “no”. Why disable all these things? Most of these aren’t included in the bundle you downloaded, so you’d get compile errors like “file not found” if you didn’t disable these.

    if you don’t have bison.exe, you’ll get:

    ERROR: bison is required

    If you don’t have flex.exe, you’ll get

    ERROR: flex is required

    so get bison and flex as explained above.

  9. Type

    nmake

  10. switch to c:\PHPDEV\php-5.2.6\Debug_TS
  11. Type something like

    php -r “$x = ‘hello’; echo($x);”

Sara, you are fantastic. The book is rich and explains things very clearly. I had to skim through some of the stuff about php life cycle and php variables, because I was anxious to build it, but there’s tons more to read here :). Seems to be fairly considerate to windows users. Thanks for writing that book, to begin with.

online guide
another article – ishouldbecoding.com
Elizabeth Smith

12 Comments

    • Elizabeth Smith
    • Posted June 13, 2008 at 1:18 pm
    • Permalink

    I generally make it a habit not to mess with vsvars32.bat – instead I have a buildphp.bat that calls vsvars32.bat and then has a line that says

    set PATH=c:/PHPDEV;%PATH%

    which appends those needed binaries location onto the path, but doesn’t mess up my vsvars path for when I need to build NON php items

  1. Very excellent work on this. I got PHP 5.2.6 compiled on WinXP in much less time than I thought I would.

    One problem I ran into worth mentioning. I used VS 2008 Express, which did not include winres.h for MFC support when compiling win32\build\template.rc. The workaround there is to replace

    #include “winres.h”

    with

    #include “windows.h”

    After that, everything else worked great.

    • rayford
    • Posted February 6, 2010 at 5:56 am
    • Permalink

    I also could not get this
    php -r “$x = ‘hello’; echo($x);”

    to work on windows7 but this test
    php -r “$x=’hey’;print_r($x);”

    ran fine. Nice work!

    Other notes the 5.3.6 link died probably the minute 5.2.7 came out – doesn’t stop most people from finding the latest now at 5.3.1 I think.

    There is no Debug_TS folder that I could find but there is a Release_TS folder and its empty. I just ran the commands in the PHPDEV folder.

    There is likely more but dont give up keep at it. I’m off to make some PHP modules and figure out how to get them on my joomla sandbox site. =)

    • Kirk
    • Posted February 7, 2010 at 10:44 pm
    • Permalink

    cscript /nologo configure.js –without-xml –without-wddx –without-simplexml –without-dom –without-libxml –disable-zlib –without-sqlite –disable-odbc –disable-cgi –enable-cli –enable-debug –without-iconv –disable-ipv6

    I had to copy and paste from the page above to see all the switches on the cscript command. I am seeing fewer errors now, but the nmake is still not working. I am going to keep punching away at it until I can get this worked thru.

    • rayford
    • Posted February 8, 2010 at 12:25 am
    • Permalink

    There is a difference between visual studio command prompt and regular command prompt. Anyone know exactly what the diff is?

    • rayford
    • Posted February 8, 2010 at 12:34 am
    • Permalink

    ok following Kirk’s tip – view source on this page will reveal many more switches on the cscript command. Once this runs correctly the nmake will also run correctly and THAT creates the DEBUG_TS folder I couldn’t find earlier.

  2. I made the cscript command scroll-y now!

    • Ed
    • Posted July 20, 2010 at 1:25 am
    • Permalink

    As easy as pie! I have been using Visual C++ 6.0 for ages to build and debug extensions and now I can move to Visual Studio 2008. Thank you :)

    • ken
    • Posted October 4, 2010 at 2:53 am
    • Permalink

    I couldn’t get it to work until I put bison and flex in c:\cygwin\bin\, then everything worked great. Thanks for the awesome “Cliff’s Notes” version! (and to Sara too, I know she’s amazing)

    • schalk
    • Posted October 21, 2010 at 1:25 pm
    • Permalink

    @rayford, VS command prompt is just regular cmd with initial run of vcvarsall.bat setting some environment variables.

  3. Hello, do you think this tutorial is relevant for trying to recompile php with –enable-gd-jis-conv using xampp? Its so hard to figure out how!
    Using windows 7.

    Thanks,
    Nicholas.

  4. Hi. Thanks for this manual.

    I find some errors, If I try to swich off curlwrapper I obtain next error:

    C:\PHPDEV\php-5.5.4>cscript /nologo configure.js –without-curlwrapper
    Unknown option –without-curlwrapper; please try configure.js –help for a list
    of valid options

    I look inside configure.js and I can’t find curlwrapper.

    If I try nmake I get this error:

    C:\PHPDEV\php-5.5.4>nmake

    Microsoft (R) Program Maintenance Utility Version 9.00.30729.01
    Copyright (C) Microsoft Corporation. All rights reserved.

    NMAKE : fatal error U1064: MAKEFILE not found and no target specified
    Stop.

    I don’t know where to continue.

    Thanks.


One Trackback/Pingback

  1. By 在Windows下源码编译PHP | Demon's Blog on 31 Aug 2010 at 8:15 am

    […] how to compile php on windows / win32 […]

Leave a comment