win10 vs2015 php源码编译

来源:互联网 发布:linux架设代理服务器 编辑:程序博客网 时间:2024/06/09 17:31

php源码代码量较小,thinkpad x240 15分钟内,即可完成一个版本的编译。


1 必要资源


vc2015下载地址:https://www.visualstudio.com/downloads/download-visual-studio-vs

php官网:http://www.php.net/

php 在windows上编译步骤官网说明:https://wiki.php.net/internals/windows/stepbystepbuild

根据官网说明,PHP7.0+使用VS2015编译。
编译PHP7.0+ 使用vs2015 x64命令行环境("C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat")或者vs2015 x86命令行环境("C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat")

下载php源码官网:https://github.com/php/php-src.git
# PHP源码 github 镜像地址,源码下的 README.WIN32-BUILD-SYSTEM 文件,介绍了windows下编译方法


2 源码下载
从github 的 php源码镜像下载最新php源码,并迁出最想要的版本。

cd d:\git\
git clone https://github.com/php/php-src.git
git checkout -bphp-7.1.0RC1 php-7.1.0RC1


3 编译准备工具

创建PHP编译工具目录:mkdir d:\php-sdk
创建存放编译工具目录:mkdir d:\php-sdk\tools
下载编译工具:
windows php编译工具1 php-sdk-binary-tools最新版保存到d:\php-sdk\tools\php-sdk-binary-tools-20110915.zip
下载windows PHP编译工具。http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip
加压到d:\php-sdk,有bin、script、share3个目录

下载php-sdk编译依赖包,我们要编译php7的x64位版本。
D:\php-sdk\tools\deps-7.1-vc14-x64.7z
D:\php-sdk\tools\deps-7.1-vc14-x86.7z
http://windows.php.net/downloads/php-sdk/deps-7.1-vc14-x64.7z
http://windows.php.net/downloads/php-sdk/deps-7.1-vc14-x86.7z

创建必备条件:
cd d:\php-sdk
bin\phpsdk_buildtree.bat phpdev
xcopy /E phpdev\vc9\* phpdev\vc11\
xcopy /E phpdev\vc9\* phpdev\vc14\

解压 D:\php-sdk\tools\deps-7.1-vc14-x64.7z 到 D:\php-sdk\phpdev\vc14\x64\
解压 D:\php-sdk\tools\deps-7.1-vc14-x86.7z 到 D:\php-sdk\phpdev\vc14\x86\


4 开始编译:


4.1 php x64位编译

cd d:\php-sdk
bin\phpsdk_setvars.bat
cd d:\git\php-src

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat"

buildconf

# 生成编译输出目录
mkdir d:\phpbuild\x64
configure --disable-calendar --enable-object-out-dir=d:\phpbuild\x64 --with-php-build=D:\php-sdk\phpdev\vc14\x64\deps

# debug版本
# configure --enable-debug --disable-calendar --enable-object-out-dir=d:\phpbuild\x64 --with-php-build=D:\php-sdk\phpdev\vc14\x64\deps

# *************************************************
# 注意:--enable-calendar=shared 这里修改ext/calendar/jewish.c文件的编码,也可以使用--disable-calendar
# 正式生成 dll 共享版本
# 编译通过,如果要成功生成php_oci8_12c.dll,必须有oracle客户端的配置。php_pdo_oci.dll也需要oracle客户端配置。
# configure --enable-object-out-dir=d:\phpbuild\x64 --with-php-build=D:\php-sdk\phpdev\vc14\x64\deps --enable-cli-win32 --enable-embed --enable-phpdbg --enable-calendar=shared --with-toolset --with-mp --with-extra-includes --with-extra-libs --with-snapshot-template --with-analyzer=shared --with-codegen-arch --with-all-shared --with-bz2=shared --with-curl=shared --with-dba=shared --with-enchant=shared --enable-fileinfo=shared --enable-ftp=shared --with-gettext=shared --with-gmp=shared --with-mhash=shared --with-imap=shared --with-interbase=shared --enable-intl=shared --with-ldap=shared --with-libmbfl=shared --enable-mbstring=shared --enable-mbregex=shared --with-mcrypt=shared --with-oci8=shared --with-oci8-11g=shared --with-oci8-12c=shared --with-odbcver --enable-odbc=shared --with-openssl=shared --with-pgsql=shared --with-pspell=shared --with-snmp=shared --enable-sockets=shared --with-sqlite3=shared --with-config-file-scan-dir=shared --enable-sysvshm=shared --with-tidy=shared --enable-exif=shared --with-mysqli=shared --enable-pdo=shared --with-pdo-dblib=shared --with-pdo-mssql=shared --with-pdo-firebird=shared --with-pdo-mysql=shared --with-pdo-oci=shared --with-pdo-odbc=shared --with-pdo-pgsql=shared --with-pdo-sqlite=shared --with-pdo-sqlite-external=shared --enable-phar-native-ssl --enable-soap=shared --with-xmlrpc=shared --with-xsl=shared --with-gd=shared

