源码编译安装
获取源码
- 从官网的下载页面下载对应的源码。
- 从GitHub上下载PHP的源码,地址为 https://github.com/php/php-src
# GitHub上的源码可通过 clone 选择一个要安装的版本并下载到本地计算机
[root@instance-36dg06w0 php-7.3.5]# git clone -b PHP-7.3.5 https://github.com/php/php-src.git
获取源码后,将源码复制到 /usr/local/src
目录下
[root@instance-36dg06w0 php-7.3.5]# cp -r /root/source_code/php-src/ /usr/local/src/php-7.3.5
开始安装
生成 configure
文件
git 克隆下来的文件没有 configure
文件,所以通过 buildconf
文件生成该文件,如果已经存在 configure
文件则不需要生成。具体过程如下:
[root@instance-36dg06w0 php-7.3.5]# ./buildconf
You should not run buildconf in a release package.
use buildconf --force to override this check.
指令执行失败,根据提示给指令添加选项
[root@instance-36dg06w0 php-7.3.5]# ./buildconf --force
Forcing buildconf
Removing configure caches
buildconf: checking installation...
buildconf: autoconf not found.
You need autoconf version 2.68 or newer installed
to build PHP from Git.
make: *** [buildmk.stamp] Error 1
再次执行失败,根据提示,知道系统缺少 autoconf 应用程序,yum安装
[root@instance-36dg06w0 php-7.3.5]# yum install autoconf
再次执行 buildconf,成功生成 configure
[root@instance-36dg06w0 php-7.3.5]# ./buildconf --force
Forcing buildconf
Removing configure caches
buildconf: checking installation...
buildconf: autoconf version 2.69 (ok)
rebuilding aclocal.m4
rebuilding configure
rebuilding main/php_config.h.in
[root@instance-36dg06w0 php-7.3.5]# ll configure
-rwxr-xr-x 1 root root 2650999 May 27 15:40 configure
查看 ./configure
指令相关选项
通过 ./configure -h
可以查看 ./configure
所拥有的安装选项,一下是常用的一些选项及含义:
选项 | 用法 | 含义 |
---|---|---|
–prefix | –prefix=PREFIX | 把与体系结构无关的文件(architecture-independent)安装到 PREFIX 目录下。默认情况下, PREFIX 的值为 /usr/local ,可执行文件放在 /usr/local/bin 目录,库文件放在 /usr/local/lib 目录,配置文件放在 /usr/local/etc 目录,其他资源文件放在 /usr/local/share 目录,设置了 prefix 后,会把这些文件都放在一个目录下,方便删除卸载应用 |
–build | –build=BUILD | 执行代码编译的主机,正常的话就是你的主机系统。这个参数一般由 config.guess 来猜就可以。当然自己指定也可以。 |
–host | –host=HOST | 编译出来的二进制程序所执行的主机,因为绝大多数是如果本机编译,本机执行。所以这个值就等于 BUILD 。只有交叉编译的时候(也就是本机编译,其他系统机器执行)才会 build 和 host 不同。 用 host 指定运行主机。 |
–target | –target=TARGET | 这个选项只有在建立交叉编译环境的时候用到,正常编译和交叉编译都不会用到。他用build主机上的编译器,编译一个新的编译器(binutils, gcc,gdb等),这个新的编译器将来编译出来的其他程序将运行在target指定的系统上。 |
–with-apxs2 | –with-apxs2=FILE | 编译共享的 Apache 2.0 模块。FILE 是可选的 Apache apxs 工具的路径,默认指向 apxs。 |
–disable-cli | –disable-cli | 默认情况下命令行模式是被开启的,如果要关闭该模式,可以使用该选项 |
–enable-embed | –enable-embed=TYPE | 允许 SAPI 库的构建,开启该设置后,我们可以在其他的 C/C++ 应用中调用 PHP 提供的 API , TYPE 的值为 shared 或 static ,默认为 shared |
–enable-fpm | –enable-fpm | 允许 fpm SAPI 可执行文件的构建,即开启进程管理器(FastCGI Process Manager) php-fpm |
–with-fpm-user | –with-fpm-user=USER | 设置运行 php-fpm 的用户,默认 nobody |
–with-fpm-group | –with-fpm-group=GRP | 设置运行 php-fpm 的用户组,默认 nobody |
–with-fpm-systemd | –with-fpm-systemd | 激活系统集成功能,开启后 fpm 可以上报给系统一些信息 |
–with-fpm-acl | –with-fpm-acl | 使用 POSIX 访问控制列表 |
–with-litespeed | –with-litespeed | 将 PHP 作为 litespeed WEB 服务器的一个模块 |
–enable-phpdbg | –enable-phpdbg | 创建 phpdbg ,一个php调试工具 |
–enable-phpdbg-webhelper | –enable-phpdbg-webhelper | 创建 phpdbg web SPAI 支持 |
–enable-phpdbg-debug | –enable-phpdbg-debug | 调试模式下构建 phpdbg |
–enable-phpdbg-readline | –enable-phpdbg-readline | 是 phpdbg 支持 readline (通过依靠 ext/readline ) |
–disable-cgi | –disable-cgi | 禁止编译 CGI 版本的 PHP ,PHP5.3.0 起,这个选项会启用 FastCGI ,而在以前,必须使用 --enable-fastcgi 启用FastCGI。 |
–with-valgrind | –with-valgrind=DIR | 添加 valgrind 支持 |
–enable-gcov | –enable-gcov | 启用 GCOV 代码覆盖(需要 LTP ),仅限开发者模式 |
–enable-debug | –enable-debug | 编译时加入调试符号 |
–with-layout | –with-layout=TYPE | 设置被安装文件的布局。 TYPE 是 PHP (默认)或 GNU |
–with-config-file-path | –with-config-file-path=PATH | 设置 php.ini 的搜索路径。默认为 PREFIX/lib |
–with-config-file-scan-dir | –with-config-file-scan-dir=PATH | 设置被扫描配置文件的路径 |
–enable-sigchild | –enable-sigchild | 使用 PHP 自带的 SIGCHLD 处理器 |
–enable-libgcc | –enable-libgcc | 针对 libgcc 使用显示链接 |
–disable-short-tags | –disable-short-tags | 默认禁用短形式的开始标签 <? |
–enable-dmalloc | –enable-dmalloc | 开启 dmalloc |
–disable-ipv6 | –disable-ipv6 | 禁止 IPV6 支持 |
–enable-dtrace | –enable-dtrace | 开启 dtrace |
–enable-fd-setsize | –enable-fd-setsize | 允许设置文件描述符集 fd_set 的大小 |
–with-EXTENSION | –with-EXTENSION=shared[,PATH] | 将扩展编译成 shared 模式,并非所有扩展都可以设置成 shared |
–disable-all | –disable-all | 禁用默认启用的所有扩展 |
–disable-libxml | –disable-libxml | 禁止 LIBXML 支持 |
–with-libxml-dir | –with-libxml-dir=DIR | LIBXML: libxml2 安装目录 |
–with-openssl | –with-openssl=DIR | 添加 OpenSSL 支持(要求 OpenSSL 版本 >= 1.0.1) |
–with-kerberos | –with-kerberos=DIR | OPENSSL:添加 Kerberos 支持 |
–with-system-ciphers | –with-system-ciphers | OPENSSL:使用系统默认密码列表代替硬编码值 |
–with-pcre-regex | –with-pcre-regex=DIR | 添加兼容 perl 的正则表达式支持, DIR 是 PCRE 安装的前缀 BUNDLED |
–with-pcre-jit | –with-pcre-jit | 开启 PCRE JIT (即时编译) 功能(BUNDLED only) |
–with-pcre-valgrind | –with-pcre-valgrind=DIR | 开启 PCRE 的 valgrind 支持,仅限开发者模式 |
-without-sqlite3 | -without-sqlite3=DIR | 不添加 SQLite3 支持, DIR 是 SQLite3 安装目录的前缀 |
–with-zlib | –with-zlib=DIR | 添加 ZLIB 支持(zlib 版本 >= 1.2.0.4) |
–with-zlib-dir | –with-zlib-dir=<DIR> | 定义 zlib 本地安装目录 |
–enable-bcmath | –enable-bcmath | 启用 bcmath (Binary Calculator),用于浮点型数字的精确计算 |
–with-bz2 | –with-bz2=DIR | 添加 BZip2 支持 |
–enable-calendar | –enable-calendar | 开启 Calendar (历法扩展集)支持,可以用于日历转换 |
–disable-ctype | –disable-ctype | 禁用 ctype 函数 |
–with-curl | –with-curl=DIR | 添加 cURL 支持 |
–enable-dba | –enable-dba | 构建捆绑模块的 DBA ,如果要将扩展设置为共享,使用 --enable-dba=shared |
–with-qdbm | –with-qdbm=DIR | DBA: QDBM 支持 |
–with-gdbm | –with-gdbm=DIR | DBA: GDBM 支持 |
–with-ndbm | –with-ndbm=DIR | DBA: NDBM 支持 |
–with-db4 | –with-db4=DIR | DBA: Oracle Berkeley DB 4.x 或 5.x 支持 |
–with-db3 | –with-db3=DIR | DBA: Oracle Berkeley DB 3.x 支持 |