安装 PHP
PHP(PHP: Hypertext Preprocessor
,超文本预处理器的字母缩写)是一种被广泛应用的开放源代码的多用途脚本语言,它可嵌入到 HTML 中,尤其适合 web 开发。
准备工作
开始之前我们需要先使用预先准备好的 bash 脚本,解压文件和授权目录,具体参考 脚本文件
本次编译安装 PHP 的方式,允许同时构建多个 php 版本,如: php-7.4.33
+ php-8.4.x
变更说明
- 从 2025/01/22 开始重新启用
php-7.4.33
以支撑旧项目; - 从 2025/01/22 开始正式移除
php-8.3.x
版本,其相关内容请阅读[PHP旧版]; - 由于发行版的兼容性问题,计划在 debian13 以后移除对
php-7.4.3
的支持;
构建 PHP
1. 安装依赖
本次 PHP 编译过程中,在系统原有扩展存在下,还需安装如下依赖项:
apt install libcurl4-openssl-dev libpng-dev libavif-dev libwebp-dev \
libjpeg-dev libxpm-dev libfreetype-dev libgmp-dev libonig-dev libcapstone-dev \
libsodium-dev libzip-dev -y
# php 扩展所需额外依赖
apt install autoconf libyaml-dev -y
# 在安装完 新版PHP所需依赖后,PHP 7.4 还需依赖如下:
# 未发现需要其他依赖项
debian12 纯净版所需完整依赖
apt install -y xz-utils
apt install -y make gcc g++ libcurl4-openssl-dev libpng-dev pkg-config \
libavif-dev libwebp-dev libjpeg-dev libxpm-dev libfreetype-dev libgmp-dev \
libonig-dev libcapstone-dev libsodium-dev libzip-dev libsystemd-dev libxml2-dev \
libffi-dev
# sqlite3 扩展所需依赖,已安装sqlite3则不需要
apt install libsqlite3-dev -y
# pgsql 扩展所需依赖,已安装PostgreSQL则不需要
apt install libpq-dev -y
# php 安装动态扩展所需依赖
apt install autoconf libyaml-dev -y
sqlite3 依赖
想使用最新或指定版 sqlite3 ,需自己编译好 sqlite3 后,在 PKG_CONFIG_PATH
环境变量中追加 sqlite3 的 pkgconfig
配置文件路径
usermod -a -G sqlite php-fpm
# 构建 PHP 需将 sqlite3 的 pkgconfig 目录加入到临时环境变量里
export PKG_CONFIG_PATH=/server/sqlite/lib/pkgconfig:$PKG_CONFIG_PATH
# 使用下面指令检查,sqlite3 是否正确加入
pkg-config --list-all | grep sqlite3
# 加入成功显示:
sqlite3 SQLite - SQL database engine
# 未安装 sqlite3,则需安装 libsqlite3-dev 依赖库
# 这中方式不用将 pkgconfig 加入到 PKG_CONFIG_PATH 环境变量中
apt install libsqlite3-dev -y
pgsql 依赖
想使用最新或指定版 pgsql,需自己编译好 libpq 库后,在 php 构建选项里指定目录路径
usermod -a -G postgres php-fpm
# PHP 的构建选项需指定Postgres安装目录
../configure --prefix=/server/php/84/ \
--with-pgsql=/server/postgres \
--with-pdo-pgsql=/server/postgres \
...
# 未安装 PostgreSQL 则需安装 libpq-dev 依赖库
# 该方式不需要指定postgres安装目录
apt install libpq-dev -y
依赖 openssl 特殊版本
重要说明
php-7.4 不支持 Debian12 自带的 openssl-3.0.x 版本,因此这里自行编译安装了 [openssl-1.1.1w],安装 php 动态扩展时,如果需要 openssl 支持的话,也需要跟 PHP 编译时的 openssl 兼容,例如:[mongodb 扩展]
点击 👉[查看详情]
提示
- 本次已编译 SQLite3,无需额外使用依赖库
- 确保 php 用户对 SQLite3 的 pkgconfig 目录有
读取
和执行
权限
- 确保 php 用户对 SQLite3 的 pkgconfig 目录有
- 本次已编译 Postgres,无需额外使用依赖库
- 确保 php 用户对 Postgres 安装目录要有
读取
和执行
权限
- 确保 php 用户对 Postgres 安装目录要有
- 不同版本所需依赖项可能不同
- 使用更多外部扩展,所需依赖项也会更多
- php 较低版本如果要在新版的 linux 系统上安装,很多依赖可能都需要自己重新
通常你需要自己去阅读 configure
的错误提示,以及掌握 linux 软件包的编译安装。
更复杂的情况
对于过时的 php 版本,安装在较新的 linux 发行版中,有些依赖会由于版本过高导致出错,但是 configure
检测并不会报错的情况,例如: php-7.4.33 依赖的 openssl 库版本过高问题,就不会报错
2. 创建并进入构建目录
mkdir /home/php-fpm/php-8.4.12/build_php
cd /home/php-fpm/php-8.4.12/build_php/
mkdir /home/php-fpm/php-7.4.33/build_php
cd /home/php-fpm/php-7.4.33/build_php/
3. 查看构建选项
# 全部构建选项
./configure -h
# 扩展构建选项
./configure -h | grep pgsql
./configure -h | grep sqlite
# 导出构建选项
./configure -h > configure.txt
'configure' configures PHP 8.4.12 to adapt to many kinds of systems.
Usage: ../configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print 'checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for '--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or '..']
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
By default, 'make install' will install all the files in
'/usr/local/bin', '/usr/local/lib' etc. You can specify
an installation prefix other than '/usr/local' using '--prefix',
for instance '--prefix=$HOME'.
For better control, use the options below.
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/php]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]
Program names:
--program-prefix=PREFIX prepend PREFIX to installed program names
--program-suffix=SUFFIX append SUFFIX to installed program names
--program-transform-name=PROGRAM run sed PROGRAM on installed program names
System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]
--target=TARGET configure for building compilers for TARGET [HOST]
Optional Features and Packages:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-libdir=NAME Look for libraries in .../NAME rather than .../lib
--disable-rpath Disable passing additional runtime library search
paths
--enable-re2c-cgoto Enable re2c -g flag to optimize conditional jumps
using computed goto extension, if supported by the
compiler
SAPI modules:
--with-apxs2[=FILE] Build shared Apache 2 handler module. FILE is the
optional pathname to the Apache apxs tool [apxs]
--disable-cli Disable building CLI version of PHP (this forces
--without-pear)
--enable-embed[=TYPE] Enable building of embedded SAPI library TYPE is
either 'shared' or 'static'. [TYPE=shared]
--enable-fpm Enable building of the fpm SAPI executable
--with-fpm-user[=USER] Set the user for php-fpm to run as. (default:
nobody)
--with-fpm-group[=GRP] Set the group for php-fpm to run as. For a system
user, this should usually be set to match the fpm
username (default: nobody)
--with-fpm-systemd Activate systemd integration
--with-fpm-acl Use POSIX Access Control Lists
--with-fpm-apparmor Support AppArmor confinement through libapparmor
--with-fpm-selinux Support SELinux policy library
--enable-fuzzer Build PHP as Clang fuzzing test module (for
developers)
--enable-litespeed Build PHP as litespeed module
--disable-phpdbg Disable building of phpdbg
--enable-phpdbg-debug Build phpdbg in debug mode to enable additional
diagnostic output for developing and troubleshooting
phpdbg itself
--enable-phpdbg-readline
Enable readline support in phpdbg (depends on static
ext/readline)
--disable-cgi Disable building CGI version of PHP
--with-valgrind Enable Valgrind support
General settings:
--enable-gcov Enable GCOV code coverage - FOR DEVELOPERS ONLY!!
--enable-debug Compile with debugging symbols
--enable-debug-assertions
Compile with debug assertions even in release mode
--enable-zts Enable thread safety
--enable-rtld-now Use dlopen with RTLD_NOW instead of RTLD_LAZY
--with-layout=TYPE Set how installed files will be laid out. Type can
be either PHP or GNU [PHP]
--with-config-file-path=PATH
Set the path in which to look for php.ini
[PREFIX/lib]
--with-config-file-scan-dir=PATH
Set the path where to scan for configuration files
--enable-sigchild Enable PHP's own SIGCHLD handler
--enable-libgcc Enable explicitly linking against libgcc
--disable-short-tags Disable the short-form <? start tag by default
--enable-dmalloc Enable dmalloc
--disable-ipv6 Disable IPv6 support
--enable-dtrace Enable DTrace support
--enable-fd-setsize Set size of descriptor sets
--enable-werror Enable -Werror
--enable-memory-sanitizer
Enable memory sanitizer (clang only)
--enable-address-sanitizer
Enable address sanitizer
--enable-undefined-sanitizer
Enable undefined sanitizer
Extensions:
--with-EXTENSION=[shared[,PATH]]
NOTE: Not all extensions can be built as 'shared'.
Example: --with-foobar=shared,/usr/local/foobar/
o Builds the foobar extension as shared extension.
o foobar package install prefix is /usr/local/foobar/
--disable-all Disable all extensions which are enabled by default
--without-libxml Build without LIBXML support
--with-openssl Include OpenSSL support (requires OpenSSL >= 1.1.1)
--with-system-ciphers OPENSSL: Use system default cipher list instead of
hardcoded value
--with-openssl-legacy-provider
OPENSSL: Load legacy algorithm provider in addition
to default provider
--with-openssl-argon2 OPENSSL: Enable argon2 password hashing
--with-external-pcre Use external library for PCRE support
--without-pcre-jit Disable PCRE JIT functionality
--without-sqlite3 Do not include SQLite3 support.
--with-zlib Include ZLIB support (requires zlib library)
--enable-bcmath Enable bc style precision math functions
--with-bz2[=DIR] Include BZip2 support
--enable-calendar Enable support for calendar conversion
--disable-ctype Disable ctype functions
--with-curl Include cURL support
--enable-dba Build DBA with bundled modules. To build shared DBA
extension use --enable-dba=shared
--with-qdbm[=DIR] DBA: QDBM support
--with-gdbm[=DIR] DBA: GDBM support
--with-ndbm[=DIR] DBA: NDBM support
--with-db4[=DIR] DBA: Oracle Berkeley DB 4.x or 5.x support
--with-db3[=DIR] DBA: Oracle Berkeley DB 3.x support
--with-db2[=DIR] DBA: Oracle Berkeley DB 2.x support
--with-db1[=DIR] DBA: Oracle Berkeley DB 1.x support/emulation
--with-dbm[=DIR] DBA: DBM support
--with-tcadb[=DIR] DBA: Tokyo Cabinet abstract DB support
--with-lmdb[=DIR] DBA: Lightning memory-mapped database support
--without-cdb[=DIR] DBA: CDB support (bundled)
--disable-inifile DBA: INI support (bundled)
--disable-flatfile DBA: FlatFile support (bundled)
--enable-dl-test Enable dl_test extension
--disable-dom Disable DOM support
--with-enchant Include Enchant support
--enable-exif Enable EXIF (metadata from images) support
--with-ffi Include FFI support
--disable-fileinfo Disable fileinfo support
--disable-filter Disable input filter support
--enable-ftp Enable FTP support
--with-ftp-ssl Explicitly enable FTP over SSL support when building
without openssl extension or when using phpize. If
the openssl extension is enabled at the configure
step (--with-openssl), FTP-SSL is enabled implicitly
regardless of this option.
--enable-gd Include GD support
--with-external-gd Use external libgd
--with-avif GD: Enable AVIF support (only for bundled libgd)
--with-webp GD: Enable WEBP support (only for bundled libgd)
--with-jpeg GD: Enable JPEG support (only for bundled libgd)
--with-xpm GD: Enable XPM support (only for bundled libgd)
--with-freetype GD: Enable FreeType 2 support (only for bundled
libgd)
--enable-gd-jis-conv GD: Enable JIS-mapped Japanese font support (only
for bundled libgd)
--with-gettext[=DIR] Include GNU gettext support
--with-gmp[=DIR] Include GNU MP support. Use PKG_CONFIG_PATH (or
GMP_CFLAGS and GMP_LIBS) environment variables, or
alternatively the optional DIR argument to customize
where to look for the GNU MP library.
--with-mhash Include mhash support
--without-iconv[=DIR] Exclude iconv support
--enable-intl Enable internationalization support
--with-ldap[=DIR] Include LDAP support
--with-ldap-sasl LDAP: Build with Cyrus SASL support
--enable-mbstring Enable multibyte string support
--disable-mbregex MBSTRING: Disable multibyte regex support
--with-mysqli Include MySQLi support. The MySQL native driver will
be used
--with-mysql-sock[=SOCKPATH]
MySQLi/PDO_MYSQL: Location of the MySQL Unix socket
pointer. If unspecified, the default locations are
searched
--with-odbcver[=HEX] Force support for the passed ODBC version. A hex
number is expected, default 0x0350. Use the special
value of 0 to prevent an explicit ODBCVER to be
defined.
--with-adabas[=DIR] Include Adabas D support [/usr/local]
--with-sapdb[=DIR] Include SAP DB support [/usr/local]
--with-solid[=DIR] Include Solid support [/usr/local/solid]
--with-ibm-db2[=DIR] Include IBM DB2 support [/home/db2inst1/sqllib]
--with-empress[=DIR] Include Empress support $EMPRESSPATH (Empress
Version >= 8.60 required)
--with-empress-bcs[=DIR]
Include Empress Local Access support $EMPRESSPATH
(Empress Version >= 8.60 required)
--with-custom-odbc[=DIR]
Include user defined ODBC support. DIR is ODBC
install base directory [/usr/local]. Make sure to
define CUSTOM_ODBC_LIBS and have some odbc.h in your
include dirs. For example, you should define
following for Sybase SQL Anywhere 5.5.00 on QNX,
prior to running this configure script:
CPPFLAGS="-DODBC_QNX -DSQLANY_BUG" LDFLAGS=-lunix
CUSTOM_ODBC_LIBS="-ldblib -lodbc"
--with-iodbc Include iODBC support
--with-esoob[=DIR] Include Easysoft OOB support
[/usr/local/easysoft/oob/client]
--with-unixODBC[=DIR] Include unixODBC support. Use PKG_CONFIG_PATH (or
ODBC_CFLAGS and ODBC_LIBS) environment variables, or
alternatively the optional DIR argument to customize
where to look for the unixODBC library.
--with-dbmaker[=DIR] Include DBMaker support
--disable-opcache Disable Zend OPcache support
--disable-huge-code-pages
Disable copying PHP CODE pages into HUGE PAGES
--disable-opcache-jit Disable JIT
--with-capstone Support opcache JIT disassembly through Capstone
--enable-pcntl Enable pcntl support (CLI/CGI only)
--with-pdo-dblib[=DIR] PDO: DBLIB-DB support. DIR is the FreeTDS home
directory
--with-pdo-firebird[=DIR]
PDO: Firebird support. DIR is the Firebird base
install directory [/opt/firebird]
--with-pdo-mysql[=DIR] PDO: MySQL support. DIR is the MySQL base directory.
If no value or mysqlnd is passed as DIR, the MySQL
native driver will be used
--with-pdo-odbc=flavour,dir
PDO: Support for 'flavour' ODBC driver. The
'flavour' part determines what driver or driver
manager to use; it can be either ibm-db2, iODBC,
unixODBC, or generic. The include and lib dirs are
looked for under 'dir'. You may attempt to use an
otherwise unsupported driver using the 'generic'
flavour. The syntax for generic ODBC support is:
--with-pdo-odbc=generic,dir,libname,ldflags,cflags.
When built as 'shared' the extension filename is
always 'pdo_odbc.so'. For unixODBC and iODBC, the
'dir' part is ignored and can be omitted, as
pkg-config will be searched instead. For ibm-db2, it
will search for the DB2 driver at that path.
--with-pdo-pgsql[=DIR] PDO: PostgreSQL support. Optional DIR is the
PostgreSQL base install directory or the path to
pg_config. Also, the PGSQL_CFLAGS and PGSQL_LIBS
environment variables can be used instead of the DIR
argument to customize the libpq paths.
--without-pdo-sqlite PDO: sqlite 3 support.
--disable-pdo Disable PHP Data Objects support
--with-pgsql[=DIR] Include PostgreSQL support. Optional DIR is the
PostgreSQL base install directory or the path to
pg_config. Also, the PGSQL_CFLAGS and PGSQL_LIBS
environment variables can be used instead of the DIR
argument to customize the libpq paths.
--disable-phar Disable phar support
--disable-posix Disable POSIX-like functions
--with-libedit Include libedit readline replacement (CLI/CGI only)
--with-readline[=DIR] Include readline support (CLI/CGI only)
--disable-session Disable session support
--with-mm[=DIR] SESSION: Include mm support for session storage
--enable-shmop Enable shmop support
--disable-simplexml Disable SimpleXML support
--with-snmp[=DIR] Include SNMP support. Use PKG_CONFIG_PATH (or
SNMP_CFLAGS and SNMP_LIBS) environment variables, or
alternatively the optional DIR argument to customize
where to look for the net-snmp-config utility of the
NET-SNMP library.
--enable-soap Enable SOAP support
--enable-sockets Enable sockets support
--with-sodium Include sodium support
--with-external-libcrypt
Use external libcrypt or libxcrypt
--with-password-argon2 Include Argon2 support in password_*
--enable-sysvmsg Enable sysvmsg support
--enable-sysvsem Enable System V semaphore support
--enable-sysvshm Enable the System V shared memory support
--with-tidy[=DIR] Include TIDY support
--disable-tokenizer Disable tokenizer support
--disable-xml Disable XML support
--with-expat XML: use Expat library instead of libxml2 in the xml
extension
--disable-xmlreader Disable XMLReader support
--disable-xmlwriter Disable XMLWriter support
--with-xsl Build with XSL support
--enable-zend-test Enable zend_test extension
--with-zip Include Zip read/write support
--enable-mysqlnd Enable mysqlnd explicitly, will be done implicitly
when required by other extensions
--with-mysqlnd-ssl Explicitly enable extended SSL support in the
mysqlnd extension when building without openssl
extension or when using phpize. If the openssl
extension is enabled at the configure step
(--with-openssl), extended SSL is enabled implicitly
regardless of this option.
--disable-mysqlnd-compression-support
Disable support for the MySQL compressed protocol in
mysqlnd
PEAR:
--with-pear[=DIR] Install PEAR in DIR [PREFIX/lib/php]
Zend:
--disable-fiber-asm Disable the use of boost fiber assembly files
--disable-gcc-global-regs
Disable GCC global register variables
--disable-zend-signals Disable Zend signal handling
--enable-zend-max-execution-timers
Enable Zend max execution timers; when building with
thread safety (--enable-zts), they are automatically
enabled by default based on the system support
Libtool:
--enable-shared=PKGS Build shared libraries default=yes
--enable-static=PKGS Build static libraries default=yes
--enable-fast-install=PKGS
Optimize for fast installation default=yes
--with-gnu-ld Assume the C compiler uses GNU ld default=no
--disable-libtool-lock Avoid locking (might break parallel builds)
--with-pic Try to use only PIC/non-PIC objects default=use both
--with-tags=TAGS Include additional configurations automatic
Some influential environment variables:
PHP_EXTRA_VERSION
Extra PHP version label suffix, e.g. '-dev', 'rc1', '-acme'
PKG_CONFIG path to pkg-config utility
PKG_CONFIG_PATH
directories to add to pkg-config's search path
PKG_CONFIG_LIBDIR
path overriding pkg-config's built-in search path
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CPP C preprocessor
SYSTEMD_CFLAGS
C compiler flags for SYSTEMD, overriding pkg-config
SYSTEMD_LIBS
linker flags for SYSTEMD, overriding pkg-config
APPARMOR_CFLAGS
C compiler flags for APPARMOR, overriding pkg-config
APPARMOR_LIBS
linker flags for APPARMOR, overriding pkg-config
SELINUX_CFLAGS
C compiler flags for SELINUX, overriding pkg-config
SELINUX_LIBS
linker flags for SELINUX, overriding pkg-config
CXX C++ compiler command
CXXFLAGS C++ compiler flags
CXXCPP C++ preprocessor
VALGRIND_CFLAGS
C compiler flags for VALGRIND, overriding pkg-config
VALGRIND_LIBS
linker flags for VALGRIND, overriding pkg-config
LIBXML_CFLAGS
C compiler flags for LIBXML, overriding pkg-config
LIBXML_LIBS linker flags for LIBXML, overriding pkg-config
OPENSSL_CFLAGS
C compiler flags for OPENSSL, overriding pkg-config
OPENSSL_LIBS
linker flags for OPENSSL, overriding pkg-config
PCRE2_CFLAGS
C compiler flags for PCRE2, overriding pkg-config
PCRE2_LIBS linker flags for PCRE2, overriding pkg-config
SQLITE_CFLAGS
C compiler flags for SQLITE, overriding pkg-config
SQLITE_LIBS linker flags for SQLITE, overriding pkg-config
ZLIB_CFLAGS C compiler flags for ZLIB, overriding pkg-config
ZLIB_LIBS linker flags for ZLIB, overriding pkg-config
CURL_CFLAGS C compiler flags for CURL, overriding pkg-config
CURL_LIBS linker flags for CURL, overriding pkg-config
CURL_FEATURES
value of supported_features for libcurl, overriding pkg-config
ENCHANT2_CFLAGS
C compiler flags for ENCHANT2, overriding pkg-config
ENCHANT2_LIBS
linker flags for ENCHANT2, overriding pkg-config
ENCHANT_CFLAGS
C compiler flags for ENCHANT, overriding pkg-config
ENCHANT_LIBS
linker flags for ENCHANT, overriding pkg-config
FFI_CFLAGS C compiler flags for FFI, overriding pkg-config
FFI_LIBS linker flags for FFI, overriding pkg-config
PNG_CFLAGS C compiler flags for PNG, overriding pkg-config
PNG_LIBS linker flags for PNG, overriding pkg-config
AVIF_CFLAGS C compiler flags for AVIF, overriding pkg-config
AVIF_LIBS linker flags for AVIF, overriding pkg-config
WEBP_CFLAGS C compiler flags for WEBP, overriding pkg-config
WEBP_LIBS linker flags for WEBP, overriding pkg-config
JPEG_CFLAGS C compiler flags for JPEG, overriding pkg-config
JPEG_LIBS linker flags for JPEG, overriding pkg-config
XPM_CFLAGS C compiler flags for XPM, overriding pkg-config
XPM_LIBS linker flags for XPM, overriding pkg-config
FREETYPE2_CFLAGS
C compiler flags for FREETYPE2, overriding pkg-config
FREETYPE2_LIBS
linker flags for FREETYPE2, overriding pkg-config
GDLIB_CFLAGS
C compiler flags for GDLIB, overriding pkg-config
GDLIB_LIBS linker flags for GDLIB, overriding pkg-config
GMP_CFLAGS C compiler flags for GMP, overriding pkg-config
GMP_LIBS linker flags for GMP, overriding pkg-config
ICU_CFLAGS C compiler flags for ICU, overriding pkg-config
ICU_LIBS linker flags for ICU, overriding pkg-config
SASL_CFLAGS C compiler flags for SASL, overriding pkg-config
SASL_LIBS linker flags for SASL, overriding pkg-config
ONIG_CFLAGS C compiler flags for ONIG, overriding pkg-config
ONIG_LIBS linker flags for ONIG, overriding pkg-config
ODBC_CFLAGS C compiler flags for ODBC, overriding pkg-config
ODBC_LIBS linker flags for ODBC, overriding pkg-config
CAPSTONE_CFLAGS
C compiler flags for CAPSTONE, overriding pkg-config
CAPSTONE_LIBS
linker flags for CAPSTONE, overriding pkg-config
PDO_ODBC_CFLAGS
C compiler flags for PDO_ODBC, overriding pkg-config
PDO_ODBC_LIBS
linker flags for PDO_ODBC, overriding pkg-config
PGSQL_CFLAGS
C compiler flags for PGSQL, overriding pkg-config
PGSQL_LIBS linker flags for PGSQL, overriding pkg-config
EDIT_CFLAGS C compiler flags for EDIT, overriding pkg-config
EDIT_LIBS linker flags for EDIT, overriding pkg-config
SNMP_CFLAGS C compiler flags for SNMP, overriding pkg-config
SNMP_LIBS linker flags for SNMP, overriding pkg-config
LIBSODIUM_CFLAGS
C compiler flags for LIBSODIUM, overriding pkg-config
LIBSODIUM_LIBS
linker flags for LIBSODIUM, overriding pkg-config
ARGON2_CFLAGS
C compiler flags for ARGON2, overriding pkg-config
ARGON2_LIBS linker flags for ARGON2, overriding pkg-config
EXPAT_CFLAGS
C compiler flags for EXPAT, overriding pkg-config
EXPAT_LIBS linker flags for EXPAT, overriding pkg-config
XSL_CFLAGS C compiler flags for XSL, overriding pkg-config
XSL_LIBS linker flags for XSL, overriding pkg-config
EXSLT_CFLAGS
C compiler flags for EXSLT, overriding pkg-config
EXSLT_LIBS linker flags for EXSLT, overriding pkg-config
LIBZIP_CFLAGS
C compiler flags for LIBZIP, overriding pkg-config
LIBZIP_LIBS linker flags for LIBZIP, overriding pkg-config
EXTENSION_DIR
Default directory for dynamically loadable PHP extensions. If
left empty, it is determined automatically. Can be overridden
using the PHP 'extension_dir' INI directive.
PHP_UNAME System information (defaults to the 'uname -a' output)
PHP_BUILD_SYSTEM
The system that PHP was built on (defaults to the 'uname -a'
output)
PHP_BUILD_PROVIDER
The PHP build provider information
PHP_BUILD_COMPILER
Information about the compiler used for the PHP build
PHP_BUILD_ARCH
The build architecture
Use these variables to override the choices made by 'configure' or to help
it to find libraries and programs with nonstandard names/locations.
Report bugs to <https://github.com/php/php-src/issues>.
PHP home page: <https://www.php.net>.
`configure' configures PHP 7.4.33 to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..']
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.
For better control, use the options below.
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/php]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]
Program names:
--program-prefix=PREFIX prepend PREFIX to installed program names
--program-suffix=SUFFIX append SUFFIX to installed program names
--program-transform-name=PROGRAM run sed PROGRAM on installed program names
System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]
--target=TARGET configure for building compilers for TARGET [HOST]
Optional Features and Packages:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-libdir=NAME Look for libraries in .../NAME rather than .../lib
--disable-rpath Disable passing additional runtime library search
paths
--enable-re2c-cgoto Enable -g flag to re2c to use computed goto gcc
extension
--disable-gcc-global-regs
whether to enable GCC global register variables
SAPI modules:
--with-apxs2[=FILE] Build shared Apache 2 handler module. FILE is the
optional pathname to the Apache apxs tool [apxs]
--disable-cli Disable building CLI version of PHP (this forces
--without-pear)
--enable-embed[=TYPE] EXPERIMENTAL: Enable building of embedded SAPI
library TYPE is either 'shared' or 'static'.
[TYPE=shared]
--enable-fpm Enable building of the fpm SAPI executable
--with-fpm-user[=USER] Set the user for php-fpm to run as. (default:
nobody)
--with-fpm-group[=GRP] Set the group for php-fpm to run as. For a system
user, this should usually be set to match the fpm
username (default: nobody)
--with-fpm-systemd Activate systemd integration
--with-fpm-acl Use POSIX Access Control Lists
--enable-litespeed Build PHP as litespeed module
--enable-phpdbg Build phpdbg
--enable-phpdbg-webhelper
Build phpdbg web SAPI support
--enable-phpdbg-debug Build phpdbg in debug mode
--enable-phpdbg-readline
Enable readline support in phpdbg (depends on static
ext/readline)
--disable-cgi Disable building CGI version of PHP
--with-valgrind Enable valgrind support
General settings:
--enable-gcov Enable GCOV code coverage - FOR DEVELOPERS ONLY!!
--enable-debug Compile with debugging symbols
--enable-rtld-now Use dlopen with RTLD_NOW instead of RTLD_LAZY
--with-layout=TYPE Set how installed files will be laid out. Type can
be either PHP or GNU [PHP]
--with-config-file-path=PATH
Set the path in which to look for php.ini
[PREFIX/lib]
--with-config-file-scan-dir=PATH
Set the path where to scan for configuration files
--enable-sigchild Enable PHP's own SIGCHLD handler
--enable-libgcc Enable explicitly linking against libgcc
--disable-short-tags Disable the short-form <? start tag by default
--enable-dmalloc Enable dmalloc
--disable-ipv6 Disable IPv6 support
--enable-dtrace Enable DTrace support
--enable-fd-setsize Set size of descriptor sets
--enable-werror Enable -Werror
Extensions:
--with-EXTENSION=shared[,PATH]
NOTE: Not all extensions can be build as 'shared'.
Example: --with-foobar=shared,/usr/local/foobar/
o Builds the foobar extension as shared extension.
o foobar package install prefix is /usr/local/foobar/
--disable-all Disable all extensions which are enabled by default
--without-libxml Build without LIBXML support
--with-openssl Include OpenSSL support (requires OpenSSL >= 1.0.1)
--with-kerberos OPENSSL: Include Kerberos support
--with-system-ciphers OPENSSL: Use system default cipher list instead of
hardcoded value
--with-external-pcre Use external library for PCRE support
--with-pcre-jit Enable PCRE JIT functionality
--without-sqlite3 Do not include SQLite3 support.
--with-zlib Include ZLIB support (requires zlib >= 1.2.0.4)
--enable-apcu Enable APCu support
--disable-apcu-rwlocks Disable rwlocks in APCu
--enable-apcu-debug Enable APCu debugging
--enable-apcu-clear-signal Enable SIGUSR1 clearing handler
--disable-apcu-mmap Disable mmap, falls back on shm
--enable-apcu-spinlocks Use spinlocks before flocks
--disable-valgrind-checks
Disable valgrind based memory checks
--enable-coverage DEVELOPERS ONLY!!
--enable-bcmath Enable bc style precision math functions
--with-bz2[=DIR] Include BZip2 support
--enable-calendar Enable support for calendar conversion
--disable-ctype Disable ctype functions
--with-curl Include cURL support
--enable-dba Build DBA with bundled modules. To build shared DBA
extension use --enable-dba=shared
--with-qdbm[=DIR] DBA: QDBM support
--with-gdbm[=DIR] DBA: GDBM support
--with-ndbm[=DIR] DBA: NDBM support
--with-db4[=DIR] DBA: Oracle Berkeley DB 4.x or 5.x support
--with-db3[=DIR] DBA: Oracle Berkeley DB 3.x support
--with-db2[=DIR] DBA: Oracle Berkeley DB 2.x support
--with-db1[=DIR] DBA: Oracle Berkeley DB 1.x support/emulation
--with-dbm[=DIR] DBA: DBM support
--with-tcadb[=DIR] DBA: Tokyo Cabinet abstract DB support
--with-lmdb[=DIR] DBA: Lightning memory-mapped database support
--without-cdb[=DIR] DBA: CDB support (bundled)
--disable-inifile DBA: INI support (bundled)
--disable-flatfile DBA: FlatFile support (bundled)
--disable-dom Disable DOM support
--with-enchant Include Enchant support
--enable-exif Enable EXIF (metadata from images) support
--with-ffi Include FFI support
--disable-fileinfo Disable fileinfo support
--disable-filter Disable input filter support
--enable-ftp Enable FTP support
--with-openssl-dir FTP: Whether to enable FTP SSL support without
ext/openssl
--enable-gd Include GD support
--with-external-gd Use external libgd
--with-webp GD: Enable WEBP support (only for bundled libgd)
--with-jpeg GD: Enable JPEG support (only for bundled libgd)
--with-xpm GD: Enable XPM support (only for bundled libgd)
--with-freetype GD: Enable FreeType 2 support (only for bundled
libgd)
--enable-gd-jis-conv GD: Enable JIS-mapped Japanese font support (only
for bundled libgd)
--with-gettext[=DIR] Include GNU gettext support
--with-gmp[=DIR] Include GNU MP support
--with-mhash Include mhash support
--without-iconv[=DIR] Exclude iconv support
--with-imap[=DIR] Include IMAP support. DIR is the c-client install
prefix
--with-kerberos IMAP: Include Kerberos support
--with-imap-ssl IMAP: Include SSL support
--enable-intl Enable internationalization support
--disable-json Disable JavaScript Object Serialization support
--with-ldap[=DIR] Include LDAP support
--with-ldap-sasl LDAP: Build with Cyrus SASL support
--enable-mbstring Enable multibyte string support
--disable-mbregex MBSTRING: Disable multibyte regex support
--with-mysqli[=FILE] Include MySQLi support. FILE is the path to
mysql_config. If no value or mysqlnd is passed as
FILE, the MySQL native driver will be used
--with-mysql-sock[=SOCKPATH]
MySQLi/PDO_MYSQL: Location of the MySQL unix socket
pointer. If unspecified, the default locations are
searched
--with-oci8[=DIR] Include Oracle Database OCI8 support. DIR defaults
to $ORACLE_HOME. Use
--with-oci8=instantclient,/path/to/instant/client/lib
to use an Oracle Instant Client installation
--with-odbcver[=HEX] Force support for the passed ODBC version. A hex
number is expected, default 0x0350. Use the special
value of 0 to prevent an explicit ODBCVER to be
defined.
--with-adabas[=DIR] Include Adabas D support [/usr/local]
--with-sapdb[=DIR] Include SAP DB support [/usr/local]
--with-solid[=DIR] Include Solid support [/usr/local/solid]
--with-ibm-db2[=DIR] Include IBM DB2 support [/home/db2inst1/sqllib]
--with-empress[=DIR] Include Empress support $EMPRESSPATH (Empress
Version >= 8.60 required)
--with-empress-bcs[=DIR]
Include Empress Local Access support $EMPRESSPATH
(Empress Version >= 8.60 required)
--with-custom-odbc[=DIR]
Include user defined ODBC support. DIR is ODBC
install base directory [/usr/local]. Make sure to
define CUSTOM_ODBC_LIBS and have some odbc.h in your
include dirs. For example, you should define
following for Sybase SQL Anywhere 5.5.00 on QNX,
prior to running this configure script:
CPPFLAGS="-DODBC_QNX -DSQLANY_BUG" LDFLAGS=-lunix
CUSTOM_ODBC_LIBS="-ldblib -lodbc"
--with-iodbc Include iODBC support
--with-esoob[=DIR] Include Easysoft OOB support
[/usr/local/easysoft/oob/client]
--with-unixODBC Include unixODBC support
--with-dbmaker[=DIR] Include DBMaker support
--disable-opcache Disable Zend OPcache support
--disable-huge-code-pages
Disable copying PHP CODE pages into HUGE PAGES
--enable-pcntl Enable pcntl support (CLI/CGI only)
--disable-pdo Disable PHP Data Objects support
--with-pdo-dblib[=DIR] PDO: DBLIB-DB support. DIR is the FreeTDS home
directory
--with-pdo-firebird[=DIR]
PDO: Firebird support. DIR is the Firebird base
install directory [/opt/firebird]
--with-pdo-mysql[=DIR] PDO: MySQL support. DIR is the MySQL base directory.
If no value or mysqlnd is passed as DIR, the MySQL
native driver will be used
--with-zlib-dir[=DIR] PDO_MySQL: Set the path to libz install prefix
--with-pdo-oci[=DIR] PDO: Oracle OCI support. DIR defaults to
$ORACLE_HOME. Use
--with-pdo-oci=instantclient,/path/to/instant/client/lib
for an Oracle Instant Client installation.
--with-pdo-odbc=flavour,dir
PDO: Support for 'flavour' ODBC driver. The include
and lib dirs are looked for under 'dir'. The
'flavour' can be one of: ibm-db2, iODBC, unixODBC,
generic. If ',dir' part is omitted, default for the
flavour you have selected will be used. e.g.:
--with-pdo-odbc=unixODBC will check for unixODBC
under /usr/local. You may attempt to use an
otherwise unsupported driver using the 'generic'
flavour. The syntax for generic ODBC support is:
--with-pdo-odbc=generic,dir,libname,ldflags,cflags.
When built as 'shared' the extension filename is
always pdo_odbc.so
--with-pdo-pgsql[=DIR] PDO: PostgreSQL support. DIR is the PostgreSQL base
install directory or the path to pg_config
--without-pdo-sqlite PDO: sqlite 3 support.
--with-pgsql[=DIR] Include PostgreSQL support. DIR is the PostgreSQL
base install directory or the path to pg_config
--disable-phar Disable phar support
--disable-posix Disable POSIX-like functions
--with-pspell[=DIR] Include PSPELL support. GNU Aspell version 0.50.0 or
higher required
--with-libedit Include libedit readline replacement (CLI/CGI only)
--with-readline[=DIR] Include readline support (CLI/CGI only)
--enable-redis Enable redis support
--disable-redis-session Disable session support
--disable-redis-json Disable json serializer support
--enable-redis-igbinary Enable igbinary serializer support
--enable-redis-msgpack Enable msgpack serializer support
--enable-redis-lzf Enable lzf compression support
--with-liblzf=DIR Use system liblzf
--enable-redis-zstd Enable Zstd compression support
--with-libzstd=DIR Use system libzstd
--enable-redis-lz4 Enable lz4 compression support
--with-liblz4=DIR Use system liblz4
--disable-session Disable session support
--with-mm[=DIR] SESSION: Include mm support for session storage
--enable-shmop Enable shmop support
--disable-simplexml Disable SimpleXML support
--with-snmp[=DIR] Include SNMP support
--enable-soap Enable SOAP support
--enable-sockets Enable sockets support
--with-sodium Include sodium support
--with-password-argon2[=DIR]
Include Argon2 support in password_*. DIR is the
Argon2 shared library path
--enable-sysvmsg Enable sysvmsg support
--enable-sysvsem Enable System V semaphore support
--enable-sysvshm Enable the System V shared memory support
--with-tidy[=DIR] Include TIDY support
--disable-tokenizer Disable tokenizer support
--disable-xml Disable XML support
--with-expat XML: use expat instead of libxml2
--disable-xmlreader Disable XMLReader support
--with-xmlrpc[=DIR] Include XMLRPC-EPI support
--with-expat XMLRPC-EPI: use expat instead of libxml2
--with-iconv-dir=DIR XMLRPC-EPI: iconv dir for XMLRPC-EPI
--disable-xmlwriter Disable XMLWriter support
--with-xsl Build with XSL support
--with-yaml[=DIR] Enable LibYAML support.
DIR is the path to LibYAML install prefix
--enable-zend-test Enable zend-test extension
--with-zip Include Zip read/write support
--enable-mysqlnd Enable mysqlnd explicitly, will be done implicitly
when required by other extensions
--disable-mysqlnd-compression-support
Disable support for the MySQL compressed protocol in
mysqlnd
PEAR:
--with-pear[=DIR] Install PEAR in DIR [PREFIX/lib/php]
Zend:
--enable-maintainer-zts Enable thread safety - for code maintainers only!!
--disable-inline-optimization
If building zend_execute.lo fails, try this switch
--disable-zend-signals whether to enable zend signal handling
TSRM:
--with-tsrm-pth[=pth-config]
Use GNU Pth
--with-tsrm-st Use SGI's State Threads
--with-tsrm-pthreads Use POSIX threads (default)
Libtool:
--enable-shared=PKGS Build shared libraries default=yes
--enable-static=PKGS Build static libraries default=yes
--enable-fast-install=PKGS
Optimize for fast installation default=yes
--with-gnu-ld Assume the C compiler uses GNU ld default=no
--disable-libtool-lock Avoid locking (might break parallel builds)
--with-pic Try to use only PIC/non-PIC objects default=use both
--with-tags=TAGS Include additional configurations automatic
Some influential environment variables:
PKG_CONFIG path to pkg-config utility
PKG_CONFIG_PATH
directories to add to pkg-config's search path
PKG_CONFIG_LIBDIR
path overriding pkg-config's built-in search path
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CPP C preprocessor
SYSTEMD_CFLAGS
C compiler flags for SYSTEMD, overriding pkg-config
SYSTEMD_LIBS
linker flags for SYSTEMD, overriding pkg-config
VALGRIND_CFLAGS
C compiler flags for VALGRIND, overriding pkg-config
VALGRIND_LIBS
linker flags for VALGRIND, overriding pkg-config
LIBXML_CFLAGS
C compiler flags for LIBXML, overriding pkg-config
LIBXML_LIBS linker flags for LIBXML, overriding pkg-config
KERBEROS_CFLAGS
C compiler flags for KERBEROS, overriding pkg-config
KERBEROS_LIBS
linker flags for KERBEROS, overriding pkg-config
OPENSSL_CFLAGS
C compiler flags for OPENSSL, overriding pkg-config
OPENSSL_LIBS
linker flags for OPENSSL, overriding pkg-config
PCRE2_CFLAGS
C compiler flags for PCRE2, overriding pkg-config
PCRE2_LIBS linker flags for PCRE2, overriding pkg-config
SQLITE_CFLAGS
C compiler flags for SQLITE, overriding pkg-config
SQLITE_LIBS linker flags for SQLITE, overriding pkg-config
ZLIB_CFLAGS C compiler flags for ZLIB, overriding pkg-config
ZLIB_LIBS linker flags for ZLIB, overriding pkg-config
CURL_CFLAGS C compiler flags for CURL, overriding pkg-config
CURL_LIBS linker flags for CURL, overriding pkg-config
CURL_FEATURES
value of supported_features for libcurl, overriding pkg-config
ENCHANT_CFLAGS
C compiler flags for ENCHANT, overriding pkg-config
ENCHANT_LIBS
linker flags for ENCHANT, overriding pkg-config
FFI_CFLAGS C compiler flags for FFI, overriding pkg-config
FFI_LIBS linker flags for FFI, overriding pkg-config
PNG_CFLAGS C compiler flags for PNG, overriding pkg-config
PNG_LIBS linker flags for PNG, overriding pkg-config
WEBP_CFLAGS C compiler flags for WEBP, overriding pkg-config
WEBP_LIBS linker flags for WEBP, overriding pkg-config
JPEG_CFLAGS C compiler flags for JPEG, overriding pkg-config
JPEG_LIBS linker flags for JPEG, overriding pkg-config
XPM_CFLAGS C compiler flags for XPM, overriding pkg-config
XPM_LIBS linker flags for XPM, overriding pkg-config
FREETYPE2_CFLAGS
C compiler flags for FREETYPE2, overriding pkg-config
FREETYPE2_LIBS
linker flags for FREETYPE2, overriding pkg-config
GDLIB_CFLAGS
C compiler flags for GDLIB, overriding pkg-config
GDLIB_LIBS linker flags for GDLIB, overriding pkg-config
ICU_CFLAGS C compiler flags for ICU, overriding pkg-config
ICU_LIBS linker flags for ICU, overriding pkg-config
CXX C++ compiler command
CXXFLAGS C++ compiler flags
CXXCPP C++ preprocessor
SASL_CFLAGS C compiler flags for SASL, overriding pkg-config
SASL_LIBS linker flags for SASL, overriding pkg-config
ONIG_CFLAGS C compiler flags for ONIG, overriding pkg-config
ONIG_LIBS linker flags for ONIG, overriding pkg-config
ODBC_CFLAGS C compiler flags for ODBC, overriding pkg-config
ODBC_LIBS linker flags for ODBC, overriding pkg-config
EDIT_CFLAGS C compiler flags for EDIT, overriding pkg-config
EDIT_LIBS linker flags for EDIT, overriding pkg-config
LIBSODIUM_CFLAGS
C compiler flags for LIBSODIUM, overriding pkg-config
LIBSODIUM_LIBS
linker flags for LIBSODIUM, overriding pkg-config
EXPAT_CFLAGS
C compiler flags for EXPAT, overriding pkg-config
EXPAT_LIBS linker flags for EXPAT, overriding pkg-config
XSL_CFLAGS C compiler flags for XSL, overriding pkg-config
XSL_LIBS linker flags for XSL, overriding pkg-config
EXSLT_CFLAGS
C compiler flags for EXSLT, overriding pkg-config
EXSLT_LIBS linker flags for EXSLT, overriding pkg-config
LIBZIP_CFLAGS
C compiler flags for LIBZIP, overriding pkg-config
LIBZIP_LIBS linker flags for LIBZIP, overriding pkg-config
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
Report bugs to <https://bugs.php.net>.
PHP home page: <https://www.php.net>.
4. 构建指令参考
构建指令参考
../configure --prefix=/server/php/84/ \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--with-openssl \
--with-zlib \
--with-zip \
--enable-bcmath \
--enable-calendar \
--enable-intl \
--enable-exif \
--with-gettext \
--with-gmp \
--with-sodium \
--with-curl \
--with-ffi \
--enable-gd \
--with-avif \
--with-webp \
--with-jpeg \
--with-xpm \
--with-freetype \
--enable-mbstring \
--with-capstone \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
# postgres 根目录或 pg_config 路径
--with-pgsql=/server/postgres \
--with-pdo-pgsql=/server/postgres \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm > stdout.log
../configure --prefix=/server/php/74/ \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--with-openssl \
--with-pcre-jit \
--with-zlib \
--with-zip \
--enable-bcmath \
--enable-calendar \
--enable-intl \
--enable-exif \
--with-gettext \
--with-gmp \
--with-mhash \
--with-sodium \
--with-curl \
--with-ffi \
--enable-gd \
--with-webp \
--with-jpeg \
--with-xpm \
--with-freetype \
--enable-mbstring \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
# postgres 根目录或 pg_config 路径
--with-pgsql=/server/postgres \
--with-pdo-pgsql=/server/postgres \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm > stdout.log
# nohup make -j4 &
make -j4 > make.log
make test > make-test.log
make install
../configure --prefix=/server/php/84/ \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--with-openssl \
--with-zlib \
--with-zip \
--enable-bcmath \
--enable-calendar \
--enable-intl \
--enable-exif \
--with-gettext \
--with-gmp \
--with-sodium \
--with-curl \
--with-ffi \
--enable-gd \
--with-avif \
--with-webp \
--with-jpeg \
--with-xpm \
--with-freetype \
--enable-mbstring \
--with-capstone \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-pgsql \
--with-pdo-pgsql \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm > stdout.log
../configure --prefix=/server/php/74/ \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--with-openssl \
--with-pcre-jit \
--with-zlib \
--with-zip \
--enable-bcmath \
--enable-calendar \
--enable-intl \
--enable-exif \
--with-gettext \
--with-gmp \
--with-mhash \
--with-sodium \
--with-curl \
--with-ffi \
--enable-gd \
--with-webp \
--with-jpeg \
--with-xpm \
--with-freetype \
--enable-mbstring \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-pgsql \
--with-pdo-pgsql \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm > stdout.log
构建指令区别:
>=8.1.0
默认已经对 OpenSSL 启用pcre-jit
实现正则即时编译>=8.1.0
的 gd2 扩展增加的--with-avif
选项>=8.1.0
对--with-mhash
选项标记为已弃用,如果没有旧项目需要向后兼容,不要添加此选项>=8.4.0
增加--with-capstone
选项
PHP 配置
php.ini
是 PHP 的配置文件,具体选项可以阅读 官方手册
1. 配置文件模板
php 编译完成后,在源码包根目录下会自动生成两个推荐的配置文件模版
- 开发环境推荐:
php.ini-development
- 部署环境推荐:
php.ini-production
2. 配置文件路径
通过下面的指令可以快速获取到 PHP 配置文件存放路径
# php7.4
/server/php/74/bin/php --ini
# php8.4
/server/php/84/bin/php --ini
# php7.4
/server/php/74/bin/php-config --ini-path
# php8.4
/server/php/84/bin/php-config --ini-path
3. 拷贝配置文件
cp /home/php-fpm/php-8.4.12/php.ini-* /server/php/84/lib/
# 开发环境
cp /server/php/84/lib/php.ini{-development,}
# 部署环境
# cp /server/php/84/lib/php.ini{-production,}
cp /home/php-fpm/php-7.4.33/php.ini-* /server/php/74/lib/
# 开发环境
cp /server/php/74/lib/php.ini{-development,}
# 部署环境
# cp /server/php/74/lib/php.ini{-production,}
4. 检测配置文件
使用 php 程序,快速检测配置文件使用加载成功
# php7.4
/server/php/74/bin/php --ini
# php8.4
/server/php/84/bin/php --ini
5. 开启 OPcache
PHP 官方明确说明 OPcache 只允许编译为共享扩展,并默认构建
使用 --disable-opcache
选项可以禁止构建
# 在 `php.ini` 第 953 行,将 `;` 去掉
zend_extension=opcache
# 在 `php.ini` 第 1796 行,加入以下内容,可获得较好性能
# 检查脚本时间戳是否有更新的周期,以秒为单位
opcache.revalidate_freq=60
警告
开启 opcache
扩展,会导致数据被缓存,可能无法获取到最新数据,所以线上环境必须经过严格测试
如果你不明白自己在做什么,最好不要开启它
PHP-FPM 配置
Nginx 只能处理静态页面,如果要处理 php 脚本,就必须借助 PHP-FPM 这些 FastCGI 进程管理器
- nginx 将内容转发给 PHP-FPM
- PHP-FPM 接管 php 统一处理
- 处理后产生的返回值再返回给 nginx
- 最终由 nginx 输出
1. 配置文件分类
PHP-FPM 配置文件可分成两种
- 主进程配置文件:管理整个 PHP-FPM 服务的
- 工作池进程配置文件:管理单个工作池进程的
主进程:
主进程(master)配置文件,是针对整个 PHP-FPM 的通用配置
- 路径:
/server/php/etc/php-fpm.conf
- 数量: 有且仅有,1 个
- 需求: 主进程配置文件必须存在
- 默认: 默认未创建
- 模板:
/server/php/etc/php-fpm.conf.default
工作池进程:
工作池进程(pool)配置文件,是针对单个工作进程的配置文件
- 路径:
/server/php/etc/php-fpm.d/*.conf
- 数量: 允许多个
- 需求: 至少需要 1 个工作吃进程配置文件
- 默认: 默认未创建
- 模板:
/server/php/etc/php-fpm.d/www.conf.default
2. 主进程配置文件
PHP-FPM 的主配置文件选项基本上都是使用默认,所以案例选项很少
php 主配置文件案例
;/server/php/84/etc/php-fpm.conf
pid=/run/php84-fpm/process.pid
error_log=/server/logs/php/error-84.log
include=/server/php/84/etc/php-fpm.d/*.conf
;/server/php/74/etc/php-fpm.conf
pid=/run/php74-fpm/process.pid
error_log=/server/logs/php/error-74.log
include=/server/php/74/etc/php-fpm.d/*.conf
3. 工作池配置文件
PHP-FPM 工作池进程配置文件有多个,并且支持随意命名,但为了更好的管理,我们最好遵循一些规则:
- 针对单独站点 : 跟 nginx 站点配置文件命名一致
- 根据工作池性质 :
- 接收 tp6 站点,命名
tp.conf
; - 接收其它站点,命名
default.conf
- 接收 tp6 站点,命名
通用工作池案例
; 路径: /server/php/84/etc/php-fpm.d/default.conf
; =============================================================================
; [子进程名] 通常与该配置文件的名称保持一致
; =============================================================================
[default]
; -----------------------------------------------------------------------------
; 主进程以root运行时,设置子进程用户 [通用]
; -----------------------------------------------------------------------------
;子进程用户,默认为 nobody (主进程不以root运行时,忽略此选项)
;user = php-fpm
;子进程用户组,默认为 nobody (主进程不以root运行时,忽略此选项)
;group = php-fpm
; -----------------------------------------------------------------------------
; 通过TCP端口监听/支持外部客户端/优化高并发
; -----------------------------------------------------------------------------
;监听所有网卡上的 9684 端口
;listen = 9684
;监听指定网卡上 9684 端口
listen = 127.0.0.1:9684
;设置 listen 的最大值,-1表示无限制,默认值:-1
listen.backlog = -1
;设置允许连接的客户端(IPv4 或 IPv6 地址列表),缺省:未设置(接受所有客户端连接)
;listen.allowed_clients = 127.0.0.1,192.168.66.254
listen.allowed_clients = 127.0.0.1
; -----------------------------------------------------------------------------
; 通过套接字(unix socket)监听/仅支持本机客户端/更低的延迟
; -----------------------------------------------------------------------------
;指定套接字监听文件路径
;listen = /run/php83-fpm/default.sock
;使用套接字监听方式时,允许设置监听用户
;子进程监听用户,默认为 nobody
;listen.owner = php-fpm
;子进程监听用户组,默认为 nobody
;listen.group = php-fpm
;监听权限
;listen.mode = 0660
; -----------------------------------------------------------------------------
; 设置进程管理器管理进程数量的方式 [通用]
; -----------------------------------------------------------------------------
;方式 1: 固定进程数
;设置进程管理器管理的子进程数量是固定的
;pm = static
;pm 为 static 时表示创建的子进程的数量,pm 为 dynamic 时表示最大可创建的子进程的数量
;pm.max_children = 50
;设置每个子进程重启前服务过的请求数量,对于存在内存泄漏的第三方模块来说是非常有用的
;pm.max_requests = 1000
;方式 2: 动态进程数
pm = dynamic
pm.max_children = 50
;设置启动时创建的子进程数目(仅在 pm-dynamic 时使用)
pm.start_servers = 2
;设置空闲服务进程的最低数目(仅在 pm-dynamic 时使用)
pm.min_spare_servers = 1
;设置空闲服务进程的最大数目(仅在 pm-dynamic 时使用)
pm.max_spare_servers = 3
pm.max_requests = 500
;/server/php/74/etc/php-fpm.d/default.conf
[74]
listen = 127.0.0.1:9674
listen.backlog = -1
;仅支持监听对象是 unix 套接字
;listen.owner = php-fpm
;listen.group = php-fpm
;listen.mode = 0660
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 500
ThinkPHP 项目专用工作池案例
[tp]
listen = 127.0.0.1:9610
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 500
更多参数说明,请阅读 PHP 手册
⚠️ 下面是 FastCGI 工作进程池的资源竞争导致请求死锁的案例以及具体解决方案:
1. `接口提供者-站点A` 跟 `当前项目-站点B` 在同台服务器;
2. IIS 手动增加的 FastCGi 最大实例数默认为 4,维护者未做修改;
3. 2 个站点共用同一个 `程序应用池`;
4. 由于 2 个站点需要的 PHP 版本号一样,共用同一个 FastCGI 程序(php-cgi.exe 文件);
5. `站点A` 提供接口给 `站点B`;
6. `站点B-前端` 有个页面向 `站点B-PHP后端` 同时发起了 `5个请求`;
7. `这5个请求` 又是全部需要向 `站点A` 发起 CURL 请求来获得数据的;
8. 到此当前 `程序应用池` 对 FasCGI 模块最大可生成的 4 个工作进程已被 `站点B前端->站点B后端` 的 5 个并发请求全部占用(有 1 个请求在排队中);
9. 所以 `站点B->站点A` 的 CURL 请求也全部在排队中,发生了堵塞事件;
10. 这个情况,只有到请求超时返回失败 FastCGI 子进程才能被释放;
11. 由于 `这5个请求` 同时发出,失败几乎也是同时发生,所以这个页面的 5 请求会陷入请求失败的死循环。
1. `PHP当前项目站点` 不要跟 `PHP接口站点` 处于同台服务器;
- 完美解决
2. 为每个站点设置不同的 `应用程序池`,不同应用程序池之间工作进程是独立;
- 在服务器资源有限的情况,这是完美解决方案
3. 在性能允许的情况下增大 `FastCGI设置 > 最大实例数` 的值;
- 临时应急,不能从根本上解决问题
4. 每个站点单独使用一个 `php-cgi.exe` 程序(复制 `php-cgi.exe` 重命名)。
- 可行但不建议,仅在 web 服务器不支持 `方式2` 的情况下使用
1. `PHP当前项目站点` 不要跟 `PHP接口站点` 处于同台服务器;
- 完美解决
2. 为每个站点设置单独的 `工作池`,不同工作池产生 `worker进程` 是独立的;
- 在服务器资源有限的情况,这是完美解决方案
- 在 `<phpRootPath>/etc/php-fpm.d` 目录下增加工作池配置文件
3. 在性能允许的情况下增大 `max_children` 的值;
- 临时应急,不能从根本上解决问题
Systemd 管理
PHP-FPM 自带了一套比较完善的进程管理指令,编译完成后还会在构建目录下生成 Systemd Unit 文件
默认模板
# It's not recommended to modify this file in-place, because it
# will be overwritten during upgrades. If you want to customize,
# the best way is to use the "systemctl edit" command.
[Unit]
Description=The PHP FastCGI Process Manager
After=network.target
[Service]
Type=notify
PIDFile=/server/php/84/var/run/php-fpm.pid
ExecStart=/server/php/84/sbin/php-fpm --nodaemonize --fpm-config /server/php/84/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
# Set up a new file system namespace and mounts private /tmp and /var/tmp directories
# so this service cannot access the global directories and other processes cannot
# access this service's directories.
PrivateTmp=true
# Mounts the /usr, /boot, and /etc directories read-only for processes invoked by this unit.
ProtectSystem=full
# Sets up a new /dev namespace for the executed processes and only adds API pseudo devices
# such as /dev/null, /dev/zero or /dev/random (as well as the pseudo TTY subsystem) to it,
# but no physical devices such as /dev/sda.
PrivateDevices=true
# Explicit module loading will be denied. This allows to turn off module load and unload
# operations on modular kernels. It is recommended to turn this on for most services that
# do not need special file systems or extra kernel modules to work.
ProtectKernelModules=true
# Kernel variables accessible through /proc/sys, /sys, /proc/sysrq-trigger, /proc/latency_stats,
# /proc/acpi, /proc/timer_stats, /proc/fs and /proc/irq will be made read-only to all processes
# of the unit. Usually, tunable kernel variables should only be written at boot-time, with the
# sysctl.d(5) mechanism. Almost no services need to write to these at runtime; it is hence
# recommended to turn this on for most services.
ProtectKernelTunables=true
# The Linux Control Groups (cgroups(7)) hierarchies accessible through /sys/fs/cgroup will be
# made read-only to all processes of the unit. Except for container managers no services should
# require write access to the control groups hierarchies; it is hence recommended to turn this on
# for most services
ProtectControlGroups=true
# Any attempts to enable realtime scheduling in a process of the unit are refused.
RestrictRealtime=true
# Restricts the set of socket address families accessible to the processes of this unit.
# Protects against vulnerabilities such as CVE-2016-8655
RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX
# Takes away the ability to create or manage any kind of namespace
RestrictNamespaces=true
[Install]
WantedBy=multi-user.target
# It's not recommended to modify this file in-place, because it
# will be overwritten during upgrades. If you want to customize,
# the best way is to use the "systemctl edit" command.
[Unit]
Description=The PHP FastCGI Process Manager
After=network.target
[Service]
Type=notify
PIDFile=/server/php/74/var/run/php-fpm.pid
ExecStart=/server/php/74/sbin/php-fpm --nodaemonize --fpm-config /server/php/74/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
# Set up a new file system namespace and mounts private /tmp and /var/tmp directories
# so this service cannot access the global directories and other processes cannot
# access this service's directories.
PrivateTmp=true
# Mounts the /usr, /boot, and /etc directories read-only for processes invoked by this unit.
ProtectSystem=full
# Sets up a new /dev namespace for the executed processes and only adds API pseudo devices
# such as /dev/null, /dev/zero or /dev/random (as well as the pseudo TTY subsystem) to it,
# but no physical devices such as /dev/sda.
PrivateDevices=true
# Explicit module loading will be denied. This allows to turn off module load and unload
# operations on modular kernels. It is recommended to turn this on for most services that
# do not need special file systems or extra kernel modules to work.
ProtectKernelModules=true
# Kernel variables accessible through /proc/sys, /sys, /proc/sysrq-trigger, /proc/latency_stats,
# /proc/acpi, /proc/timer_stats, /proc/fs and /proc/irq will be made read-only to all processes
# of the unit. Usually, tunable kernel variables should only be written at boot-time, with the
# sysctl.d(5) mechanism. Almost no services need to write to these at runtime; it is hence
# recommended to turn this on for most services.
ProtectKernelTunables=true
# The Linux Control Groups (cgroups(7)) hierarchies accessible through /sys/fs/cgroup will be
# made read-only to all processes of the unit. Except for container managers no services should
# require write access to the control groups hierarchies; it is hence recommended to turn this on
# for most services
ProtectControlGroups=true
# Any attempts to enable realtime scheduling in a process of the unit are refused.
RestrictRealtime=true
# Restricts the set of socket address families accessible to the processes of this unit.
# Protects against vulnerabilities such as CVE-2016-8655
RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX
# Takes away the ability to create or manage any kind of namespace
RestrictNamespaces=true
[Install]
WantedBy=multi-user.target
案例参考
echo "[Unit]
Description=The PHP 8.4 FastCGI Process Manager
After=network.target
[Service]
Type=notify
User=php-fpm
Group=php-fpm
RuntimeDirectory=php84-fpm
RuntimeDirectoryMode=0750
ExecStart=/server/php/84/sbin/php-fpm --nodaemonize --fpm-config /server/php/84/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 \$MAINPID
PrivateTmp=true
ProtectSystem=full
PrivateDevices=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectControlGroups=true
RestrictRealtime=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX
RestrictNamespaces=true
[Install]
WantedBy=multi-user.target
" > /lib/systemd/system/php84-fpm.service
echo "[Unit]
Description=The PHP 7.4 FastCGI Process Manager
After=network.target
[Service]
Type=notify
User=php-fpm
Group=php-fpm
RuntimeDirectory=php74-fpm
RuntimeDirectoryMode=0750
# RuntimeDirectoryPreserve=yes #如果存在多个php版本并且都指向同一目录,则必须设为yes,否则停止其中一个服务,目录就会自动删除
ExecStart=/server/php/74/sbin/php-fpm --nodaemonize --fpm-config /server/php/74/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
ProtectSystem=full
PrivateDevices=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectControlGroups=true
RestrictRealtime=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX
RestrictNamespaces=true
[Install]
WantedBy=multi-user.target
" > /lib/systemd/system/php74-fpm.service
# 创建单元文件
mv /path/php*-fpm.service /usr/lib/systemd/system/
# 重载Systemd
systemctl daemon-reload
# 加入systemctl服务,并立即开启
systemctl enable --now php84-fpm
systemctl enable --now php74-fpm
注意事项:
- 1 个
unix-socket
,对应 1 个php-fpm
工作进程 - 1 个 php-fpm 工作进程配置文件对应 1 个 unix-socket
- 多个配置文件,不允许指向同一个 unix-socket,会出现冲突
- 每个配置文件:
- 必须设置单独的
socket
文件路径,如:tp6.sock、default.sock - 可以设置自己的用户,如:www、nginx、php-fpm、nobody
- 必须设置单独的
Composer
Composer 是一个 PHP 依赖管理工具,开发环境必备
警告
不建议在部署环境安装 git
composer
npm
等开发环境工具
请全部在开发环境处理好,然后拷贝进服务器即可
1. 安装
推荐直接使用阿里云镜像下载 composer
su - php-fpm -s /bin/zsh
cd /server/php/tools
./php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
./php composer-setup.php
./php -r "unlink('composer-setup.php');"
chmod 750 composer.phar
# 软链接到可用的环境变量路径,如: /usr/local/bin/ 路径下
ln -s /server/php/tools/composer.phar /usr/local/bin/composer
2. 全量镜像
Composer 国内全量镜像推荐 华为云>腾讯云>阿里云
# 切换到开发用户或php-fpm用户
su - php-fpm -s /bin/zsh
# 使用国内 Composer 全量镜像
composer config -g repo.packagist composer https://mirrors.huaweicloud.com/repository/php/
# 取消使用国内 Composer 全量镜像
composer config -g --unset repos.packagist
国内镜像推荐
# 华为云
composer config -g repo.packagist composer https://mirrors.huaweicloud.com/repository/php/
# 腾讯云
composer config -g repos.packagist composer https://mirrors.cloud.tencent.com/composer/
# 阿里云 [不能实时同步,部分扩展缺失]
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
3. 升级
升级 composer 也非常简单,建议使用国内全量镜像后再升级
# 切换到php-fpm用户,只能从root进入
su - php-fpm -s /bin/zsh
/server/php/84/bin/php /usr/local/bin/composer self-update
升级 PHP
升级 PHP 跟正常编译几乎一样,下面是注意事项:
安装依赖
- PHP 跨主版本更新,必须重新编译安装动态扩展;
- PHP 跨次版本更新,建议重新编译安装动态扩展;
- PHP 小版本更新,如果 PHP 并未修改动态扩展,就不用重新编译安装动态扩展。
重命名执行程序 执行
make install
之前,先将sbin/php-fpm
文件重命名,实现平滑升级bash# php8.4 mv /server/php/84/sbin/php-fpm{,.bak}
配置文件
php.ini
- 小版本升级,需要修改配置文件,除非遇到 PHP 非常特殊的情况,
- 其他版本升级,就直接替换掉配置文件,然后将需要的动态扩展重新加上去即可
警告
服务器升级 PHP 乃至任何软件升级前,都应该先存快照,备份一份
动态安装 PECL 扩展
项目运行过程中,可能需要额外的扩展支持,这时我们不可避免要去安装动态扩展
# 使用 phpize 初始化 configure 配置文件时,需要 autoconf 依赖库
apt install autoconf -y
# /server/php/84/lib/php.ini
extension=redis
extension=mongodb
extension=yaml
extension=apcu
;zend_extension=opcache
zend_extension=xdebug
[xdebug]
# xdebug.mode=off
xdebug.mode=develop,coverage,debug,gcstats,profile,trace
xdebug.client_host=127.0.0.1
# xdebug.client_host=192.168.66.254
xdebug.client_port=9084
# /server/php/74/lib/php.ini
extension=redis
extension=mongodb
extension=yaml
extension=apcu
;zend_extension=opcache
zend_extension=xdebug
[xdebug]
# xdebug.mode=off
xdebug.mode=develop,debug,trace
xdebug.client_host=127.0.0.1
# xdebug.client_host=192.168.66.254
xdebug.client_port=9074
# 加入环境变量的php版本
php --ri xdebug
php --ri redis
php --ri mongodb
php --ri yaml
php --ri apcu
/server/php/74/bin/php --ri xdebug
/server/php/74/bin/php --ri redis
/server/php/74/bin/php --ri mongodb
/server/php/74/bin/php --ri yaml
/server/php/74/bin/php --ri apcu
注意
在测试环境(Debian12 发行版)中安装 php-7.4.33 的 PECL 扩展,需要 使用特定版本的 Autoconf 来生成 configure 文件!
使用特定版本的 Autoconf
测试环境(Debian12 发行版)使用 /server/php/74/bin/phpize
生成 configure 文件时,通常会出现警告, 这是因为系统自带的 Autoconf 版本为 2.71
,从 php-7.4.33 源码包的 configure 文件开头可以看到, PHP 自身是使用 Autoconf-2.69
来生成 configure 文件的:
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for PHP 7.4.33.
...
我们可以自己从 Autoconf 官网 下载指定版本的包,并编译到自己的服务器上, 再将环境变量 $PATH
的首个检查路径设为 “刚刚编译的 Autoconf 的 bin 目录下” 这样可以确保使用该版本。
# 公共依赖库,请使用root账户编译
mkdir /server/autoconf-2.69
cd /root/autoconf-2.69
./configure --prefix=/server/autoconf-2.69
make -j4 > make.log
make install
# 修改 $PATH 首个检查路径
export PATH=/server/autoconf-2.69/bin:$PATH
1. xdebug 扩展
xdebug 扩展安装案例:
cd /home/php-fpm/php_ext/xdebug-3.4.2
phpize
./configure --with-php-config=/server/php/84/bin/php-config
make -j4 > make.log
make install
# 如果 Xdebug 和 OPCache 同时使用,xdebug 必须在 opcache 之后:
zend_extension=opcache
zend_extension=xdebug
[xdebug]
# xdebug.mode=off
xdebug.mode=develop,coverage,debug,gcstats,profile,trace
xdebug.client_host=127.0.0.1
# xdebug.client_host=192.168.66.254
xdebug.client_port=9084
cd /home/php-fpm/php_ext/xdebug-3.1.6
/server/php/74/bin/phpize
./configure --with-php-config=/server/php/74/bin/php-config
make -j4 > make.log
make install
# 如果 Xdebug 和 OPCache 同时使用,xdebug 必须在 opcache 之后:
zend_extension=opcache
zend_extension=xdebug
[xdebug]
# xdebug.mode=off
xdebug.mode=develop,debug,trace
xdebug.client_host=127.0.0.1
# xdebug.client_host=192.168.66.254
xdebug.client_port=9074
2. redis 扩展
cd /home/php-fpm/php_ext/redis-6.2.0
phpize
./configure --with-php-config=/server/php/84/bin/php-config
make -j4 > make.log
make test
make install
cd /home/php-fpm/php_ext/redis-6.2.0
/server/php/74/bin/phpize
./configure --with-php-config=/server/php/74/bin/php-config
make -j4 > make.log
make test
make install
3. MongoDB 扩展
cd /home/php-fpm/php_ext/mongodb-2.0.0
phpize
./configure --with-php-config=/server/php/84/bin/php-config
make -j4 > make.log
make test
make install
cd /home/php-fpm/php_ext/mongodb-1.20.1
/server/php/74/bin/phpize
./configure --with-php-config=/server/php/74/bin/php-config
make -j4 > make.log
make test
make install
重要说明
- mongodb 扩展包
>1.20.1
后的不再支持PHP 7.4
- 在 Debian12 发行版中
php-7.4.33
在安装 mongodb 扩展时,必须使用跟编译 PHP 时兼容的 openssl 版本, 具体操作见[依赖 openssl 特殊版本]
4. yaml 扩展
# 安装依赖库
apt install libyaml-dev -y
cd /home/php-fpm/php_ext/yaml-2.2.5
phpize
./configure --with-php-config=/server/php/84/bin/php-config
make -j4 > make.log
make test
make install
# 安装依赖库
apt install libyaml-dev -y
cd /home/php-fpm/php_ext/yaml-2.2.5
/server/php/74/bin/phpize
./configure --with-php-config=/server/php/74/bin/php-config
make -j4 > make.log
make test
make install
5. apcu 扩展
cd /home/php-fpm/php_ext/apcu-5.1.27
phpize
./configure --with-php-config=/server/php/84/bin/php-config
make -j4 > make.log
make test
make install
cd /home/php-fpm/php_ext/apcu-5.1.27
/server/php/74/bin/phpize
./configure --with-php-config=/server/php/74/bin/php-config
make -j4 > make.log
make test
make install
权限
chown php-fpm:php-fpm -R /server/php /server/logs/php
find /server/php /server/logs/php /server/php/tools/ -type f -exec chmod 640 {} \;
find /server/php /server/logs/php /server/php/tools/ -type d -exec chmod 750 {} \;
# 可执行文件需要执行权限
chmod 750 -R /server/php/{74,84}/{bin,sbin}
# 动态扩展库文件: 运行时需要读取权限,升级时需要写入权限,独立调用时需要执行权限(不存在独立调用)
chmod 640 /server/php/{84,74}/lib/php/extensions/no-debug-non-zts-*/*
# composer,phpCsFixer等工具包,在独立调用时也需要执行权限
chmod 750 /server/php/tools/{composer,php-cs-fixer}.phar
# 权限同部署环境
# 开发用户 emad 加入 lnpp包用户组
usermod -a -G sqlite,redis,postgres,mysql,php-fpm,nginx emad
什么是独立调用
像 {composer,php-cs-fixer}.phar
等 phar 工具包本质上都是 php 脚本文件, 只要终端支持 php 脚本,php 脚本文件
就可以象 sh 脚本文件
一样独立调用
#!/usr/bin/env php
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view
* the license that is located at the bottom of this file.
*/
...
php composer [options]
php php-cs-fixer [options]
/server/php/74/bin/php /server/php/tools/composer.phar [options]
/server/php/74/bin/php /server/php/tools/php-cs-fixer.phar [options]
composer [options]
php-cs-fixer [options]
/server/php/tools/composer.phar [options]
/server/php/tools/php-cs-fixer.phar [options]
独立调用的条件
php 可执行程序必须加入到对应终端的环境变量中,终端才能通过代码开头的 #!/usr/bin/env php
识别到。