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

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.


[photopress:writer.jpg,full,alignleft] 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

The Compile Environment

[photopress:vce.jpg,full,alignleft] Although GCC rules the world in the *nix universe, on Windows things tend to be more fragmented. There is cygwin for those who love their linux tools, mingw the open source favorite, Borland's "professional" C tools, hardware specific compilers such as Intel's and Sun's and of course Microsoft's enormous(as in sheer size) Visual Studio. I'm sure there are many more C\C++ compilers for windows, but these appear to be the most common.

Because this is a fun side project I didn't want to be shelling out any big bucks, and because theoretically Microsoft knows windows best I decided to go with Visual C++ Express - a stripped down version of the C++ component from Microsoft's Visual Studio available for free.

Start by making sure you have a fairly large chunk of hard drive space available for the environment. Although VCE isn't that large, you'll also be installing other components that will take up over a gig of space. Next you'll need to download Microsoft's Visual C++ Express from their website. Follow the installer using the usual setup, you don't need the additional items offered like sql server 2005 if you just intend to compile and work on PHP.

After you have the program installed, open it once to make sure things are set up. There will be a nag until you "register" the product. Basically you'll need to answer a bunch of questions and you'll need a Microsoft passport account. Registration is free and if you uninstall and then reinstall using the same passport you won't need to fill out the form again.

Next we need to install the Windows Platform SDK. This is an enormous install, and can take a long time to download on dial-up. After you've downloaded and installed the Windows SDK you need to get it working with VCE. Microsoft has a document on the procedure. You can skip the first few steps since we'll be using the command line tools. You just need to alter your corewin_express.vsprops and default.js. It's not too difficult if you know how to use find in wordpad and search for files on windows. Or you can simply download the already altered files from the links above and drop them into place if you're lazy. You can also ignore the "build a test application" part of the instructions.

[photopress:prompt.jpg,full,alignright] Finally we need the last piece of the puzzle, the .Net Framework SDK. As before, download it, let it install in the default location (it will want to become part of your VCE install).

