Jan 28 2005 07:02:46 Building PHP5 on Win32 This article describes how to use the new 'UNUX' like build system and Microsoft Visual Studio 2003 .NET to build the Windows version of PHP5, including many of the extensions. It is also possible to use Microsoft Visual Studio 97 (also known as Microsoft Visual C/C++ 6.0). This version includes the same command-line tols though these are older versions and has a few known limitations. The resulting programs from either version of the C compiler works equily fine. If you are interested in building PHP4 for Win32 you need Microsoft Visual Studio 97. The PHP5 source three still includes .dsp and .dsw files designed to work with Microsoft Visual Studio 97, but not all the extensions are covered by this build system. Note: Windows binaries are provided at http://snaps.php.net and on this site. If you don't plan to change the configuration or to build you own extensions there should be no need to compile it. It's much faster to download the precompiled version. |
Getting PHP Source files You can download the latest version of the source code from snaps.php.net or you can use a cvs client to get the very latest version version directly from the cvs repository. WinCVS is a very powerfull and graphical cvs client for Windows. You need to configure the following parameters to checkout the module for the latest version of PHP5: protocol: pserver The name of the module to check out is php-src and if you don't specify a branch you will get HEAD. The command line version that is described on http://php.net can also be used: cvs -d :pserver:cvsread@cvs.php.net:/repository login If you are working with multiple versions of PHP on the same system I would recommend that you rename the php-src directory to PHP5 or PHP5.1. That makes it easier to figure out which version you are working with. If you need to update the source three you can use the cvs update command: cvs update -d -P The -d option indicates that you want new directories created if they do not exist on your system. The -P option indicates that empty directories weill be deleted. Some of the PHP extensions are stored in an aditional repository called PECL. You can perform a checkout on this module as well to obtain additional extensions. The PECL module should be checked out to a directory next to, and on the same level, as the php source three or in the php source three next to the ext sub-directory. The command to checkout the PECL module is: cvs -d :pserver:cvsread@cvs.php.net:/repository checkout pecl Note that it's no longer needed to perform the login command. Your system will store the login information in a file until you actually perform a logout. This does not mean that you keep a connection open, just that you don't need to perform the login each time you want to update the cvs three. If you are downloading one of the source packages from snaps.php.net you will have to unpack the contents to a local directory. WinZip can handle tar.gz files by decompressing the file into a tar file and then showing/extracting the content. Getting required sources files Some of the extensions that are build-in (zlib, simplexml, dom, xml), requires additional sources. You can either download these sources, or in some cases binary distributions or you can disable these exensions. The zlib can be found in PHP's cvs repository and can be checked out with this command: cvs -d:pserver:cvsread@cvs.php.net:/repository checkout zlib The iconv and libxml binaries can be found here. You can also download a complete (but old) set of header files and libraries from http://www.php.net/extra/win32build.zip. This file should be unpacked next to the php5 source three, and the folder renamed to php_build. Providing header and library files to many of the php extensions is not possible as these most often are proprietery code under a closed source license. Note: I'm working on an updated version of this zip file that will make it possible to compile at least the basic stuff without having to download additional packages. Getting other tools Before you can build PHP from the source files you need two tools (flex and bison). These are not included in Microsoft Visual Studio. An easy way to get these, and many other tools ported from the UNIX world, is to download and install CygWin. Make sure you are installing the development tools. Preparing the build environment The first step is to execute the buildconf script. This is a .bat file on the windows system, and it is used to scan all the sub-directories under ext for config.w32 files. If you have the PECL module installed either next to the php5 source three or next to the ext sub-directory that directory will be included in the scan. The result of the scan is a file called configure.js. This is the basic script that is used to build the specific configuration with all the options and extensions you want. The buildconf script might display some information about modules that are being skipped. That's normal and is caused by some modules existing in both ext and pecl directories. At the end the script shows what to do next: Now run 'cscript /nologo configure.js --help' This command will display all the options that are available to the configure script. It's a very long list of parameters, and if you are new to the concept of configire and make this might seam overwelming. Running configure If you are used to building stuff on Unix/Linux yoy would simply run ./configure at this point, but Windows does not recognise the configure.js script as a valid command so you have to run it trough the cscript command. cscript /nologo configure.js /nologo is not needed but it removed the Microsoft banner from the output. This command prepares the Makefile to build the default configuration of PHP. The output will look like this: Saving configure options to config.nice.bat It shows that CGI and CLI SAPI's are build and a number of extensions are included as build-ins. Getting help from configure.js The configure script is generated from all the individual config.w32 files located in the subdirectories under the ext/ or pecl/ directories. This makes it possible for the configure script to show a list of available options. cscript /nologo configure.js --help Will display a long list of options and explanations. Click here to view a sample output from the configure.js script. Running nmake.exe Nmake.exe is the tool (provided with Visual Studio 97 and Visual Studio .NET) thats used to compile and link all the files. running nmake.exe after a sucessfully running configure will produce all the .dll and .exe that was requested by the configuration. Depending on the target selected these files will all end up in a sub folder called Release, Release_TS, Debug or Debug_TS. You can choose to build single files, by adding the filenames as optional parameters to the nmake command so you don't have to wait for the build to go through all files each time. This is ofthe used if you are making changes to the code. nmake php_mssql.dll php_fbsql.dll If you want to install the php files on the system where you are building you can run 'nmake install'. This will copy the files to the directory specified by the configure option --enable-prefix. The default directory is c:/php5 for the Release and Release_TS targets. nmake install This command will compile and link the binaries if the source files were changed since last compilation and then copy all the files to the selected directory and it will run the regsvr32 program to register the syslog handler to use Windows EventLog for messages and errors from PHP. |