I recently spent some time trying to build PHP on Windows, I succeeded in the end but it took rather longer than I'd have liked. I normally use the Windows PHP binaries available from snaps.php.net, but in this case I was trying to test whether a proposed patch would fix a Windows specific defect - so I really had to be able to build PHP. I particularly wanted to use a "free" development environment and, as a Windows novice (and life-time *nix user) I hit a lot of simple issues which took a while to solve. I decided to document the steps that I went through in building PHP in the hope that they might be useful to anyone else that would like to build PHP on a Windows system.
These instructions are intended to cover everything that you need to do to be able to build PHP on a Windows XP system. They may work on other Windows systems, I haven't checked. No prior knowledge is assumed, except how to perform basic operations using the windows command line (eg mkdir, copy) and how to use an editor (eg edit) and no software (other than Windows) is assumed to be installed.
The instructions have been tested with PHP6 and PHP5, the only difference being that any references to ICU can be ignored if you are building PHP5.
Before starting to build anything you will need to download a set of tools from Microsoft. This can take some time, for example it took me 45 minutes to install the build tools whilst in the office working with a high speed ethernet connection. Working at home with my own broadband connection it took me 4.5 hours to do the same thing. I don't recommend a dial up connection if you can possibly avoid it. The build tools will use approximately 500MB of disk space.
- Get the Visual C++ 2005 Express Edition compiler from here
- Check that you have the right operating system and processor to be able to use the compiler.
- Click download and then run, or save to disk and then run if you prefer.
- Read and accept the licence and all default settings.
- The compiler will be installed here: C:\Program Files\Microsoft Visual Studio 8\
- At the end you will be asked to register - this takes about 5 minutes, if you don't do it something will keep nagging you.
- Get the Windows Server 2003 SP1 Platform SDK, here.
- There are three options, I chose PSDK-x86.exe as I'm running a 32 bit Windows system. The other two are for amd64 and ia64 systems.
- Click download and then run, or save to disk and then run if you prefer.
- Read and accept the license, then click through the next screens.
- Select "typical" install.
- The code will be installed in: C:\Program Files\Microsoft Platform SDK\
- This is a long installation - 20 minutes on my office connection, 2 hours from home.
Note: There is a more recent version of the SDK that I didn't find until after I'd used the one linked above. The newer version can be found here. I haven't tried it yet so can't say whether it works with these instructions.
- Get the .NET Framework 2.0 SDK from here. Careful - it takes a couple of minutes to start up and can put the installation window behind the one you are working in.
- Click run, then read and accept the license.
- On the installation options screen just select the Tools and Debugger - you won't need samples or doc.
- Take default installation folder (will be put under the same directory as the Visual C++).
- This is a long download - two hours on my home connection.
There are a number of these - I used this and it worked fine. I just downloaded it and followed the installation instructions
First decide what directory structure you want for your build environment, I use e:\zoe\BUILDS so everywhere I refer to that directory you will need to replace it with whatever you have decided to call your build directory.
I found that the easiest way to extract .zip files on Windows was to open them with Explorer and select "extract all files".
At the end of this section the sub-directory structure should look like this:
| |-winbld32 |e:\zoe\BUILDS - |-bindlib | |-icu | |-php6.0YYYYMMDDHHmm (or php5.0YYYYMMDDHHmm if you are building PHP5) |
- Put the windows build tools in e:\zoe\BUILDS (win32build.zip)
- Extract the zip file into e:\zoe\BUILDS\win32build
- Extract bindlib into e:\zoe\BUILDS\bindlib\
- Get the ICU libraries, extract them into e:\zoe\BUILDS\icu. I downloaded this:
icu4c-3_6-Win32-msvc7_1.zip 6.1MB Windows (win32 x86 32-bit) Visual Studio.Net 2003 (MSVC 7.1)
- Get PHP - I used the PHP snaps site and downloaded the tar.gz file. I copied it to my e:\zoe\BUILDS directory and used the tar utility (step 1) to extract the contents into e:\zoe\BUILDS\php6.0-YYYYMMDDHHmm
Before we can build anything, a little customisation is required to make Visual Studio Express work nicely with the SDK and to tell the build tools where to find the libraries that PHP needs to build. For reference, flex and bison are part of win32build directory and ICU is in the ICU directory. If you are building PHP5 you won't need ICU of course.
- Add paths to the vsvars32.bat file
In directory C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\ edit vsvars32.bat to include references to the Platform SDK in PATH, INCLUDE and LIB.
The relevant lines in my copy look like this:
@set PATH=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;C:\Program Files\Microsoft Visual Studio 8\VC\BIN;C:\Program Files\Microsoft Visual Studio 8\Common7\Tools;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 8\VC\VCPackages;C:\Program Files\Microsoft Platform SDK\Bin;%PATH%@set INCLUDE=C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE;c:\Program Files\Microsoft Platform SDK\Include;%INCLUDE%@set LIB=C:\Program Files\Microsoft Visual Studio 8\VC\LIB;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\lib;c:\Program Files\Microsoft Platform SDK\Lib;%LIB%
- Renaming winres.h
In directory C:\Program Files\Microsoft Platform SDK\Includecopy the file WinResrc.h to winres.h
- Changes to environment variables.
- Start->Control panel->System->Advanced->Environment variables
- Edit (or add) "path" to add e:\zoe\BUILDS\icu\bin;e:\zoe\BUILDS\win32build\bin
- Edit (or add) "include" to add e:\zoe\BUILDS\icu\include;e:\zoe\BUILDS\win32build\include
- Edit (or add) "lib" to add e:\zoe\BUILDS\icu\lib;e:\zoe\BUILDS\win32build\lib
These changes won't take effect in any windows that you currently have open - you will need to close them and re-open.
- Start up the build environment
- Start -> Visual C++ 2005 Express Edition -> Visual Studio Tools -> Visual Studio 2005 Command Prompt.
- Building resolv.lib.
- In the Visual Studio window, cd e:\zoe\BUILDS\bindlib
- vcexpress (to start the GUI)
- File - > Open -> Project/Solution -> bindlib.dsp
- You'll get a warning about needing to convert bindlib.dsp to the current format. At "Convert and Open", click "yes".
- Now click on Project->Properties->Configuration properties->C/C++/General
- At the top, click "configuration manager" then select "release" and Win32" as the active configurations
- Under additional Include Directories, add (after the dot) ;c:\Program Files\Microsoft Platform SDK\Include and then click OK (this tells it where to find Winsock.h)
- Finally - click on Build and select Build bindlib.
Assuming the the build is successful you can close the GUI - you should find a sub-directory in bindlib called Release. Copy the file resolv.lib from there to e:\zoe\BUILDS\win32build\lib, overwriting the one that's already there.
- Building PHP
- From within your VS C++ window, change directory to the place that you extracted the PHP source
- At the command line, type:
- cscript /nologo configure.js "--with-extra-libs=e:\zoe\BUILDS\icu" "--with-extra-includes=e:\zoe\BUILDS\icu\include" "--without-s
implexml" "--enable-prefix=e:\php6" "--disable-zlib" "--disable-odbc" "--disable-cgi" "--enable-cli" "--without-iconv" "--without-
- nmake install
- Run a test to make sure that the build succeeded
- Create a file called test.php with the following contents <?php phpinfo() ?>
- At the command line, type "e:\php6\php.exe test.php"
Guillaume Rossolini has translated this into French - see here: here
Guillaume has also tried the newer version of the Microsoft Platform SDK and has confirmed that it works too. The only difference is that the installation folder is: C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2.
Merci beaucoup Guillaume!!