Now we have one more step to complete. PHP uses a command line environment to build instead of a Visual Studio project. There is a file called vsvars32.bat that is used to set up all the Visual Studio variables. Search for that file (it's buried pretty well). You need to edit the batch file, adding the paths to the /bin directories from the two newly installed sdk's to the PATH variable, the /include directories of both to the INCLUDE variable, and the /lib directories to the LIB (not LIBPATH) variables. Save the file, and now when you run the Visual Studio 2005 command prompt (in the start menu) everything will be set up properly.

One last thing - php will be looking for a file called winres.h. A quick google search and I find a mailing list post with the same error, and a fix. Seems the microsoft platform sdk and php disagree on a header name - so search for WinResrc.h, (somewhere in the include dir of the windows platform sdk) copy it, and rename the file winres.h

Compiling PHP

[photopress:dirlayout.jpg,full,alignleft] First of all, you need to decide on a location for all the source code you will be using. I chose c:/php because I'm so original, but basically anywhere would work. First you'll need the source code for PHP5.2. I used tortoisecvs to check out the latest php source with anonymous CVS into c:/php/php5. You can also download an official release or a source snap.

Next you'll need libraries and headers. You can get all the required ones plus additional ones for building extensions from Edin's site. Unzip the contents and place them in the build directory, parallel to your php source. You also need to add the path to your php_build/bin directory to the vsvars32.bat file so the build environment can find and use the tools there. If you get an error during configure about bison you may need to add @SET BISON_SIMPLE= php_build\bin\bison.simple to the vsvars32.bat file.
Now it's time to build PHP. Open up the Visual Studio 2005 command prompt and cd to your php source directory. Run buildconf, and then follow the directions to view all available configuration options. Create your configure line. You need the cli to run PHP-GTK2 properly but you can also build the windows cli and do any additional extensions you'd like.

After running cscript /nologo configure.js (your configure options here) you're all set.

[photopress:configure.jpg,full,alignright] Run nmake - this is the actual compilation and might take awhile. After nmake is finished it's probably a good idea to run nmake test

Now there are a few caveats to building software with VCE (basically Visual Studio 2005 tools) that all make deployment a bit of a pain. First of all anything built will require the mscvr80.dll - that's the new microsoft C runtime. Usually the runtime is shipped with new versions of windows or installed via a service pack. For some reason anything less than vista will need to install the redistributable package from microsoft.

Secondly VCE creates "manifest files" that tell the dll or exe which runtime to use. Unless you want to bother always shipping the manifest file around, you'll need to "pack" the manifest into the dll or exe file - msdn has instructions for doing this. Using the command line is the easiest course - altering makefiles is too much of a pain. And if you create debug versions you're not allowed to distribute them.

Compiling PHP-GTK2

PHP-GTK2 will require two items, the source code for the extension and the GTK+ development library stuff. Let's start with the libraries since it will take a rather long time and a lot of downloads.

Start with Gtk's ftp site. We'll want the 2.6.9 branch versions of GTK+ and its dependencies. Download glib, gtk+ and pango dev packages. I had a problem with something not being available in the 1.9.0 download of atk, so I got the 1.10.1 version instead. I created a seperate directory for all the GTK+ libs, parallel to the php_build dir, and called it gtk_build (I know, I'm so original)

Now unzip the glib contents. Drop the created folders into your gtk_build directory. Now go into gtk_build/lib/glib-2.0/include and move glibconfig.h to gtk_build/include. Next go into gtk_build/include/glib-2.0. Move the contents of that directory up one so you have gtk_build/include/glib and gtk_build/include/gobject, etc. Next unzip the gtk contents. Drop the folders into gtk_build again. Next go into gtk_build/lib/gtk-2.0/include and move gdkconfig.h into gtk_build/include. Then go to gtk_build/include/gtk-2.0 and move all the contents one directory up (just like you did with glib). Unzip pango and atk and drop them into place. Just like gtk and glib you'll need to go into the include directory and move /atk out of /atk-1.0 and /pango out of /pango-1.0.

Almost there - gtk uses iconv and gettext, but the version you used for PHP won't work quite right, so we'll head to Tor's site and get some working libs. You'll need libiconv and gettext. Unzip them and put their contents in your gtk_build directory. Do NOT put them in your php_build directory - they'll overwrite stuff and cause a mess!


No, we're still not done. You'll also need two additional tools - grep and sed for windows. You can get them from GNU utilities for Win32. Download the zip, remove grep and sed, and place them in you php_build/bin - NOT your gtk_build directory.

Now you'll need to add a few more directories to vsvars32.bat. You'll need to add your gtk_build/lib path and the path to your newly compiled PHP Release_TS folder to LIB, the location of some kind of php cli added to PATH (this is used for generating C files), and the location of gtk_build/include and your php source (mine is c:\php\php5) to the INCLUDE variable. Now you're almost ready to build.

Probably the best way to get php-gtk2 source is to use cvs, the only release is an alpha that's rather old at this point. My source ended up in php-gtk parallel to the php_build, php5, and gtk_build directories.
There's one last thing you need to do - open main/php_gtk.h in your php-gtk source folder. There's a little VS 2005 bug that we need to fix (I need to submit it to the mailing list) - move

#include "php.h"
#include "php_ini.h"

underneath the #ifdef PHP_WIN32 block (that means after the #endif)

Now open the command prompt, just like you did for building php, and run buildconf, then look at the configure options and then run configure - currently the only PHP-GTK2 extension with a windows configure file is libglade - you can get the header and library files needed from Glade/Gtk+ downloads, put the contents in your gtk_build directory. The include directory is nested like the others, so take glade-2.40/glade and move it one dir up. But I still couldn't get the extension to build properly - but since I don't use any extensions I don't really care at this point :)
It might take awhile for the files to generate. You can look at the progress in win32/logs.

Finally nmake

Just like the php SAPIS you built above, the dll will need to have the manifest packed inside (how annoying)

Deploying PHP-GTK2

I already discussed a few problems in deployment - you'll need to get the manifest into the dlls/exe files and every user needs the right microsoft C runtime.

Here's another problem. GTK can be very flakey on Windows because there are a ton of different dll files and you need the right ones. Dll Hell at its finest. Usually a program that uses GTK on windows bundles their own GTK+ libs to avoid missing symbols or incorrect versions and other such nonsense. The nice thing about GTk+ is it's supposed to be completely backward compatible. Although this isn't always true in practice, PHP-GTK2 should be able to run with newer dll runtime versions without any problems. The advantage to this is you get all the bugfixes, and there have been a lot to the windows version. Just remember that a newer runtime version doesn't mean the new features magically appear as well.

Start by creating a directory for holding your deployable (not deplorable) PHP-GTK2. All the .dll files should go in the top directory - usually they are in /bin in the zip. The reason for this is so php can find them easily without modifying PATH vars or other such nonsense.
First you'll need to download glib and its dependencies, Iconv and gettext. You only need the iconv.dll and charset.dll from the iconv package. The gettext only has intl.dll. Then the .dlls included in the glib package. You'll need the lib/locale directory for translated messages. If your app is only in one or two languages, you only need to include those.

Next the dependency stuff - libxml2 for the libxml2.dll, zlib for zlib1.dll. Then we need image dll stuff, libpng for libpng13.dll, libjpeg for jpeg62.dll, tiff for libtiff3.dll, and freetype for freetype6.dll. Then we need the smaller libraries - cairo for libcairo-2.dll, which is very cool, atk for libatk-1.0-0.dll (and possibly .mo files from the lib/locale directory), and pango - you'll need the four .dlls from the package along with the entire /etc folder.

Finally you'll need gtk+ - the latest from the 2.6, 2.8, or 2.10 branches (I like - a bit more stable on windows) You'll need everything in the zip file. Put the .dlls in bin in the deployment directory and then copy the additional directories parallel.

Now you're ready to move your newly built PHP 5.2 and PHP-GTK2 to its new home. Move your windows php cli (if you built it) and your regular php cli (I hope you built at least one) to the deployment dir. You'll also need the php5ts.dll and any extensions you built as shared (plus any .dlls they require).

Finally, move your php-gtk2.dll over and load it via your php.ini. You can find an example php-gtk ini in the /win32 dir in the php-gtk source. You're finished - try running one of the demo apps (they're in /demo in the php-gtk source)

If you'd like wimp to be the default theme, copy the gtkrc file from share/themes/MS-Windows/gtk-2.0 to etc/gtk-2.0

Have fun!


Trevor Gryffyn

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 ( 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

2006-11-16 8:11 am


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.

2006-11-16 10:06 am


Wow, nice tutorial!\r\n\r\nI'm one of those silly people who wants to compile PHP 5.2 on Windows, too. (Windows XP Home SP2)\r\n\r\nYour tutorial helped me a lot (I'm already at it for 1 day now, lol), at least I got it compiled now.\r\n\r\nYou forgot the part about winres(rc).h in this article.\r\n\r\nWhat I did: I copied WINRES.H (C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\mfc) + WinResrc.h (C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include) to "php-5.2.0\win32\build" and to "php_build\include" (both files in both folders, hey it worked :-))\r\n\r\nNow 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)\r\n\r\nI'll let you know how it turns out, if you got any suggestions about MSVCR80.dll, I'd like to hear them :-)

