Custom Building PHP on Windows and Linux

At the encouragement of Elizabeth Smith, I went through the process (not-so-recently as of this blog entry) of compiling PHP on Windows. I actually managed to get 5.2.5 and 5.3 both working on Windows XP. Major credit for success in that endeavor goes to Elizabeth herself who helped me through hurdles in the process, her older tutorial on compiling PHP 5.2 on XP using VCE 2005, and Pádraic Brady’s tutorial for compiling PHP 5.3 on Vista using VCE 2008.

First off, there are a few hefty things to download and install. Here’s the laundry list.

Beyond the slight differences in the software required, the process described in Elizabeth’s tutorial is still fairly accurate. One thing I noticed for 5.2.5 is that there’s an issue with including IPv6 support, which is done by default when you configure your build. When you try to compile, you’ll probably see an error that looks like this.

network.c(897): error C2065: 'in6addr_any': undeclared identifiernetwork.c(897): error C2440: '=' : cannot convert from 'int' to  'IN6_ADDR'

There are two ways to get around this. The first is to include the –disable-ipv6 flag in the configure line. The other is applying the changes in lines 94-96 of a fairly simple patch to your network.c file so that it includes these lines in the proper place.

#if HAVE_IPV6const struct in6_addr in6addr_any = {0}; /* IN6ADDR_ANY_INIT; */#endif

Another issue is that you may receive an error regarding libmysql.dll not being found when you attempt to run nmake test. You must have the directory containing this file either in your PATH or parallel to php5ts.dll, as these are the only places that Windows will look for it. Thanks again to Elizabeth for this tip.

OK, hopefully the Linux people haven’t left yet. (You guys have a slightly more short and sweet segment in this blog entry.) I also did a custom build of 5.3 on Debian recently to use in running Phergie. I wanted to do a minimal local build to optimize performance (5.3 includes the garbage collection patch) as well as to include a few extensions that Phergie uses. One of these was the pspell extension for her Spellcheck plugin. I don’t have root access to the system on which I was going to run her, and since it didn’t have the aspell libraries already installed, I had to compile those from source as well. Here’s how I did it.

First, aspell itself.
wget -c
tar -zxvf aspell-0.60.5.tar.gz
cd aspell-0.60.5
./configure –prefix=/path/to/aspell-0.60.5/build
make install

Next, the English dictionary for aspell.

wget -c
bunzip2 aspell6-en-6.0-0.tar.bz2
tar -xvf aspell6-en-6.0-0.tar
cd aspell6-en-6.0-0
./configure –vars ASPELL=/path/to/aspell-0.60.5/build/bin/aspell \
make install

And finally, PHP with the pspell extension compiled in.

wget -c
tar -zxvf php5.3-200803032330.tar.gz
./configure –disable-cgi –without-sqlite –enable-pcntl \
–prefix=/path/to/php-5.3/build/php_build \
make test
make install

And presto, that’s all there was to it.


  1. DM says:

    Do you have any tips on compiling the PECL Perl extension for Windows by anychance? The dll provided on pecl4win is out of date and only works on php

  2. AWS says:

    Re: compiling under linux…

    1. Are you sure your directions are right? You installed aspell at “/path/to/aspell-0.60.5/build”, and then you configure php with “–with-pspell=/path/to/php-5.3/build/aspell-0.60.5/build”. I wouldn’ve expected those two paths to be the same.

    2. Is that a special php version you’re using? I see it’s a 5.3 from the snapshot build server. Does that mean this technique won’t work on php 5.2.6?

  3. @DM Unfortunately I don’t. You might check out though because she’s the Queen of compiling PHP on Windows. ;)

    @AWS Thanks for the correction on #1! :) On #2, I was compiling a snapshot build of 5.3 to take advantage of the new garbage collection because I’m using the build to run what’s essentially a daemon process. As far as I know, there’s no reason that it shouldn’t also work with 5.2.6, but I can’t speak to that because I haven’t actually tried it myself.