PDF版 ePub版

# 编译前的准备

### *nix Tools

C语言的编译器是我们使用C语言的必备工具，你的系统应该已经自带了一种C语言的编译器，而且它极有可能是大名鼎鼎的GCC。通过检测你本机gcc或者cc程序的版本，可以很方便的知道你机器上是否已经安装的某种C语言的编译器。

walu@walu-ThinkPad-Edge:~$gcc --version gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 如果你还没有安装编译器，那你需要安装一个。最简单的办法便是去下载一个与你系统相符的rpm或者deb包，当然你也可以通过以下命令的一种来方便的安装：yum install gcc, apt-get install gcc, pkg-add -r gcc, 或者 emerge gcc. 除了编译器，你还需要以下程序：make, autoconf, automake, 和libtool。说实话，我连autoconf现在是啥还不知道(截至到现在，2011年9月6号)，不过除非RP太低，一般系统中都会自备了，而且phpize程序会把这些需要的脚本给生成好的。 对于编译需要的程序以及它们的版本我们可以在PHP官网找到最新的答案： • autoconf: 2.13 (2.59+ for PHP 5.4+) • automake: 1.4+ • libtool: 1.4.x+ (except 1.4.2) • bison: 1.28, 1.35, 1.75, 2.0 or higher • flex (PHP 5.2 and earlier): 2.5.4 (not higher) • re2c: 0.13.4+ 你千万不要被上面的清单给吓着，其实系统应该给装备好了，除非真RP低，那你出门去买张彩票吧... ... 当然，我们也可以通过SVN从PHP源码库里导出一份源码，需要注意的是，PHP的svn源码库地址是https协议的。官方推荐我们直接签出它的php-src目录: $ svn checkout https://svn.php.net/repository/php/php-src --depth immediates php-src
\$ cd php-src

• PHP 5.3: svn checkout https://svn.php.net/repository/php/php-src/branches/PHP_5_3 php-src-5.3
• PHP 5.4: svn checkout https://svn.php.net/repository/php/php-src/branches/PHP_5_4 php-src-5.4
• PHP HEAD: svn checkout https://svn.php.net/repository/php/php-src/trunk php-src-trunk

### Win32 Tools

The Win32/PHP5 build system is a complete rewrite and represents a significant leap forward from the PHP4 build system. Instructions for compiling PHP4 under Windows are available on php.net, only the PHP5 build systemwhich requires Windows 2000, Windows 2003, or Windows XPwill be discussed here.

First, you'll need to grab libraries and development headers used by many of the core PHP extensions. Fortunately, many of these files are redistributed from php.net as a single .zip file located at http://www.php.net/extra/win32build.zip.

Create a new directory named C:\PHPDEV\ and unzip win32build.zip using your favorite zip management program into this location. The folder structure contained in the zip file will create a subdirectory, C:\PHPDEV\win32build, which will contain further subfolders and files. It's not necessary to name your root folder PHPDEV; the only important thing is that win32build and the PHP source tree are both children of the same parent folder.

Next you'll need a compiler. If you've already got Visual C++ .NET you have what you need; otherwise, download Visual C++ Express from Microsoft at http://lab.msdn.microsoft.com/express/.

The installer, once you've downloaded and run it, will display the usual welcome, EULA (End-User License Agreement), and identification dialogs. Read through these screens and proceed using the Next buttons after you've agreed to the terms of the EULA and entered any appropriate information.

Installation location is of course up to you, and a typical installation will work just fine. If you'd like to create a leaner installation, you may deselect the three optional componentsGUI, MSDN, and SQL Server.

The final package is the Platform SDK, also available for download from Microsoft at http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5. The site currently lists three download options: PSDK-x86.exe, PSDK-ia64.exe, and PSDK-amd64.exe. These options refer to x86 compatible 32bit, Intel64bit, and AMD64bit processors respectively. If you're not sure which one applies to your processor, select PSDK-x86.exe, which should work cleanly, albeit less efficiently, with both 64 bit variants.

As before, proceed through the first few screens as you would with any other installer package until you are prompted to select between Typical and Custom installation. A Typical installation includes the Core SDK package, which is sufficient for the purposes of building PHP. Other packages can be deselected by choosing a Custom installation, but if you have the hard disk space to spare, you might as well install it all. The other packages may come in handy later on.

So unless you're byte conscious, select Typical and proceed through the next couple of standard issue screens until the installer begins copying and registering files. This process should take a few minutes so grab some popcorn.

Once installation is complete you'll have a new item on your Start menuMicrosoft Platform SDK for Windows Server 2003 SP1.