2006-12-11 10:17 am


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

2006-12-11 10:21 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

2006-12-12 4:23 am


No,no,nornit doesn't work.rnI even can't compile phprnI get the following errorrnNMAKE:fatal error U1077 "C:\Program files\Microsoft Visual Studio 8\...\c1.exe" return '0x2'rnStop.rnrnCan anyone help me with it?rn

2007-04-28 3:33 am

Iuri Fiedoruk

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

2007-05-03 3:19 am

Tim Sample

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

2007-05-31 6:12 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....


2007-06-01 7:07 am


There is already an nsis installer for php-gtk2 on windows at, and for php-gtk1 if you're still using that at

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

2007-06-01 1:39 pm » IBM developerWorks: Building PHP on Windows

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

2007-07-03 5:51 am

PHP Guru

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

Thanks.. nice article.

2007-07-25 4:52 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?

2007-08-16 5:11 am


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.

2007-08-21 4:31 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 :)

2007-09-06 9:06 am


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

2007-09-06 12:34 pm



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


2007-09-10 7:45 am

Edward Z. Yang

The new location of the file is here:

2007-09-13 7:37 am


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.

2007-10-10 12:17 pm


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

2007-10-12 7:33 am

Compile That PHP-GTK2, and More | MT-Soft Website Development

[...] 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 [...]

2007-11-10 10:03 am

Pádraic Brady

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???

2007-12-10 10:26 am

Pádraic Brady

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:

main\network.c(897) : error C2065: 'in6addr_any' : undeclared identifier
main\network.c(897) : error C2440: '=' : cannot convert from 'int' to 'IN6_ADDR'
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\cl.exe"' : return code '0x2'

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!

2007-12-10 12:11 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...

2007-12-11 2:29 pm

Pádraic Brady

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.

2007-12-12 6:27 am


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...

2007-12-12 9:54 am

Pádraic Brady

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.

2007-12-15 5:26 am

Compiling PHP for Windows Vista using Visual C++ Express 2008 - Seriously! | MT-Soft Website Development

[...] 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 [...]

2007-12-18 2:39 am » Padraic Brady’s Blog: Compiling PHP for Windows Vista using Visual C++ Express 2008 - Seriously!

[...] 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 [...]

2007-12-18 6:43 am

Matthew Turland’s Blog: Custom building php on windows and linux | Development Blog With Code Updates :

[...] 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 [...]

2008-03-21 7:59 am


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

Anyway, I'm not pretty sure where to unzip the contents of

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

2008-04-11 10:55 am


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

2009-01-08 10:44 am


This is VERY out of date - go check out
There you'll find instructions, links to libraries, and all the information you need

2009-01-08 11:15 am

Compiler une extension PHP (Zend Core) sous Windows « Wild PHP

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

2009-04-21 7:11 am



Is it possible to compile a x64 version of PHP?

The reason I ask is that I have been trying to for about three weeks using various tutorials, this wouldnt be so bad If I felt I was actually getting somewhere!

I have Visual Studio 2010 installed, MS SDK 7, and Win 7, and (please correct me if I am wrong) but the idea of compiling an application on your own machine is to take advantage of the precise architecture and set up of your own machine, I mean the compiled binary provided by PHP as an installation (if I am right) is generic and would not know what is actually available on my own set up.

any help or pointers would be gratefully recieved!


2010-07-06 2:23 am


Sure - check out for some more up to date instructions on compiling PHP

2010-07-12 5:07 am

Post a Reply