How to Compile PHP5.2 and PHP-GTK2 on Windows using Visual C++ Express

By auroraeosrose | November 15, 2006

Welcome to the wonderful world of Microsoft Windows

“I’m trying to compile PHP on Windows”

Such a simple statement brought various reactions in IRC channels and mailing lists. But invariably I heard the same thing asked.

“Why?”

writer No, I’m not insane. And I realize that there are some great resources for downloading precompiled ready to go PHP windows binaries and extensions. However, I’ve been working with PHP-GTK2, a project that currently has a lot of work to be done in both documenting (which I have helped with and need to do more of) and writing C code (which is something I’d like to learn to help with). The general idea of PHP-GTK2 is to create wrappers around GTK+ which is a great toolkit but it takes a while to write things in C. Other scripting languages have similiar wrappers, including Perl, Ruby, and Python. But I prefer PHP, mostly for aesthetic and subjective, not objective reasons. And scripting languages are so much easier to deal with compared to compiled languages. Besides, it makes desktop app development on Windows really fast and easy - the screenshot is from the Open Source project I’m writing with it.
I wanted to be able to test new things being placed in CVS and learn enough C to help increase the implementation percentage. Right now PHP-GTK2 is simply trying to finish the 2.6.9 version of GTK+ - I want 2.10 for all the nifty new features, including an “assistant”, status bar icons, even cross-platform printing. But that isn’t going to happen very swiftly if all the current developers are busy. Rule number one of open source…if you want it, write it. But I couldn’t even begin to fiddle with source code until I could compile the thing.

After spending several days and countless hours messing with the nuances of Microsoft’s insane and headache inducing compile and development system I now have a working 5.2 dev + PHP-GTK2 dev. This is a rather long and somewhat insane tutorial on how to accomplish this feat for those with time on their hands who aren’t afraid of the windows command line but aren’t necessarily C gurus.

I’ll be going over four main steps

  1. Setup a (free as in money, not beer) compile environment
  2. Compile PHP
  3. Compile PHP-GTK2
  4. Deploy PHP-GTK2

Pages: 1 2 3 4 5

