For three days I fought with compiling PHP5.2 on windows. The point was to be able to compile PHP-GTK2 a little more often (there are at least two bugfixes in CVS that I need for my writer project) and asking on the list/irc for compiled versions got me some smartass answer about "learn to do it yourself". Ah, how kind and accepting geeks are.
But I'm always up for learning something new and I thought I had enough google skills and entry level knowledge to get things going. Alas, it has all failed.
Here's my little adventure.
Windows Free (as in money, not beer) Compile Tools
Step one involved setting up a compile environment. There are supposedly several tools that can be used, PHP supports Microsoft Visual C++ 6.0 and Visual C++ .NET. The problem with that is both of those are on the expensive side and since this isn't for profit I don't have the money to shell out for a "real" version. My oldest son needs new shoes and the baby needs diapers, anything over free is not an option. But PHP > 5 (which is the only thing we'll be compiling) also supports Microsoft .Net Toolchain, according to the documentation. This used to consist of three parts. The Microsoft Visual C++ Toolkit, the Windows Platform SDK, and the .NET Framework SDK. The Toolkit, you'll see, has been "replaced" by the Visual C++ Express Edition but since the stuff underneath is the supposedly the same I figured I'd give it a go.
I run Windows XP Professional SP2 and keep myself patched up. I had a nice big spot on my hard drive and downloaded the Visual C++ Express Edition. I didn't install the msdn library or the SQL Server express edition. After the fun of a huge download, install, and registration I headed to the next step. I did register the thing - it didn't cost anything and I hate the nags. Of course, Microsoft knows all about me now and I had to have a ...well it used to be a passport but I still have an old hotmail account lying around I use for msn messenger...
After getting Visual C++ Express up and running I STILL needed the Windows Platform SDK (which is HUGE btw). So another big download and install. This takes up lots of room and takes a LONG time. After I'd finished installing the monster I had to tell Visual C++ Express how to use it properly. MSDN has the full instructions for this fun and exciting process. (I hope you're detecting the sarcasm there...)
Here's the quick version. The basic idea is you need to add the lib, include and bin directories from the location of your newly installed windows platform sdk to VC++ Directories (it's under options->projects and solutions). Notice the little dropdown in the upper right hand corner? add the path to "location of sdk/bin" to executables, "location of sdk/include" to includes and "location of sdk/lib" to libraries, changing the drop down to access each different type. My paths were kind of goofy - "C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\bin" for example...gah. After those three locations were added I had to edit some files. corewin_express.vsprops goes in %VSINSTALLDIR%\VC\VCProjectDefaults and default.js goes in %VSINSTALLDIR%\VC\VCWizards\AppWiz\Generic\Application\scripts\1033 where %VSINSTALLDIR% is the location where Visual C++ is installed - mine is C:\Program Files\Microsoft Visual Studio 8.
There's one more thing to install, the .Net Framework SDK which is needed for the com/.net stuff. Another huge download - it detected my VCE installation and put the files where they belong inside the VCE directory. But I still had to add the locations just like I did for the sdk. So far so good. I have a working and FREE compile environment.
And now for some PHP
First of all I need some "extra" files for PHP on windows - grabbed the PHP 5.2 sourcecode either from the official release or a snap . I personally would prefer snapshots (because I'm nuts) but I decided to do the official 5.2 release first. I then grabbed the win32build tools and the PHP DNS name resolver. Since I planned on compiling only the cli SAPI and embed I didn't need apache sources. I followed the extensive instructions under "putting it together" from the php manualto get my directory structure is set up properly.
Now, remember how I added the windows platform sdk and .net sdk to the bin/include/library stuff in Visual C++? I got to do that again, only this time with the items in the win32build/bin win32build/include win32build/lib directories.
According to the php documentation, you're supposed to build the resolv.lib first - no problem. I headed to bindlib_win32 and double clicked on the bindlib.dsw. It opened up and some question popped up - doesn't really matter but I tend to say yes to annoying windows questions. I headed to the configuration manager and choose Release. Then build->rebuild. Checked the bottom pane for information about what's happening. I got a bunch of warnings - just ignored them. Voila, appeared to build just jim dandy.
The "new" php build environment likes to be run from the command line. The problem is that those nice additional items I added to the gui don't automatically get added to the command line build(wasn't that nice of ms?) So I had to find vsvars32.bat. Mine was located in C:\Program Files\Microsoft Visual Studio 8\Common7\Tools. Edited it and added the win32build, .net sdk and windows platform sdk locations to the PATH (for the /bin), INCLUDE (for the /include), and LIB (for the /lib) locations. Seperate them by semi-colons. Mine looks like this.
Now, PHP5 uses some additional external libraries. LibXml is a prominent one, and unless I disabled xml, simplexml, dom, xmlwriter, xmlreader...well basically every single xml related extension I would need it. Search around the internet and found a download for both. Unzipped the two and dumped them where they'd be found.
So I opened up the Visual C++ command line. There was a nice prompt all ready for me in the start menu. So I cd to myphp source directory in that cmd window and run buildconf.bat.
Next follow the directions - run cscript /nologo configure.js --help This showed all the configure options available. Created a nice configure line for how I wanted php set up. The manual has a bunch of information on this. Mine looked like this
cscript /nologo configure.js cscript /nologo configure.js "--without-gd" "--disable-cgi" "--enable-cli-win32" "--enable-embed" "--disable-json" "--enable-pdo" "--with-pdo-sqlite" "--without-dom" "--disable-xmlwriter" "--disable-xmlreader"
Configure looks good - start nmake
All the way to the END and the linker fails complaining about 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 I found WinResrc.h, (somewhere in the include dir of the windows platform sdk) copied it, and rename the file winres.h
run the configure again just for the hell of it
All the way to the end and the linker fails AGAIN.
Creating library Release_TS\php5ts.lib and object Release_TS\php5ts.exp
resolv.lib(inet_addr.obj) : error LNK2019: unresolved external symbol __pctype r
eferenced in function _inet_aton
resolv.lib(inet_addr.obj) : error LNK2019: unresolved external symbol ___mb_cur_
max referenced in function _inet_aton
Release_TS\php5ts.dll : fatal error LNK1120: 2 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\l
ink.exe"' : return code '0x460'
What the heck? So I start doing some searching - I try rebuilding resolv.lib again, download a version from cvs and build it again, download a resolv.lib from another site... turned off EVERYTHING and tried to build and ended up with weird iconv and libxml errors - even with --disable-all
So it's been three days and I'm an inch from the finish line and completely pissed off because of course I'm supposed to be some kind of genius and figure it out myself. And the minute you mention compile php on windows the whole world tunes you out.