源码编译安装
获取源码
- 从官网的下载页面下载对应的源码。
- 从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 支持 |
–with-db2 | –with-db2=DIR | DBA: Oracle Berkeley DB 2.x 支持 |
–with-db1 | –with-db1=DIR | DBA: Oracle Berkeley DB 1.x 支持 |
–with-dbm | –with-dbm=DIR | DBA: DBM 支持 |
–with-tcadb | –with-tcadb=DIR | DBA: Tokyo Cabinet 数据库支持 |
–with-lmdb | –with-lmdb=DIR | DBA: Lightning memory-mapped 数据库支持 |
–without-cdb | –without-cdb=DIR | DBA: CDB 支持(bundled) |
–disable-inifile | –disable-inifile | DBA: INI 支持(bundled) |
–disable-flatfile | –disable-flatfile | DBA: FlatFile 支持(bundled) |
–disable-dom | –disable-dom | 取消 DOM 支持 |
–with-libxml-dir | –with-libxml-dir=DIR | DOM: libxml2 安装前缀 |
–with-enchant | –with-enchant=DIR | enchant 扩展支持,GNU Aspell 版本大于等于 1.1.3 |
–enable-exif | –enable-exif | EXIF (metadata from images) 支持 |
–disable-fileinfo | –disable-fileinfo | 取消 fileinfo 支持 |
–disable-filter | –disable-filter | 取消输入过滤 filter 支持 |
–with-pcre-dir | –with-pcre-dir | FILTER: pcre 安装前缀 |
–enable-ftp | –enable-ftp | FTP 支持 |
–with-openssl-dir | –with-openssl-dir=DIR | FTP: openssl 安装前缀 |
–with-gd | –with-gd=DIR | 包含 GD 支持, DIR 是 GD库 的基础安装目录 BUNDLED |
–with-webp-dir | –with-webp-dir=DIR | GD: 设置 libwebp 安装路径的前缀 |
–with-jpeg-dir | –with-jpeg-dir=DIR | GD: 设置 libjpeg 安装路径的前缀 |
–with-png-dir | –with-png-dir=DIR | GD: 设置 libpng 安装路径的前缀 |
–with-zlib-dir | –with-zlib-dir=DIR | GD: 设置 libz 安装路径的前缀 |
–with-xpm-dir | –with-xpm-dir=DIR | GD: 设置 libXpm 安装路径的前缀 |
–with-freetype-dir | –with-freetype-dir=DIR | GD: 设置 FreeType 2 安装路径的前缀 |
–enable-gd-jis-conv | –enable-gd-jis-conv | GD: JIS-mapped Japanese font 支持 |
–with-gettext | –with-gettext=DIR | GNU gettext 支持 |
–with-gmp | –with-gmp=DIR | GNU MP 支持 |
–with-mhash | –with-mhash=DIR | mhash 支持 |
–disable-hash | –disable-hash | 取消 hash 支持 |
–without-iconv | –without-iconv=DIR | 排除 iconv 支持 |
–with-imap | –with-imap=DIR | IMAP 支持, DIR 为 c-client 安装前缀 |
–with-kerberos | –with-kerberos=DIR | IMAP: Kerberos 支持, DIR 为 Kerberos 安装前缀 |
–with-imap-ssl | –with-imap-ssl=DIR | IMAP: SSL 支持, DIR 为 OpenSSL 安装前缀 |
–with-interbase | –with-interbase=DIR | Firebird 支持, DIR 为 Firebird 的基础安装目录为 /opt/firebird |
–enable-intl | –enable-intl | internationalization 支持 |
–with-icu-dir | –with-icu-dir=DIR | 指定 ICU libraries 和 headers 的查找目录 |
–disable-json | –disable-json | 取消 json (JavaScript Object Serialization) 支持 |
–with-ldap | –with-ldap=DIR | LDAP 支持 |
–with-ldap-sasl | –with-ldap-sasl=DIR | LDAP: Cyrus SASL 支持 |
–enable-mbstring | –enable-mbstring | MBSTRING (multibyte string) 支持 |
–disable-mbregex | –disable-mbregex | MBSTRING: 取消 multibyte regex 支持 |
–disable-mbregex-backtrack | –disable-mbregex-backtrack | MBSTRING: 取消 multibyte regex backtrack 检测 |
–with-onig | –with-onig=DIR | MBSTRING: 使用外部 oniguruma , DIR 是 oniguruma 的安装前缀,如果 DIR 没有设置,则使用默认被绑定(bundled)的 oniguruma |
–with-mysqli | –with-mysqli=FILE | MySQLi 支持, FILE 是 mysql_config 的路径,如果没有值或者 mysqlnd 就是 FILE ,则使用 MySQL 本地驱动 |
–enable-embedded-mysqli | –enable-embedded-mysqli | MYSQLi: embedded 支持 (注:不适用于 MySQL 本地驱动) |
–with-mysql-sock | –with-mysql-sock=SOCKPATH | MySQLi/PDO_MYSQL: MySQL unix socket pointer 的位置,如果未指定,则搜索默认位置 |
–with-oci8 | –with-oci8=DIR | Oracle Database OCI8 支持, DIR 默认为 $ORACLE_HOME 。使用 --with-oci8=instantclient,/path/to/instant/client/lib 来安装 Oracle Instant Client |
–with-odbcver | –with-odbcver=HEX | 强迫支持 ODBC 的过去版本, hex number 是必须的,默认为 0x0350 。使用特殊值 0 可以在阻止定义明确的 ODBCVER |
–with-adabas | –with-adabas=DIR | Adabas D 支持, /usr/local |
–with-sapdb | –with-sapdb=DIR | SAP DB 支持, /usr/local |
–with-solid | –with-solid=DIR | Solid 支持, /usr/local/solid |
–with-ibm-db2 | –with-ibm-db2=DIR | IBM DB2 支持, /home/db2inst1/sqllib |
–with-empress | –with-empress=DIR | Empress 支持, \$EMPRESSPATH ,(Empress 版本大于等于 8.60 ) |
–with-empress-bcs | –with-empress-bcs=DIR | Empress Local Access 支持,\$EMPRESSPATH ,(Empress 版本大于等于 8.60 ) |
–with-custom-odbc | –with-custom-odbc=DIR | 支持用户自定义的 ODBC , DIR 是 ODBC 安装的基础目录 /usr/local ,确保定义了 CUSTOM_ODBC_LIBS 并且在包含的目录中含有一些 odbc.h 文件 |
–with-iodbc | –with-iodbc=DIR | iODBC 支持, usr/local |
–with-esoob | –with-esoob=DIR | Easysoft OOB 支持, /usr/local/easysoft/oob/client |
–with-unixODBC | –with-unixODBC=DIR | unixODBC 支持, usr/local |
–with-dbmaker | –with-dbmaker=DIR | DBMaker 支持 |
–disable-opcache | –disable-opcache | 取消 Zend OPcache 支持 |
–disable-opcache-file | –disable-opcache-file | 禁用基于文件的缓存 |
–disable-huge-code-pages | –disable-huge-code-pages | 禁止将 PHP 代码页面拷贝到 HUGE PAGES |
–enable-pcntl | –enable-pcntl | pcntl 支持(仅限于 CLI 或 CGI ) |
–disable-pdo | –disable-pdo | 取消 PDO (PHP Data Objects) 支持 |
–with-pdo-dblib | –with-pdo-dblib=DIR | PDO: DBLIB-DB 支持, DIR 是 FreeTDS 的主目录 |
–with-pdo-firebird | –with-pdo-firebird=DIR | PDO: Firebird 支持, DIR 是 FreeTDS 安装的基础目录 /opt/firebird |
–with-pdo-mysql | –with-pdo-mysql=DIR | PDO: MySQL 支持, DIR 是 MySQL 的基础目录,如果没有值或者 mysqlnd 作为 DIR ,将使用 MySQL 本地驱动 |
–with-zlib-dir | –with-zlib-dir=DIR | PDO_MySQL: 设置 libz 的安装前缀 |
–with-pdo-oci | –with-pdo-oci=DIR | PDO: Oracle OCI 支持, DIR 默认为 $ORACLE_HOME , 使用 --with-pdo-oci=instantclient,/path/to/instant/client/lib 来安装 Oracle Instant Client |
–with-pdo-odbc | –with-pdo-odbc=flavour,dir | PDO: flavour ODBC 驱动支持,包含的目录和库目录在 dir 下。 flavour 可以是以下的其中之一:ibm-db2 , iODBC , unixODBC , generic 如果 ,dir 部分被省略,你选择的 flavour 将会别使用,比如:--with-pdo-odbc=unixODBC 将会在 /usr/local 下检查 unixODBC 。你可以尝试通过通用的 flavour 来使用一个相反的不被支持的驱动,语法为:--with-pdo-odbc=generic,dir,libname,ldflags,cflags 当被创建为 shared 时,扩展文件名总会是 pdo_odbc.so |
–with-pdo-pgsql | –with-pdo-pgsql=DIR | PDO: PostgreSQL 支持,DIR 为 PostgreSQL 的基础安装目录或 pg_config 的路径 |
–without-pdo-sqlite | –without-pdo-sqlite=DIR | PDO: sqlite 3 支持, DIR 为被绑定的 sqlite 基础安装目录 |
–with-pgsql | –with-pgsql=DIR | PostgreSQL 支持,DIR 为 PostgreSQL 的基础安装目录或 pg_config 的路径 |
–disable-phar | –disable-phar | 取消 phar 支持 |
–disable-posix | –disable-posix | 禁用 POSIX-like 函数 |
–with-pspell | –with-pspell=DIR | PSPELL 支持。GNU Aspell 版本大于等于 0.50.0 |
–with-libedit | –with-libedit=DIR | libedit readline 替换,仅限于 CLI /CGI |
–with-readline | –with-readline=DIR | readline 支持,仅限于 CLI /CGI |
–with-recode | –with-recode=DIR | recode 支持 |
–disable-session | –disable-session | 禁用 session |
–with-mm | –with-mm=DIR | SESSION: 包含用于 session 存储的 mm 支持 |
–enable-shmop | –enable-shmop | shmop 支持 |
–disable-simplexml | –disable-simplexml | 禁用 SimpleXML |
–with-libxml-dir | –with-libxml-dir=DIR | SimpleXML: libxml2 安装前缀 |
–with-snmp | –with-snmp=DIR | SNMP 支持 |
–with-openssl-dir | –with-openssl-dir=DIR | SNMP: openssl 安装前缀 |
–enable-soap | –enable-soap | 启用 SOAP |
–with-libxml-dir | –with-libxml-dir=DIR | SOAP: libxml2 安装前缀 |
–enable-sockets | –enable-sockets | 开启 sockets |
–with-sodium | –with-sodium=DIR | 开启 sodium |
–with-password-argon2 | –with-password-argon2=DIR | 在 password_* 中开启 Argon2 支持, DIR 是 Argon2 共享库路径 |
–enable-sysvmsg | –enable-sysvmsg | 开启 sysvmsg |
–enable-sysvsem | –enable-sysvsem | 开启 System V semaphore |
–enable-sysvshm | –enable-sysvshm | 开启 System V shared memory |
–with-tidy | –with-tidy=DIR | 开启 TIDY |
–disable-tokenizer | –disable-tokenizer | 禁用 tokenizer |
–enable-wddx | –enable-wddx | 开启 WDDX |
–with-libxml-dir | –with-libxml-dir=DIR | WDDX: libxml2 安装前缀 |
–with-libexpat-dir | –with-libexpat-dir=DIR | WDDX: XMLRPC-EPI 的 libexpat 目录(被弃用) |
–disable-xml | –disable-xml | 禁用 XML |
–with-libxml-dir | –with-libxml-dir=DIR | XML: libxml2 安装前缀 |
–with-libexpat-dir | –with-libexpat-dir=DIR | XML: libexpat 安装前缀(被弃用) |
–disable-xmlreader | –disable-xmlreader | 禁用 XMLReader |
–with-libxml-dir | –with-libxml-dir=DIR | XMLReader: libxml2 安装前缀 |
–with-xmlrpc | –with-xmlrpc=DIR | 开启 XMLRPC-EPI |
–with-libxml-dir | –with-libxml-dir=DIR | XMLRPC-EPI: libxml2 安装前缀 |
–with-libexpat-dir | –with-libexpat-dir=DIR | XMLRPC-EPI: XMLRPC-EPI 的 libexpat 目录(被弃用) |
–with-iconv-dir | –with-iconv-dir=DIR | XMLRPC-EPI 的 iconv 目录 |
–disable-xmlwriter | –disable-xmlwriter | 禁用 XMLWriter |
–with-libxml-dir | –with-libxml-dir=DIR | XMLWriter: libxml2 安装前缀 |
–with-xsl | –with-xsl=DIR | 开启XSL , DIR 为 libxslt 的基础安装目录(libxslt >= 1.1.0 required) |
–enable-zend-test | –enable-zend-test | 开启 zend-test 扩展 |
–enable-zip | –enable-zip | 开启 Zip 的读写 |
–with-zlib-dir | –with-zlib-dir=DIR | ZIP: 将路径设置为 libz 的安装前缀 |
–with-pcre-dir | –with-pcre-dir | ZIP: pcre 安装前缀 |
–with-libzip | –with-libzip=DIR | ZIP: 使用 libzip |
–enable-mysqlnd | –enable-mysqlnd | 启用 mysqlnd ,将在其他扩展中隐性执行 |
–disable-mysqlnd-compression-support | –disable-mysqlnd-compression-support | 在 mysqlnd 中禁用对 MySQL 压缩协议的支持 |
–with-zlib-dir | –with-zlib-dir=DIR | mysqlnd: 将路径设置为 libz 的安装前缀 |
–with-pear | –with-pear=DIR | 在 PREFIX/lib/php 中安装 PEAR |
–without-pear | –without-pear | 不安装 PEAR |
–enable-maintainer-zts | –enable-maintainer-zts | 启用线程安全(for code maintainers only!!) |
–disable-inline-optimization | –disable-inline-optimization | 如果创建 zend_execute.lo 失败,尝试这个开关 |
–disable-zend-signals | –disable-zend-signals | 是否启用 zend 信号处理 |
–with-tsrm-pth | –with-tsrm-pth=pth-config | 使用 GNU Pth |
–with-tsrm-st | –with-tsrm-st | 是用 SGI 的 State Threads |
–with-tsrm-pthreads | –with-tsrm-pthreads | 使用 POSIX 线程 |
–enable-shared | –enable-shared=PKGS | 创建共享库, 默认为 yes |
–enable-static | –enable-static=PKGS | 创建静态库,默认为 yes |
–enable-fast-install | –enable-fast-install=PKGS | 优化快速安装,默认为 yes |
–with-gnu-ld | –with-gnu-ld | 假设 C 编译器使用 GNU ld ,默认为 no |
–disable-libtool-lock | –disable-libtool-lock | 避免锁定(可能破坏并行构建) |
–with-pic | –with-pic | 尝试只用 PIC 或 non-PIC 对象,默认为两个都是用 |
–with-tags | –with-tags=TAGS | 自动包含其他配置 |
根据需求选定合适的设置选项并执行 ./configure
本次安装选项如下:
./configure \
--prefix=/usr/local/php-7.3.5 \
--enable-bcmath \
--enable-dba \
--enable-embed \
--enable-exif \
--enable-fpm \
--enable-ftp \
--enable-mbstring \
--enable-mysqlnd \
--enable-phpdbg \
--enable-sockets \
--with-curl \
--with-gd \
--with-libzip \
--with-mhash \
--with-mysqli \
--with-openssl \
--with-pdo-mysql \
--with-xsl \
--with-zlib \
--enable-zip \
--disable-cgi
执行以上指令,报如下错误:
[root@instance-36dg06w0 php-7.3.5]# ./configure \
> --prefix=/usr/local/php-7.3.5 \
> --enable-bcmath \
> --enable-dba \
> --enable-embed \
> --enable-exif \
> --enable-fpm \
> --enable-ftp \
> --enable-mbstring \
> --enable-mysqlnd \
> --enable-phpdbg \
> --enable-sockets \
> --with-curl \
> --with-gd \
> --with-libzip \
> --with-mhash \
> --with-mysqli \
> --with-openssl \
> --with-pdo-mysql \
> --with-xsl \
> --with-zlib \
> --enable-zip \
> --disable-cgi
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for cc... no
checking for gcc... no
configure: error: in `/usr/local/src/php-7.3.5':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
安装 gcc
[root@instance-36dg06w0 php-7.3.5]# yum install gcc
再次执行以上 ./configure
,报如下错误:
checking for bison version... invalid
configure: WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: none, min: 204, excluded: ).
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
configure: error: bison is required to build PHP/Zend when building a GIT checkout!
安装 bison
[root@instance-36dg06w0 php-7.3.5]# yum install bison
再次执行以上 ./configure
,报如下错误:
configure: error: libxml2 not found. Please check your libxml2 installation.
安装 libxml2
,发现 libxml2
已存在,网上查找后,发现是要安装 libxml2-devel
[root@instance-36dg06w0 php-7.3.5]# yum install libxml2
Loaded plugins: langpacks, versionlock
Excluding 1 update due to versionlock (use "yum versionlock status" to show it)
Package libxml2-2.9.1-6.el7_2.3.x86_64 already installed and latest version
Nothing to do
[root@instance-36dg06w0 php-7.3.5]# yum install libxml2-devel.x86_64
再次执行以上 ./configure
,报如下错误:
configure: error: Cannot find OpenSSL's <evp.h>
安装 openssl-devel
[root@instance-36dg06w0 php-7.3.5]# yum install openssl-devel.x86_64
再次执行以上 ./configure
,报如下错误:
configure: error: cURL version 7.15.5 or later is required to compile php with cURL support
安装 curl-devel
[root@instance-36dg06w0 php-7.3.5]# yum install curl-devel
再次执行以上 ./configure
,报如下错误:
configure: error: png.h not found.
安装 libpng-devel
[root@instance-36dg06w0 php-7.3.5]# yum install libpng-devel.x86_64
再次执行以上 ./configure
,报如下错误:
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
安装 libxslt-devel
[root@instance-36dg06w0 php-7.3.5]# yum install libxslt-devel.x86_64
再次执行以上 ./configure
,报如下错误:
configure: error: Please reinstall the libzip distribution
安装 libzip-devel
[root@instance-36dg06w0 php-7.3.5]# yum install libzip-devel.x86_64
再次执行以上 ./configure
,报如下错误:
checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11
先卸载就的 libzip
,再安装新的 libzip
# 卸载旧版本
[root@instance-36dg06w0 php-7.3.5]# yum remove libzip
[root@instance-36dg06w0 src]# tar -zxvf libzip-1.5.2.tar.gz
# 下载新版本并编译安装
[root@instance-36dg06w0 src]# wget https://libzip.org/download/libzip-1.5.2.tar.gz
[root@instance-36dg06w0 src]# mkdir build
[root@instance-36dg06w0 libzip-1.5.2]# cd build/
[root@instance-36dg06w0 build]# cmake ..
[root@instance-36dg06w0 build]# make
[root@instance-36dg06w0 build]# make install
cmake
安装
# 下载已编译的文件
wget https://github.com/Kitware/CMake/releases/download/v3.14.4/cmake-3.14.4-Linux-x86_64.tar.gz
# 解压
tar -xzvf cmake-3.14.4-Linux-x86_64.tar.gz
# 添加环境变量,在 /etc/profile 最后一行添加如下代码
export PATH="$PATH:/usr/local/cmake-3.14.4/bin"
# 更新环境变量
source /etc/profile
再次执行以上 ./configure
,报如下错误:
error: off_t undefined; check your library configuration
执行如下指令:
# 修改ld.so.conf,添加动态函数索引目录
[root@instance-36dg06w0 php-7.3.5]# echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf
# 更新配置
[root@instance-36dg06w0 php-7.3.5]# ldconfig -v
再次执行以上 ./configure
,执行成功!
执行 make
执行 make
之前,先执行 make clean
,清楚已存在的目标文件
[root@instance-36dg06w0 php-7.3.5]# make clean
执行 make
[root@instance-36dg06w0 php-7.3.5]# make
报如下错误
# 编译 fileinfo 时,虚拟内存耗尽,无法分配内存
virtual memory exhausted: Cannot allocate memory
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
对此,我们可以有以下两个方法:
- 在
./configure
指令中添加--disable-fileinfo
- 使用交换分区暂时扩大内存,编译安装完成后删除交换分区
具体操作如下:
[root@instance-36dg06w0 php-7.3.5]# dd if=/dev/zero of=/tmp/swap bs=16M count=64 # 创建 1G 的 swap 文件
64+0 records in
64+0 records out
1073741824 bytes (1.1 GB) copied, 8.53766 s, 126 MB/s
[root@instance-36dg06w0 php-7.3.5]# mkswap /tmp/swap # 格式化文件
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=c1650c77-e69b-4892-bf82-f7dd01fe33b8
[root@instance-36dg06w0 php-7.3.5]# swapon /tmp/swap # 启动 /tmp/swap 文件
swapon: /tmp/swap: insecure permissions 0644, 0600 suggested.
[root@instance-36dg06w0 php-7.3.5]# free -m
total used free shared buff/cache available
Mem: 972 276 166 55 529 438
Swap: 1023 0 1023
[root@instance-36dg06w0 php-7.3.5]# swapon -s
Filename Type Size Used Priority
/tmp/swap file 1048572 0 -2
完成以上操作后,make clean
后再次执行 make
[root@instance-36dg06w0 php-7.3.5]# make clean
...
[root@instance-36dg06w0 php-7.3.5]# make
编译成功,执行 make test
,生成了以下测试结果:
=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Bug #64267 (CURLOPT_INFILE doesn't allow reset) [ext/curl/tests/bug64267.phpt]
Bug #71523 (Copied handle with new option CURLOPT_HTTPHEADER crashes while curl_multi_exec) [ext/curl/tests/bug71523.phpt]
Bug #74090 stream_get_contents maxlength>-1 returns empty string on windows [ext/standard/tests/streams/bug74090.phpt]
stream context tcp_nodelay fopen [ext/standard/tests/streams/stream_context_tcp_nodelay_fopen.phpt]
=====================================================================
看上去好像是 curl
相关的问题,目前不知道如何处理以上问题,但好像影响不大,就先暂时放着吧。。。
执行 make install
[root@instance-36dg06w0 php-7.3.5]# make install
安装成功!
配置 PHP
将源码包中的 php.ini-production
复制到php安装目录的 lib
目录下,并修改文件名为 php.ini
。
[root@instance-36dg06w0 php-7.3.5]# cp php.ini-production /usr/local/php-7.3.5/lib/php.ini
因为
./configure
的时候没有设置–with-config-file-path
选项,所以系统默认在lib
目录中寻找,此时如果将php.ini
放到其他目录,则php-fpm
加载不到该文件,php.ini
的修改也会没有效果。所以一定要将php.ini
放到–with-config-file-path
设置的地方去。
其他配置修改:
[root@instance-36dg06w0 php-7.3.5]# cp /usr/local/php-7.3.5/etc/php-fpm.d/www.conf.default /usr/local/php-7.3.5/etc/php-fpm.d/www.conf
[root@instance-36dg06w0 php-7.3.5]# cp /usr/local/php-7.3.5/etc/php-fpm.conf.default /usr/local/php-7.3.5/etc/php-fpm.conf
[root@instance-36dg06w0 php-7.3.5]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@instance-36dg06w0 php-7.3.5]# chmod +x /etc/init.d/php-fpm
添加全局变量,打开 /etc/profile
文件,在文件中添加如下指令,并回到命令行执行 source /etc/profile
指令更新变量。
export PATH=$PATH:/usr/local/php-7.3.5/bin
安装成功,查看php版本:
[root@instance-36dg06w0 php-7.3.5]# php -v
PHP 7.3.5 (cli) (built: May 31 2019 14:53:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.5, Copyright (c) 1998-2018 Zend Technologies
php-fpm
启动与停止
通过以上配置,php-fpm
的启动停止命令如下:
/etc/init.d/php-fpm start #php-fpm启动命令
/etc/init.d/php-fpm stop #php-fpm停止命令
/etc/init.d/php-fpm restart #php-fpm重启命令
ps -ef | grep php 或者 ps -A | grep -i php #查看是否已经成功启动PHP
若希望通过 systemctl
来控制 php-fpm
的开启状态,可以在 /etc/systemd/system
目录下添加 php-fpm.service
文件,文件内容如下:
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php-7.3.5/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php-7.3.5/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
配置文件结构详解可参考 该页面。
通过以上配置,即可使用 systemctl
控制 php-fpm
的开启/关闭状态。
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl start *.service #启动服务
systemctl stop *.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态
systemctl --failed #显示启动失败的服务
安装完成
到此,编译安装完成。对了,如果不需要太大的虚拟内存,之前编译时因为内存不够而创建的 swap
可以删掉了,通过 rm
指令。
rm /tmp/swap
yum
安装
yum
安装就简单的多了,只需要找到对应的 yum 源,然后执行 yum install php*
指令即可安装完成。
PHP
扩展编译安装
安装了 PHP
后,如果想要增加某个扩展,,可以通过 PHP
自带的工具 phpize
来增加扩展。