源碼編譯安裝
獲取源碼
- 從官網的下載頁面下載對應的源碼。
- 從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
來增加擴展。