PHP7.0.0在OS X编译安装

前言

PHP7即将在12月3日正式发布,而RC8是已经差不多稳定了的版本,后续的GA版本主要都是在修复bug,所以为了未来开发环境的升级,准备尝试安装一下。

PHP7.0.0将在12月3日正式发布,但是12月2日时github已经发布出PHP-7.0.0.tar.gz源码包,只是官方网站还尚未更新,本文也对错误之处进行修正。
目前PHP7正式版已经移除了古老的mysql扩展和ereg扩展

默认配置

任何软件都要先尝试下默认编译选项,PHP也是一样,特别是PHP本身模块众多。
经过尝试,默认编译情况只会开启以下模块:

[PHP Modules]
Core
ctype
date
dom
fileinfo
filter
hash
iconv
json
libxml
mysqli
mysqlnd
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter

[Zend Modules]

而苹果默认的PHP5.5.29则会开启以下模块

[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gd
hash
iconv
json
ldap
libxml
mbstring
mysql
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
snmp
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib

[Zend Modules]

经过对比,两者差别bcmath,bz2,calendar,curl,dba,ereg,exif,ftp,gd,ldap,mbstring,mysql,mysqli,mysqlnd,openssl,pdo_mysql,readline,shmop,snmp,soap,sockets,sysvmsg,sysvsem,sysvshm,tidy,wddx,xmlrpc,xsl,zip,zlib

差异模块简介

bcmath

  • 对于任意精度的数学,PHP提供了支持用字符串表示的任意大小和精度的数字的二进制计算。

  • 自 PHP 4.0.4,libbcmath 随同 PHP 一起发布。该扩展不需要任何外部的库。

  • 本类函数仅在 PHP 编译时配置了 –enable-bcmath 时可用。

bz2

  • bzip2 函数用于透明地读写 bzip2(.bz2)压缩文件。

  • 本模块使用了 Julian Seward 的 » bzip2 库中的函数。本模块需要 bzip2/libbzip2 版本 >= 1.0.x。

  • PHP 的 Bzip2 支持默认未打开。编译 PHP 时需要 –with-bz2[=DIR] 配置选项来激活 bzip2 支持。

calendar

  • 历法扩展集包括了一系列用于在不同历法间进行转换的函数,它是以Julian Day计数为中介或标准来进行的。Julian Day计数是以公元前的4713年的1月1日为起点的一种计数法。为了在不同历法间进行转换,你首先要转换成Julian Day计数,然后再转换为你所需要的历法。

  • 构建此扩展不需要其他扩展。

  • 要使用本类函数,需要在编译 PHP 时加上 –enable-calendar 。

curl

  • PHP支持的由Daniel Stenberg创建的libcurl库允许你与各种的服务器使用各种类型的协议进行连接和通讯。libcurl目前支持http、https、ftp、gopher、telnet、dict、file和ldap协议。libcurl同时也支持HTTPS认证、HTTP POST、HTTP PUT、 FTP 上传(这个也能通过PHP的FTP扩展完成)、HTTP 基于表单的上传、代理、cookies和用户名+密码的认证。

  • 为了使用PHP的cURL函数,你需要安装» libcurl包。PHP需要使用libcurl 7.0.2-beta 或者更高版本。在PHP 4.2.3 里使用cURL,你需要安装7.9.0或更高版本的libcurl。从PHP 4.3.0开始你需要安装7.9.0或更高版本的libcurl。从PHP 5.0.0开始你需要安装7.10.5或更高版本的libcurl。

  • 要使用PHP的cURL支持你必须在编译PHP时加上–with-curl[=DIR] 选项,DIR为包含lib和include的目录路径。在include目录中必须有一个名为curl,包含了easy.h和curl.h的文件夹。lib文件夹里应该有一个名为libcurl.a的文件。对于PHP 4.3.0你可以配置–with-curlwrappers 使cURL使用URL流。

dba

  • These functions build the foundation for accessing Berkeley DB style databases.

    这些方法是用来访问伯克利DB风格的数据库
  • This is a general abstraction layer for several file-based databases. As such, functionality is limited to a common subset of features supported by modern databases such as » Oracle Berkeley DB.

    这是一个用于多个基于文件的数据库的通用抽象层,因此功能仅局限于相待数据库的公共子集,例如Oracle Berkeley DB
  • By using the –enable-dba=shared configuration option you can build a dynamic loadable module to enable PHP for basic support of dbm-style databases. You also have to add support for at least one of the following handlers by specifying the –with-XXXX configure switch to your PHP configure line.

    通过使用--enable-dba=shared编译选项,你可以编译一个动态链接库让PHP支持dbm-style数据库,你还必须添加至少一种下列处理程序通过制定--with-XXXX编译开关在编译选项中

ereg

  • Regular expressions are used for complex string manipulation. PHP uses the POSIX extended regular expressions as defined by POSIX 1003.2.

    正则表达式用于复杂字符串操作,PHP使用POSIX扩展正则表达式
  • 构建此扩展不需要其他扩展。

  • 要激活 regexp 的支持在配置 PHP 时加上 –with-regex[=TYPE] 。TYPE 可以是 system,apache 或 php 之一。默认使用 php。

exif

  • 通过使用 exif 扩展,你可以操作图像元数据。 例如:你可以使用 exif 相关的函数从文件头读取 数码相机拍摄的 JPEG 和 TIFF 格式的图像文件元数据。

  • 必须使用 –enable-exif 选项编译 PHP。 exif 模块不需要其他额外的库。

  • 使用 –enable-exif 选项 配置 PHP 来启用 exif 支持。

ftp

  • 本扩展中的函数实现了通过 FTP 协议访问文件服务器的客户端。 FTP 协议在 » http://www.faqs.org/rfcs/rfc959 中定义。 本扩展提供了对于 FTP 服务器完整的访问及控制功能。 如果只是简单的从 FTP 服务器读取或向服务器写入一个文件, 请考虑使用 ftp:// 包装器 和 文件系统函数, 会更加的简单。

  • 构建此扩展不需要其他扩展。

  • 要使用这些 FTP 相关函数,在编译的时候请添加 –enable-ftp 选项。

gd

  • PHP 并不仅限于创建 HTML 输出, 它也可以创建和处理包括 GIF, PNG, JPEG, WBMP 以及 XPM 在内的多种格式的图像。 更加方便的是,PHP 可以直接将图像数据流输出到浏览器。 要想在 PHP 中使用图像处理功能,你需要连带 GD 库一起来编译 PHP。 GD 库和 PHP 可能需要其他的库, 这取决于你要处理的图像格式。

  • 你可以使用 PHP 中的图像函数来获取下列格式图像的大小: JPEG, GIF, PNG, SWF, TIFF 和 JPEG2000。

  • 如果联合 exif 扩展 一起使用, 你可以操作存储在 JPEG 和 TIFF 图像文件头部的信息, 这样就就可以获取数码相机所产生的元数据。 exif 相关的函数不需要 GD 库亦可使用。

  • 如果你有 GD 库(可从 » http://www.libgd.org/ 获得), 你就可以创建 和处理图像。

  • 可以处理的图像格式由你所使用的 GD 库版本 以及 GD 库可能需要的其他库决定。 GD gd-1.6 之前的版本支持 GIF 格式, 但是不支持 PNG 格式。 gd-1.6 以上、gd-2.0.28 以下的版本支持 PNG, 但是不支持 GIF 格式。 在 gd-2.0.28 中,又重新启用了对于 GIF 格式的支持。

  • 要激活 GD 支持,配置 PHP 时加上 –with-gd[=DIR] ,DIR 是 GD 的基本安装目录。要使用推荐的绑定的 GD 库版本(首次绑定于 PHP 4.3.0),使用 –with-gd 。要编译 GD 库,需要libpng 和 libjpeg。

ldap

  • LDAP is the Lightweight Directory Access Protocol, and is a protocol used to access “Directory Servers”. The Directory is a special kind of database that holds information in a tree structure.

    LDAP是一个轻量级目录存取协议,被用来和“目录服务器”交互,目录是一个特别类型的数据库,里面以树的结构存储信息
  • You will need to get and compile LDAP client libraries from either » OpenLDAP or » Bind9.net in order to compile PHP with LDAP support. For PHP 5.6 or newer you will need OpenLDAP 2.4 or newer.

    你将需要得到和编译LDAP客户端库从OpenLDAP或者Bind9.net为了PHP获得LDAP支持,PHP5.6或者更新版本你需要OpenLDAP2.4或者更新
  • LDAP support in PHP is not enabled by default. You will need to use the –with-ldap[=DIR] configuration option when compiling PHP to enable LDAP support. DIR is the LDAP base install directory. To enable SASL support, be sure –with-ldap-sasl[=DIR] is used, and that sasl.h exists on the system.

    LDAP扩展默认不启用。你将会需要去使用--with-ldap[=DIR]编译选项当编译PHP并启用LDAP支持,DIR是LDAP安装目录。为了去启用SASL支持,确保--with-ldap-sasl[=DIR]被使用,并且这个sasl.h在系统中存在

mbstring

  • 开发多字节字符编码方案是为了在基于字节的常规编码系统中表达超过 256 个字符。mbstring 提供了针对多字节字符串的函数,能够帮你处理 PHP 中的多字节编码。 除此以外,mbstring 还能在可能的字符编码之间相互进行编码转换。 为了方便起见,mbstring 设计成了处理基于 Unicode 的编码,类似 UTF-8、UCS-2 及诸多单字节的编码。

  • 构建此扩展不需要其他扩展。

  • mbstring 不是一个默认扩展。这意味着它默认没有被激活。 你必须在 configure 选项中显式激活该模块。

    • –enable-mbstring :激活 mbstring 函数。 要使用 mbstring 函数必须启用这个选项。

    • –enable-mbstr-enc-trans :使用 mbstring 转换引擎来转换 HTTP 输入字符的编码。 如果启用了这个功能,HTTP 输入字符编码可能将自动转换成 mbstring.internal_encoding。

    • –disable-mbregex :禁用正则表达式函数中多字节字符的支持。

mysql

  • 在写新的代码时,不推荐使用本扩展。您应该使用 mysqli 或者 PDO_MySQL 扩展代替。

  • 为了使这些函数能够使用,你必须编译加入 PHP 对 MySQL 的支持。

  • 编译时,只要使用 –with-mysql[=DIR] 配置选项即可,其中可选的 [DIR] 指向 MySQL 的安装目录。虽然本 MySQL 扩展库兼容 MySQL 4.1.0 及其以后版本,但是它不支持这些版本提供的额外功能。要使用这些功能,请使用 MySQLi 扩展库。如果要同时安装 mysql 扩展库和 mysqli 扩展库,必须使用同一个客户端库以避免任何冲突。

mysqli

  • mysqli扩展允许我们访问MySQL 4.1及以上版本提供的功能。

  • 为了使这些函数可用,你必须以支持mysqli扩展的方式编译PHP。

  • mysqli扩展在PHP5.0.0中被引入。Mysql Native驱动在PHP5.3.0版本中被引入。

mysqlnd

  • MySQL Native Driver is a replacement for the MySQL Client Library (libmysqlclient).

    MySQL原生驱动是一个MySQL客户端库的替代品
  • 安装

    ./configure --with-mysql=mysqlnd \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \

openssl

  • This module uses the functions of » OpenSSL for generation and verification of signatures and for sealing (encrypting) and opening (decrypting) data. OpenSSL offers many features that this module currently doesn’t support. Some of these may be added in the future.

    该模块采用OpenSSL签名生成和验证功能和密封(加密)和开放(解密)的数据。OpenSSL提供了许多功能,该模块目前不支持。这些可能在未来增加。
  • In order to use the OpenSSL functions you need to install the » OpenSSL package. PHP between versions 4.0.5 and 4.3.1 will work with OpenSSL >= 0.9.5. Other versions (PHP <=4.0.4 and >= 4.3.2) require OpenSSL >= 0.9.6.

    为了使用OpenSSL方法,你需要去安装OpenSSL包。在4.0。5和4.3.1的PHP需要OpenSSL>=0.9.5,其他版本需要OpenSSL>=0.9.6
  • To use PHP’s OpenSSL support you must also compile PHP –with-openssl[=DIR] .

    为了使用PHP的OpenSSL支持,你必须编译PHP --with-openssl[=DIR]

pdo_mysql

  • PDO_MYSQL is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to MySQL 3.x, 4.x and 5.x databases.

    PDO_MYSQL是实现了PHP数据对象接口的一个驱动,用于启用PHP和MySQL数据库之间的通信
  • 构建此扩展不需要其他扩展。

  • When compiling, use –with-pdo-mysql[=DIR] to install the PDO MySQL extension, where the optional [=DIR] is the MySQL base library. As of PHP 5.4, mysqlnd is the default library.

    当编译的时候使用--with-pdo-mysql[=DIR]去安装PDO MySQL扩展,mysqlnd默认是客户端库

    Optionally, the –with-mysql-sock[=DIR] sets to location to the MySQL unix socket pointer for all MySQL extensions, including PDO_MYSQL. If unspecified, the default locations are searched.

    可选的是,--with-mysql-sock[=DIR]设置mysql的unix socket文件位置

    Optionally, the –with-zlib-dir[=DIR] is used to set the path to the libz install prefix.

    可选的是,--with-zlib-dir[=DIR]被用来去设置libz安装目录

readline

  • readline 扩展函数实现了访问 GNU Readline 库的接口. 这些函数提供了可编辑的命令行. 一个例子是在 Bash 中允许你使用箭头按键来插入字符或者翻看历史命令. 因为这个库的交互特性,这个功能在你写的 Web 程序中没多大用处, 但是当你写的脚本被用在命令行中时非常有用.

  • 如果要使用 readline 函数,你必须安装 libreadline. 你也能使用非 GPL 的 libedit 库来替代 readline 库

  • 要使用这些函数,你必须在编译 PHP 的 CGI 或者 CLI 版本时启用 readline 支持. 你需要在编译配置 PHP 时使用 –with-readline[=DIR] 选项. 如果你想使用 libedit 来代替 readline , 配置 PHP 时使用 –with-libedit[=DIR] 选项

shmop

  • Shmop is an easy to use set of functions that allows PHP to read, write, create and delete Unix shared memory segments.

    shmop是一个简单的方式去使用一系列方法让php读写创建删除Unix共享内存区块
  • 构建此扩展不需要其他扩展。

  • To use shmop you will need to compile PHP with the –enable-shmop parameter in your configure line.

    为了使用shmop你需要编译PHP --enable-shmop参数

snmp

  • The SNMP extension provides a very simple and easily usable toolset for managing remote devices via the Simple Network Management Protocol.

    SNMP扩展提供了简单容易可用的工具集去管理远程设备通过简单网络管理协议
  • In order to use the SNMP functions requires installation of the » Net-SNMP package. SNMPv3 functions available only when » OpenSSL package is installed too.

    为了使用SNMP方法,要求安装net-snmp包,snmpv3方法只能当openssl包安装的时候可用
  • 重要提示:为了使用 UCD SNMP 包,需要在编译之前将 NO_ZEROLENGTH_COMMUNITY 定义为 1。 在配置 UCD SNMP 之后,编辑 config.h 或 acconfig.h,查找 NO_ZEROLENGTH_COMMUNITY,将 #define 所在行的注释去掉。修改后应该类似这样:#define NO_ZEROLENGTH_COMMUNITY 1然后使用 –with-snmp[=DIR] 选项编译 PHP。如果在组合 SNMP 命令时看到奇怪的字段错误,那就是因为没有遵从上述说明。如果不想重新编译 UCD SNMP,可以使用 –enable-ucd-snmp-hack 开关编译 PHP 以绕开上述错误。

soap

  • The SOAP extension can be used to write SOAP Servers and Clients.

    SOAP扩展可以被用来写soap服务器和客户端
  • 此扩展需要 libxml PHP 扩展。这表示需要使用 –enable-libxml ,尽管这将隐式完成因为 libxml 是缺省开启的。

  • To enable SOAP support, configure PHP with –enable-soap .

sockets

  • Socket扩展是基于流行的BSD sockets,实现了和socket通讯功能的底层接口,它可以和客户端一样当做一个socket服务器。

  • 构建此扩展不需要其他扩展。

  • 这里描述的socket函数只是PHP扩展的一部分,编译PHP时必须在配置中添加–enable-sockets 配置项来启用。

sysvmsg sysvsem sysvshm

  • This module provides wrappers for the System V IPC family of functions. It includes semaphores, shared memory and inter-process messaging (IPC).

    这个模块提供了System V IPC函数的包装器,包括了semaphores,shared memory和inter-process messaging
  • 构建此扩展不需要其他扩展。

  • Support for this functions are not enabled by default. To enable System V semaphore support compile PHP with the option –enable-sysvsem . To enable the System V shared memory support compile PHP with the option –enable-sysvshm . To enable the System V messages support compile PHP with the option –enable-sysvmsg .

    默认不支持这些方法,为了启用此魔窟啊,在编译PHP的时候需要加入--enable-sysvsem --enable-sysshm --enable-sysvmsg编译开关

tidy

  • Tidy is a binding for the Tidy HTML clean and repair utility which allows you to not only clean and otherwise manipulate HTML documents, but also traverse the document tree.

    Tidy是一种保持html清理和修复工具,不仅允许你清理而且还能操纵html文档,也能遍历文档树
  • To use Tidy, you will need libtidy installed

  • This extension is bundled with PHP 5 and greater, and is installed using the –with-tidy configure option.

wddx

  • WEB分布式数据交换是为WEB发展而设计的一项基于XML 的技术。WDDX用于在WEB应用程序的之间不同的部分传送结构化的数据,这一应用程序可以被分布到各种各样的WEB服务器。它允许一个简单地机制来传递数据并且甚至可以在不同的平台之间交换数据。

  • 此扩展需要 libxml PHP 扩展。这表示需要使用 –enable-libxml ,尽管这将隐式完成因为 libxml 是缺省开启的。

  • After installing the required expat library, compile PHP with –enable-wddx , and use –with-libexpat-dir for expat.

xmlrpc

  • xmlrpc是使用http协议做为传输协议的rpc机制,使用xml文本的方式传输命令和数据。

  • 此扩展需要 libxml PHP 扩展。这表示需要使用 –enable-libxml ,尽管这将隐式完成因为 libxml 是缺省开启的。

  • 默认情况下在 PHP 中是不能使用 XML-RPC 支持的。你需要使用 –with-xmlrpc[=DIR] 配置选项编译 PHP 才能够使用 XML-RPC 支持。从 PHP 4.1.0 开始附带了此扩展。

xsl

  • The XSL extension implements the XSL standard

  • 此扩展需要 libxml PHP 扩展。这表示需要使用 –enable-libxml ,尽管这将隐式完成因为 libxml 是缺省开启的。

  • PHP 5 includes the XSL extension by default and can be enabled by adding the argument –with-xsl[=DIR] to your configure line (DIR being the libxslt installation directory).

zip

  • 此扩展可以让你透明地读写ZIP压缩文档以及它们里面的文件。

  • 此扩展用到 Jean-loup Gailly 和 Mark Adle 的 » zlib 里的函数。

  • 为了使用这些函数,必须在编译 PH P时用 –enable-zip[=DIR] 配置选项来提供 zip 支持,其中 [DIR]是 » ZZIPlib 库安装路径。

zlib

  • This module enables you to transparently read and write gzip (.gz) compressed files, through versions of most of the filesystem functions which work with gzip-compressed files (and uncompressed files, too, but not with sockets).

    这个模块允许你转换读写gzip压缩文件,在大多数文件系统函数下与gzip压缩文件工作,但是不能用于sockets
  • This module uses the functions of » zlib by Jean-loup Gailly and Mark Adler. You have to use a zlib version >= 1.0.9 with this module.

  • Zlib support in PHP is not enabled by default. You will need to configure PHP –with-zlib[=DIR]

编译安装

首先先进行PHP的默认安装

./configure --enable-fpm --with-fpm-user=_www --with-fpm-group=_www --with-config-file-path=/usr/local/etc --with-config-file-scan-dir=/usr/local/etc/php.d --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=/tmp/mysql.sock

然后对上面所有差异的模块扩展进行编译安装

cd ext/XXX
phpize
./configure --enable/with-XXX
make
sudo make install

试验到最后,发现除了openssl和gd库,其他都能通过OS X自带的库文件完美安装,openssl是在/usr/include缺少头文件,gd库是没有自带的lib,如果有其他朋友试验出静态库编译的方法,欢迎指正。

OpenSSL库的安装方法

经过一番研究,发现了一种安装openssl静态库来实现openssl.so扩展的方式,首先下载openssl的源代码,版本随意,只要能符合php的要求,然后解压出两个文件夹,一个命名为openssl-i386,一个为openssl-x64,然后进入这两个文件夹,分别使用

./Configure darwin-i386-cc
./Configure darwin64-x86_64-cc

然后分别make编译,编译完成后进入上级目录使用

lipo -create openssl-i386/libcrypto.a openssl-x64/libcrypto.a -output libcrypto.a
lipo -create openssl-i386/libssl.a openssl-x64/libssl.a -output libssl.a

这样就整合了i386和x86_64的静态库,然后包括头文件和静态库,统统复制到xcode sdk目录或者随便什么符合unix安装结构的目录

cd php/ext/openssl
mv config0.m4 config.m4
phpize
./configure --with-openssl=/path/to
make
sudo make install

GD库的安装方法

试验了一下,发现苹果自带的php内gd库只有libpng和libjpeg两个库,那么解决方法就出来了,只需要将libpng和libjpeg库都编译成静态库,就能够完美实现gd库的编译了
首先我们下载libjpeg和libpng,下载完后解压

cd XXX
./configure --prefix=/path/to --enable-static
make
make install

注意!由于是编译安装到自定义目录,所以每个库的
./configure –prefix=/path/to是必须的。
最后请注意将所有的dylib等动态库文件全部删除或者重命名,只留下xxx.a静态库文件,否则编译的时候php会优先使用动态库文件,那样就无法删除/path/to文件夹了

然后进入PHP目录

cd ext/gd
phpize
./configure --with-gd --with-png-dir=/path/to --with-jpeg-dir=/path/to --enable-gd-native-ttf
make
sudo make install

如有错误,欢迎指正

实现了在centos6上编译安装tengine+php7+mariadb,需要如下依赖

openssl-devel pcre-devel jemalloc-devel libaio-devel
libxml2-devel
bzip2-devel
libcurl-devel
openldap-devel
readline-devel
libedit-devel
net-snmp-devel
libtidy-devel
libxslt-devel
libpng-devel libjpeg-devel

顺带着记录下开发环境的编译参数

./configure --enable-fpm --with-fpm-user=www_data --with-fpm-group=www_data --with-config-file-path=/usr/local/etc --with-config-file-scan-dir=/usr/local/etc/php.d --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=/tmp/mysql.sock --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --with-gd --with-jpeg-dir --with-png-dir --enable-gd-native-ttf --enable-mbstring --with-openssl --with-readline --with-libedit --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-wddx --with-xmlrpc --enable-zip --with-zlib
    原文作者:山河永寂
    原文地址: https://segmentfault.com/a/1190000004065931
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