# debug版本 正式生成 dll 共享版本
# configure --enable-debug --enable-object-out-dir=d:\phpbuild\x64 --with-php-build=D:\php-sdk\phpdev\vc14\x64\deps --enable-cli-win32 --enable-embed --enable-phpdbg --enable-calendar=shared --with-toolset --with-mp --with-extra-includes --with-extra-libs --with-snapshot-template --with-analyzer=shared --with-codegen-arch --with-all-shared --with-bz2=shared --with-curl=shared --with-dba=shared --with-enchant=shared --enable-fileinfo=shared --enable-ftp=shared --with-gettext=shared --with-gmp=shared --with-mhash=shared --with-imap=shared --with-interbase=shared --with-ldap=shared --with-libmbfl=shared --enable-mbstring=shared --enable-mbregex=shared --with-mcrypt=shared --with-oci8=shared --with-oci8-11g=shared --with-oci8-12c=shared --with-odbcver --enable-odbc=shared --with-openssl=shared --with-pgsql=shared --with-pspell=shared --with-snmp=shared --enable-sockets=shared --with-sqlite3=shared --with-config-file-scan-dir=shared --enable-sysvshm=shared --with-tidy=shared --enable-exif=shared --with-mysqli=shared --enable-pdo=shared --with-pdo-dblib=shared --with-pdo-mssql=shared --with-pdo-firebird=shared --with-pdo-mysql=shared --with-pdo-oci=shared --with-pdo-odbc=shared --with-pdo-pgsql=shared --with-pdo-sqlite=shared --with-pdo-sqlite-external=shared --enable-phar-native-ssl --enable-soap=shared --with-xmlrpc=shared --with-xsl=shared --with-gd=shared
# *************************************************


# 如果目录不存在,会提示如下错误
ERROR: you chosen output directory D:\phpbuild\x64 does not exist
成功后,出现
----------------------------------------------
|                 |                          |
----------------------------------------------
| Build type      | Release                  |
| Thread Safety   | Yes                      |
| Compiler        | MSVC14 (Visual C++ 2015) |
| Architecture    | x64                      |
| Optimization    | PGO disabled             |
| Static analyzer | disabled                 |
----------------------------------------------

生成 D:\phpbuild\x64\Release_TS 目录下

# 开始编译,php二进制文件
nmake

# 生成php发布包和开发包
nmake snap
# 生成php-7.1.0RC1目录,是发布目录
# 生成的php-7.1.0RC1\snapshot.txt文件,可以看到各个组件的依赖
# 生成的php-7.1.0RC1-devel-VC14-x64目录,是开发php扩展等需要的目录
# 生成 php-7.1.0RC1-Win32-VC14-x64.zip 文件,是没有带 vs 发布依赖dll的 php 发布压缩包


// 如果要编译 calendar,由于编码的问题,在正式编译之前,需要修改php源码里以下文件的编码为utf8:
// ext/calendar/jewish.c
//
// 也可以直接把calendar模块给禁用掉:
// --disable-calendar
// 正式编译:
// nmake snap # 这个过程需要的时间较长。在编译的过程,如果出现问题需要重新编译,可以使用以下命令:
// nmake clean all
// namke snap

测试PHP
编译好的文件存放在php源码文件夹里的Release_TS文件夹里(也可能没有TS后缀,这取决于编译命令里是否允许线程安全)。切换到该目录下,运行以下命令:
php.exe -n -i
查看php的基本信息。
php.exe -m
查看编译的模块

4.2 php 32位编译
cd d:\php-sdk
bin\phpsdk_setvars.bat
cd d:\git\php-src

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat"

buildconf

# 生成编译输出目录
mkdir d:\phpbuild\x86

# configure 不指定--enable-object-out-dir,x86版本会生成在当前目录下的Release_TS,x64版本生成到当前目录的x64\Release_TS目录下
# configure 指定--enable-object-out-dir=d:\phpbuild\x86后,
# configure 如果不指定--enable-debug,nmake 会在d:\phpbuild\x86目录下生成Release_TS目录,所有nmake产生的内容在d:\phpbuild\x86\Release_TS目录下。
# configure 如果指定--enable-debug,nmake 会在d:\phpbuild\x86目录下生成Debug_TS目录,所有nmake产生的内容在d:\phpbuild\x86\Debug_TS目录下。
# --enable-debug 和 --enable-debug-pack 不能同时指定
configure --disable-calendar --enable-object-out-dir=d:\phpbuild\x86 --with-php-build=D:\php-sdk\phpdev\vc14\x86\deps

# debug版本
# configure --enable-debug --disable-calendar --enable-object-out-dir=d:\phpbuild\x86 --with-php-build=D:\php-sdk\phpdev\vc14\x86\deps