34 Responses to “How to Compile PHP5.2 and PHP-GTK2 on Windows using Visual C++ Express”

  1. Trevor Gryffyn Says:
    November 16th, 2006 at 1:11 pm

    Good luck with the compiling. I don’t know if you’re dead set on GTK, but last time I used it I almost went insane I think. Just wanted to drop a quick note recommending Winbinder (http://www.winbinder.com) if you’ll be totally involved with just Windows development. It uses the native Windows GUI and API rather than create it’s own (as GTK did.. which is great for cross platform, but not ideal I think). I’m not affiliated with Winbinder nor get any kickbacks from them, just think Rubem and crew have done an incredible job and want to make sure people know about their good work. Best of luck!rnrn-TG

  2. auroraeosrose Says:
    November 16th, 2006 at 3:06 pm

    GTK2 is a whole different ballgame from GTK1 - I tried the PHP-GTK1 route a long time ago and threw up my hands in despair. But GTK2 is awesome, even if the PHP version is unfinished.rnrnI actually tried Winbinder. It is a nice idea - but last time I used it the API was horrid, it wasn’t OO, and you had to include regular php files just to use it (which completely defeats the purpose of a php extension), it didn’t have printing support (which PHP-GTK2 doesn’t at the moment, but will), and they had db junk thrown in… maybe I’m just strange but to me the code was a mess. But the dealbreaker for me is that Winbinder is php4 only - um, no thanks.

  3. Jeroen Says:
    December 11th, 2006 at 3:17 pm

    Wow, nice tutorial!rnrnI’m one of those silly people who wants to compile PHP 5.2 on Windows, too. (Windows XP Home SP2)rnrnYour tutorial helped me a lot (I’m already at it for 1 day now, lol), at least I got it compiled now.rnrnYou forgot the part about winres(rc).h in this article.rnrnWhat I did: I copied WINRES.H (C:Program FilesMicrosoft Platform SDK for Windows Server 2003 R2Includemfc) + WinResrc.h (C:Program FilesMicrosoft Platform SDK for Windows Server 2003 R2Include) to “php-5.2.0win32build” and to “php_buildinclude” (both files in both folders, hey it worked :-))rnrnNow all I got to do is solve that error about MSVCR80.dll (I tried installing that redistributable thingy you linked. Alas, it looks like it didn’t install or something, because it doesn’t work)rnrnI’ll let you know how it turns out, if you got any suggestions about MSVCR80.dll, I’d like to hear them :-)

  4. Jeroen Says:
    December 11th, 2006 at 3:21 pm

    Btw your script strips to much backslashes (), even from newlines and carriage returns (very annoying ;-))!

  5. auroraeosrose Says:
    December 12th, 2006 at 9:23 am

    I need to upgrade wordpress, but I have a mysqli hack running so it’s a pain in rear - I added the winres.h informationrnrnas for the msvcr80.dll - did you look in your winsxs directory to see if the file existed? and did you remember to use the mt command to pack EVERY DLL with the manifest it needs? also since this is sucky windows you may have to restart your machinern

  6. Ekate Says:
    April 28th, 2007 at 7:33 am

    No,no,nornit doesn’t work.rnI even can’t compile phprnI get the following errorrnNMAKE:fatal error U1077 “C:Program filesMicrosoft Visual Studio 8…c1.exe” return ‘0×2′rnStop.rnrnCan anyone help me with it?rn

  7. Iuri Fiedoruk Says:
    May 3rd, 2007 at 7:19 am

    Did you by any chance got the apache module also compiled or only the command line client?rnThanks in advance.

  8. Tim Sample Says:
    May 31st, 2007 at 10:12 am

    Great tutorial. Thanks you so much. I’d like to mention that this is the best/only resource for building PHP extensions under Windows.

  9. dinesh Says:
    June 1st, 2007 at 11:07 am

    I am currently building an application using php-gtk for that i have to make an nsis installer which can automatically install php and php - gtk dependencies ,,,
    CAn you tell me that i should make a seprate package for php , php-gtk , and of my application
    or just put the files into a nsis script and run it….

    thanx

  10. auroraeosrose Says:
    June 1st, 2007 at 5:39 pm

    There is already an nsis installer for php-gtk2 on windows at gnope.org, and for php-gtk1 if you’re still using that at http://www.firepages.org/gtkdev.html

    I’m also writing an msi installer using wix (look for it in cvs soon) the advantages of msi include command line installation, and pushing out to organizations using windows tools

  11. developercast.com » IBM developerWorks: Building PHP on Windows Says:
    July 3rd, 2007 at 9:51 am

    [...] also points to Elizabeth Smith’s tutorial on compiling on Windows for more information. [...]

  12. PHP Guru Says:
    July 25th, 2007 at 8:52 am

    This would have helped me out a bunch a year ago. Grrrrrrrrrrrrr…

    Thanks.. nice article.

  13. Jan Says:
    August 16th, 2007 at 9:11 am

    I’m trying to compile gtk with msvc 7.1 for a week. This is serious hell. Each library has different kind of msvc compilation (makefile, MSV project or even better nothing). There are no config.h.win32, libraries are installed to different location (c:usr or left in place). And I’m still unable to compile cairo (I don’t want by compiling freetype and fontconfig, expat and other crap to tear all my hair, so there is some unresolved symbols and no makefile.msc of course). The GTK makefiles is calling perl with too long line that the very stupid cmd can’t process.

    All this is because python is compiled with msvc 7.1. And if your app is using GTK compiled with msvc6 (linked with msvcrt.dll) and python in 7.1 (linked with msvcr71.dll) it will crash soon after the app is doing something with files (like g_fopen). What should I do now?

  14. auroraeosrose Says:
    August 21st, 2007 at 8:31 pm

    Jan: I’ve been (very slowly) working on building msvc project files for the gtk monstrosity - but as you’ve noted, there are so many dependencies that it’s taking me forever.

    I’m not sure what to tell you about the runtime clashing - I’ve never actually run into a problem even when mixing runtimes, but I’ve heard stories from others.

  15. johndee Says:
    September 6th, 2007 at 1:06 pm

    thanks for the article! it really saves a lot of nerve when you get into the perversion of building php on windowz %)

    unfortunately the ftp with libraries required for the build is down, so i wonder if you could post a list of these libs or the archive itself.

    will be very grateful if u send it directly to my mail :)

  16. johndee Says:
    September 6th, 2007 at 4:34 pm

    nevermind. already found it. 60mb to download 8-0. even more wicked quest than i expected…:D

  17. likopinko Says:
    September 10th, 2007 at 11:45 am

    Hi

    I am really excited. Very useful, i found lots of intresting things here. Your web site is helpful. Best regards!

    Bye

  18. Edward Z. Yang Says:
    September 13th, 2007 at 11:37 am

    The new location of the zip.zip file is here: http://files.edin.dk/php/win32/zip.zip

  19. deciacco Says:
    October 10th, 2007 at 4:17 pm

    Hi,
    I’ve been working with compiling php 5 on Windows. I think I got it working, but I get many warnings during the compile. PHP seems to work fine afterwards, so I’m not sure if this is normal. (I vaguely remember warnings during a compile of PHP on linux, so perhaps they are normal, although I’ve always fixed warnings in my programs.)

    Anyway, I was wondering if you experienced the same thing when you did you compile. Most of the warnings are “warning C4142: benign redefinition of type” or other type conversion warnings.
    Thanks

  20. auroraeosrose Says:
    October 12th, 2007 at 11:33 am

    Compilation warnings are both legion and perfectly ignorable on a windows compile - only worry if you start getting errors or undefined symbol warnings

  21. Compile That PHP-GTK2, and More | MT-Soft Website Development Says:
    November 10th, 2007 at 3:03 pm

    [...] I lied. This document does care what OS you use. I cannot help you with Compiling on Windows. This post here on Elizabeth’s blog might help you out [...]

  22. Pádraic Brady Says:
    December 10th, 2007 at 3:26 pm

    Windows is hell on wheels! ;). Just to torture myself, I’m finding this doesn’t work out just yet on Windows Vista using everything except for replacing the SDK with the newer Windows SDK for Vista. Everything works until you try nmake and then it throws some horrific Fatal Error: NMAKE:fatal error U1077 “C:/Program Files/Microsoft Visual Studio 8…c1.exe” return ‘0×2′. For some reason VC’s c1.exe doesn’t like me, or maybe it’s the vengeful Windows platform itself in Vista. Anyone managed to compile under Vista yet? Google just seems to have failed - which is incredible; has a Vista attempt ever been made or mentioned anywhere???

  23. Pádraic Brady Says:
    December 10th, 2007 at 5:11 pm

    Okay - Vista users. To compile around the error I noted, comment out line 897 (”sin6->sin6_addr = in6addr_any;”) and retry nmake. It allows a successful compile though I will not testify to what chaos the commenting out of that line may create down the line!

    The exact error preventing Vista compilation:

    mainnetwork.c(897) : error C2065: ‘in6addr_any’ : undeclared identifier
    mainnetwork.c(897) : error C2440: ‘=’ : cannot convert from ‘int’ to ‘IN6_ADDR’
    NMAKE : fatal error U1077: ‘”C:Program FilesMicrosoft Visual Studio 8VCBINcl.exe”‘ : return code ‘0×2′

    Maybe someone less rusty in C and with more VC/Windows compile superpowers can make sense of what’s going awry. Oh, and great tutorial Elizabeth!

  24. auroraeosrose Says:
    December 11th, 2007 at 7:29 pm

    Unfortunately, the windows compile superpower to fix it would probably be me. I thought we fixed this error (it took some weird voodoo ifdefing) - looks like something is going awry…. I can’t take a look at the moment because I no longer have my Vista laptop but I’ll annoy some people…

  25. Pádraic Brady Says:
    December 12th, 2007 at 11:27 am

    Should be fun trying it all again with Visual Studio 2008 Express ;). What “bad things” can be expected by my commenting out that line do you know? Waiting to get back home so I can re-compile with a few more extensions and run PHP’s tests.

  26. auroraeosrose Says:
    December 12th, 2007 at 2:54 pm

    in6addr_any undeclared is the issue - that SHOULD be being declared, if it’s NOT something is wrong in the compile….most likely a wayward define…

    Just commenting it out doesn’t fix the problem that it needs to be defined ;) see the compiler can’t find in6addr_any so it just “assumes” it’s an extern int - which is where the “cannot convert” error arises from and commenting that line out doesn’t fix the issue it just hides it, until you actually try to do something with ipv6…

  27. Pádraic Brady Says:
    December 15th, 2007 at 10:26 am

    Quick note that if anyone tries using VCE 2008 - there is no default.js or corewin_express.vsprops file to edit. Rather VCE2008 automatically detects when a Windows SDK is installed for Vista using a path check (see vcvars32.bat) and sets up the relevant environment as needed. I checked and the VCE2008 version of the integration document is inaccurate (marked pre-release version) and does not apply to the final version of VCE2008 for those two files - this threw me for a bit :). In case you go looking VCE2008 already includes v6.0A of the Windows SDK - but it will use v6.0 (the typical Vista SDK) when it’s installed. So apply the winres.h fix there.

    You may need to restart your PC once (or even twice after the SDK install for this to work) and of course make sure to register VCE2008. Now sure why it fails the first one or two times yet on my machine (you get that telling error about an invalid “-h” option). I noticed registration failed the first two attempts which might have caused the issue.

    Another observation is that I’m compiling without .NET Framework SDK 2.0 - maybe Elizabeth knows where the .NET SDK is required specifically. VCE2008 installs .NET Framework 3.5 but that’s not the SDK so probably nothing relevant. Haven’t done much compiling yet so it may be I’ve not hit something requiring the .NET SDK.

    Finally. Using VCE2005 I had an error in network.h in the main dir of the php source code. The error does not occur when building a PHP 5.3 snapshot of the source code. It seems specific to PHP 5.2.x versions. This error is apparently also specific to Windows Vista using the current Windows SDK For Vista Update.

  28. Compiling PHP for Windows Vista using Visual C++ Express 2008 - Seriously! | MT-Soft Website Development Says:
    December 18th, 2007 at 7:39 am

    [...] information available is an excellent guide written by Elizabeth Marie Smith in December 2006 about compiling PHP5 and PHP-GTK2 using Visual C++ Express. The other basically refers back to Elizabeth’s article and adds some details on needing ICU [...]

  29. developercast.com » Padraic Brady’s Blog: Compiling PHP for Windows Vista using Visual C++ Express 2008 - Seriously! Says:
    December 18th, 2007 at 11:43 am

    [...] Visual C++ Express 2008, then my blog entry is largely another coat of sugar on top of Elizabeth’s guide to clear up any difference between the two [...]

  30. Matthew Turland’s Blog: Custom building php on windows and linux | Development Blog With Code Updates : Developercast.com Says:
    March 21st, 2008 at 11:59 am

    [...] gives his “laundry list” of things to download/have access to and the link to Elizabeth’s tutorial handy. Matthew found a few differences in his compile - an issue with IPv6 support and a pathing [...]

  31. Javierfish Says:
    April 11th, 2008 at 2:55 pm

    Hello Elizabeth. Hey thanx and congratulations for this great tutorial. I just can’t believe that php.net’s people don’t give such detailed instructions as yours!

    Anyway, I’m not pretty sure where to unzip the contents of zip.zip

    The contents of zip.zip contains in the first level the dev/ folder. If I extracted the contents of the php source files to c:php, the zip.zip content should be on c:phpdev ? Thank you again!

  32. deciacco Says:
    January 8th, 2009 at 3:44 pm

    Looks like Edin’s zip.zip file is down and the one on perisama.net is corrupt. Anybody know where we can get this file?

  33. auroraeosrose Says:
    January 8th, 2009 at 4:15 pm

    This is VERY out of date - go check out http://wiki.php.net/internals/windows
    There you’ll find instructions, links to libraries, and all the information you need

  34. Compiler une extension PHP (Zend Core) sous Windows « Wild PHP Says:
    April 21st, 2009 at 11:11 am

    [...] Un HOW-TO de Elizabeth Marie Smith [...]

Comments