This chapter teaches how to compile PHP from sources on windows, using Microsoft's tools. To compile PHP with cygwin, please refer to Installation on Unix systems.
This step-by-step quick-start guide was written in March of 2008, running Windows XP Service Pack 2 with all the latest updates and building PHP 5.2.5 and PHP 5.3. Experiences using different tools may differ.
Download and install:
+-C:\work | +-bindlib_w32 | | +-Debug | | | +-resolv.lib | | | +-... | | +-... | +-win32build | | +-bin | | +-include | | +-lib | +-php-5.2.5 | | +-build | | +-win32 | | +-...
C:\Program Files\Microsoft Visual Studio 9.0\VC> set "PATH=C:\work\win32build\bin;%PATH%" C:\Program Files\Microsoft Visual Studio 9.0\VC>
To compile and build PHP you need a Microsoft Development Environment. The following environments are supported:
While VC6 (Microsoft Visual C++ 6.0) is used to perform official Windows builds, it can no longer be downloaded from Microsoft's website. New users seeking to build PHP for free must use Microsoft Visual C++ 2005 Express Edition and its auxiliary components.
Note: Combined, these components are very large and will require over one gigabyte of disk space.
Setting up Microsoft Visual C++ 2005 Express is rather involved, and requires the installation of three separate packages and various compatibility changes. Be sure to keep track of the paths in which these programs are installed into. Download and install the following programs:
There are a few post-installation steps:
Finally, when using MSVC 2005 Express from the command line, several environment variables must be set up. vsvars32.bat usually found in C:\Program Files\Microsoft Visual Studio 8\Common7\Tools (search for the file if otherwise) contains these declarations. The PATH, INCLUDE and LIB environment variables need the corresponding bin, include and lib directories of the two newly installed SDKs added to them.
Note: The .NET SDK paths may already be present in the vsvars32.bat file, as this SDK installs itself into the same directory as Microsoft Visual C++ 2005 Express.
To extract the downloaded files you will also need a ZIP extraction utility. Windows XP and newer already include this functionality built-in.
Before you get started, you have to download:
After downloading the required packages you have to extract them in a proper place:
Following this steps your directory structure looks like this:
+--C:\work | | | +--bindlib_w32 | | | | | +--arpa | | | | | +--conf | | | | | +--... | | | +--php-5.x.x | | | | | +--build | | | | | +--... | | | | | +--win32 | | | | | +--... | | | +--win32build | | | | | +--bin | | | | | +--include | | | | | +--lib
If you aren't using » Cygwin, you must also create the directories C:\usr\local\lib and then copy bison.simple from C:\work\win32build\bin to C:\usr\local\lib.
Note: If you want to use PEAR and the comfortable command line installer, the CLI-SAPI is mandatory. For more information about PEAR and the installer read the documentation at the » PEAR website.
You must build the resolv.lib library. Decide whether you want to have debug symbols available (bindlib - Win32 Debug) or not (bindlib - Win32 Release), but please remember the choice you made, because the debug build will only link with PHP when it is also built in debug mode. Build the appropriate configuration:
At this point, you should have a usable resolv.lib in either your C:\work\bindlib_w32\Debug or Release subdirectories. Copy this file into your C:\work\win32build\lib directory over the file by the same name found in there.
This chapter explains how to compile PHP >=5 using the new build system, which is CLI-based and very similar with the main PHP's Unix build system.
Note: This build system isn't available in PHP 4. Please refer to Building from source instead.
First you should open a Visual Studio Command Prompt, which should be available under the Start menu. A regular Command Prompt window shouldn't work, as probably it doesn't have the necessary environment variables set. Then type something like cd C:\work\php-5.x.x to enter in the PHP source dir. Now you are ready to start configuring PHP.
The second step is running the buildconf batch file to make the configure script, by scanning the folder for config.w32 files. By default this command will also search in the following directories: pecl; ..\pecl; pecl\rpc; ..\pecl\rpc. Since PHP 5.1.0, you can change this behaviour by using the --add-modules-dir argument (e.g. cscript /nologo win32/build/buildconf.js --add-modules-dir=../php-gtk2 --add-modules-dir=../pecl).
The third step is configuring. To view the list of the available configuration options type cscript /nologo configure.js --help. After choosing the options that you will enable/disable, type something like: cscript /nologo configure.js --disable-foo --enable-fun-ext. Using --enable-foo=shared will attempt to build the 'foo' extension as a shared, dynamically loadable module.
The last step is compiling. To achieve this just issue the command nmake. The generated files (e.g. .exe and .dll) will be placed in either Release_TS or Debug_TS directories (if built with Thread safety), or in the Release or Debug directories otherwise.
Optionally you may also run PHP's test suite, by typing nmake test. If you want to run just a specific test, you may use the 'TESTS' variable (e.g. nmake /D TESTS=ext/sqlite/tests test - will only run sqlite's tests). To delete the files that were created during the compilation, you can use the nmake clean command.
A very useful configure option to build snapshots is --enable-snapshot-build, which add a new compiling mode (nmake build-snap). This tries to build every extension available (as shared, by default), but it will ignore build errors in individual extensions or SAPI.
Compiling PHP using the DSW files isn't supported as of PHP 5, as a much more flexible system was made available. Anyway, you can still use them, but keep in mind that they are not maintained very often, so you can have compiling problems. To compile PHP 4 for windows, this is the only available way though.
The first step is to configure MVC++ to prepare for compiling. Launch Microsoft Visual C++, and from the menu select Tools => Options. In the dialog, select the directories tab. Sequentially change the dropdown to Executables, Includes, and Library files. Your entries should look like this:
The best way to get started is to build the CGI version:
It is possible to do minor customization to the build process by editing the main/config.win32.h file. For example you can change the default location of php.ini, the built-in extensions, and the default location for your extensions.
Next you may want to build the CLI version which is designed to use PHP from the command line. The steps are the same as for building the CGI version, except you have to select the php4ts_cli - Win32 Debug_TS or php4ts_cli - Win32 Release_TS project file. After a successful compiling run you will find the php.exe in either the directory Release_TS\cli\ or Debug_TS\cli\.
In order to build the SAPI module (php4isapi.dll) for integrating PHP with Microsoft IIS, set your active configuration to php4isapi-whatever-config and build the desired dll.