# **************************************************
# 生成正式x86 dll版本
# 注意:--enable-calendar=shared 这里修改ext/calendar/jewish.c文件的编码,也可以使用--disable-calendar
# 编译通过,如果要成功生成php_oci8_12c.dll,必须有oracle客户端的配置。php_pdo_oci.dll也需要oracle客户端配置。
# configure --enable-object-out-dir=d:\phpbuild\x86 --with-php-build=D:\php-sdk\phpdev\vc14\x86\deps --enable-cli-win32 --enable-embed --enable-phpdbg --enable-calendar=shared --with-toolset --with-mp --with-extra-includes --with-extra-libs --with-snapshot-template --with-analyzer=shared --with-codegen-arch --with-all-shared --with-bz2=shared --with-curl=shared --with-dba=shared --with-enchant=shared --enable-fileinfo=shared --enable-ftp=shared --with-gettext=shared --with-gmp=shared --with-mhash=shared --with-imap=shared --with-interbase=shared --enable-intl=shared --with-ldap=shared --with-libmbfl=shared --enable-mbstring=shared --enable-mbregex=shared --with-mcrypt=shared --with-oci8=shared --with-oci8-11g=shared --with-oci8-12c=shared --with-odbcver --enable-odbc=shared --with-openssl=shared --with-pgsql=shared --with-pspell=shared --with-snmp=shared --enable-sockets=shared --with-sqlite3=shared --with-config-file-scan-dir=shared --enable-sysvshm=shared --with-tidy=shared --enable-exif=shared --with-mysqli=shared --enable-pdo=shared --with-pdo-dblib=shared --with-pdo-mssql=shared --with-pdo-firebird=shared --with-pdo-mysql=shared --with-pdo-oci=shared --with-pdo-odbc=shared --with-pdo-pgsql=shared --with-pdo-sqlite=shared --with-pdo-sqlite-external=shared --enable-phar-native-ssl --enable-soap=shared --with-xmlrpc=shared --with-xsl=shared --with-gd=shared

# debug 版本 # debug的--enable-intl=shared 会有错误,所以不使用这个配置
# configure --enable-debug --enable-object-out-dir=d:\phpbuild\x86 --with-php-build=D:\php-sdk\phpdev\vc14\x86\deps --enable-cli-win32 --enable-embed --enable-phpdbg --enable-calendar=shared --with-toolset --with-mp --with-extra-includes --with-extra-libs --with-snapshot-template --with-analyzer=shared --with-codegen-arch --with-all-shared --with-bz2=shared --with-curl=shared --with-dba=shared --with-enchant=shared --enable-fileinfo=shared --enable-ftp=shared --with-gettext=shared --with-gmp=shared --with-mhash=shared --with-imap=shared --with-interbase=shared --with-ldap=shared --with-libmbfl=shared --enable-mbstring=shared --enable-mbregex=shared --with-mcrypt=shared --with-oci8=shared --with-oci8-11g=shared --with-oci8-12c=shared --with-odbcver --enable-odbc=shared --with-openssl=shared --with-pgsql=shared --with-pspell=shared --with-snmp=shared --enable-sockets=shared --with-sqlite3=shared --with-config-file-scan-dir=shared --enable-sysvshm=shared --with-tidy=shared --enable-exif=shared --with-mysqli=shared --enable-pdo=shared --with-pdo-dblib=shared --with-pdo-mssql=shared --with-pdo-firebird=shared --with-pdo-mysql=shared --with-pdo-oci=shared --with-pdo-odbc=shared --with-pdo-pgsql=shared --with-pdo-sqlite=shared --with-pdo-sqlite-external=shared --enable-phar-native-ssl --enable-soap=shared --with-xmlrpc=shared --with-xsl=shared --with-gd=shared
# **************************************************

nmake  # 生成d:\git\php-src\Release_TS目录

nmake snap

5 一些在windows 下不能指定的选项:

# windows下编译不能通过的选项:
--enable-pgi --with-pgo --enable-fd-setsize
# --enable-pgi 和 --with-pgo 不能同时指定


6 运行环境注意点
  认真看下http://windows.php.net/download#php-7.1页面左侧介绍。
  windows上运行于不同apache版本,和不同iis版本,对于线程安全和非线程安全要求不同。
  你需要了解非线程安全(zts) 和线程安全(ts)版本的区别。
  你需要了解vs2015编译的版本,在win7等不同系统下运行,需要的vs2015依赖dll。


7 一些默认configure配置项
 默认指定不带的模块
 --without-uncritical-warn-choke
 --without-gd
 --without-libwebp
 --without-iconv
 --without-mysqlnd
 --without-readline
 --without-libxml
 --without-dom
 --without-simplexml
 --without-xml
 --without-wddx

 默认停用的选项
 --disable-zts
 --disable-ipv6
 --disable-security-flags
 --disable-cgi
 --disable-cli
 --disable-phpdbg-webhelper
 --disable-bcmath
 --disable-calendar
 --disable-com-dotnet
 --disable-ctype
 --disable-filter
 --disable-hash
 --disable-json
 --disable-mbregex-backtrack
 --disable-opcache
 --disable-opcache-file
 --disable-session
 --disable-tokenizer
 --disable-zip
 --disable-zlib
 --disable-phar
 --disable-xmlreader
 --disable-xmlwriter
 


0 0