Building PHP5 on Win32

本文详细介绍了如何使用新的类似UNIX的构建系统和Microsoft Visual Studio 2003.NET来构建Windows版本的PHP5及其扩展。此外还提供了获取源代码、所需文件和其他工具的方法,并解释了配置构建环境及运行构建命令的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
Repository path: /repository
Username: cvsread
Password: phpfi
Hostname: cvs.php.net

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
cvs -d :pserver:cvsread@cvs.php.net:/repository checkout php-src

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
Checking for cl.exe ... <in default path>
Checking for link.exe ... <in default path>
Checking for nmake.exe ... <in default path>
Checking for lib.exe ... <in default path>
Checking for bison.exe ... /cygwin/bin
Checking for flex.exe ... /cygwin/bin
Checking for re2c.exe ... <not found>
Checking for zip.exe ... /cygwin/bin
Checking for lemon.exe ... <not found>
Checking for mc.exe ... C:/Program Files/Microsoft Visual Studio .NET 2003/Common7/Tools/bin
Checking for arpa/nameser.h ... ../bindlib_w32
Checking for library resolv.lib ... ../bindlib_w32/Release/resolv.lib

Build dir: Release_TS
PHP Core: php5ts.dll and php5ts.lib

Checking for wspiapi.h ... <in default path>
Enabling IPv6 support
Checking for NewAPIs.h ... <in default path>
Enabling SAPI sapi/cgi
Enabling SAPI sapi/cli
Enabling extension ext/bcmath
Enabling extension ext/calendar
Checking for library oleaut32.lib ... <in LIB path> OleAut32.Lib
Enabling extension ext/com_dotnet
Checking for mscoree.h ... <in default path>
Enabling extension ext/ctype
Enabling extension ext/ftp
Checking for library libjpeg.lib ... <not found>
Checking for iconv.h ... <not found>
Checking for iconv.h ... <not found>
Enabling extension ext/odbc
Enabling extension ext/pcre
Enabling extension ext/session
Enabling extension ext/spl
Enabling extension ext/sqlite
Enabling extension ext/standard
Enabling extension ext/tokenizer
Enabling extension ext/zlib
Checking for library zlib.lib ... ../zlib/Release/zlib.lib
Checking for zlib.h ... ../zlib
Checking for library libxml2_a.lib;libxml2.lib ... <not found>
Enabling extension ext/dom
Enabling extension ext/simplexml
Enabling extension ext/wddx
Enabling extension ext/xml

Creating build dirs...
Generating files...
Generating Makefile
Generating main/internal_functions.c
[content unchanged; skipping]
Generating main/config.w32.h
Done.

Type 'nmake' to build PHP

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.




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值