安装 PHP
PHP(PHP: Hypertext Preprocessor
,超文本预处理器的字母缩写)是一种被广泛应用的开放源代码的多用途脚本语言,它可嵌入到 HTML 中,尤其适合 web 开发。
构建 PHP 时可以直接指定 MySQL 的 socket 路径,所以建议在 MySQL 之后安装
提示
也可以在 php.ini 配置文件里指定 MySQL 的 socket 路径
扩展库
PHP 扩展库按加载时间可分为:动态库(共享扩展)
和 静态库
1. 动态库
动态库是在程序运行时链接的,动态库在编译时不会放到连接的目标程序中,即:可执行文件无法单独运行,动态库扩展名一般为:
win | unix |
---|---|
*.dll | *.so |
2. 静态库
静态库是在程序编译时链接的,静态库在编译时会直接整合到目标程序中,编译成功的可执行文件可独立运行,静态库扩展名一般为:
win | unix |
---|---|
*.lib | *.a |
3. 动态库和静态库区别
静态编译:静态库将需要的依赖在构建时,已经从系统 拷贝
到程序中,执行时就不需要调用系统的库,系统包移除时也不至于会让扩展失效,但是它会额外占用磁盘资源
动态编译:动态库构建了 1 个连接文件(*.so
) ,用于连接程序和系统对应库的文件,执行时需要调用系统的库以及该库对应的依赖项
- 性能:静态库优于动态库,服务器硬件配置较差的,应该倾向于静态库
- 体积:静态库体积大于动态库
- 升级:静态库升级需要重新构建 PHP,动态库升级只需要重新生成连接文件(
*.so
)即可 - 稳定:静态库更加稳定,对于动态库来讲,如果系统对应库升级,与动态库对应的构建版本不一致,可能会遇到兼容性问题
4. 扩展库构建类型选择
- 使用频繁的扩展库,推荐使用静态编译
- 更新频繁的扩展库,建议使用动态编译
- 非官方认可扩展库,建议使用动态编译
官方认可扩展库列表 里的扩展,如有必要均可用静态库的方式构建,安全性和稳定性都由官方验证过
准备工作
开始之前我们需要先使用预先准备好的 bash 脚本,解压文件和授权目录,具体参考 脚本文件
本次计划构建 2 个 php 版本:
php 7.4.x
php 8.3.x
静态编译 PECL 扩展
本次静态编译下面这些 PECL 扩展:
- apcu
- redis
- yaml
- rdkafka
1. 拷贝扩展源码
将 PECL 扩展源码拷贝到 php 的 ext 目录下
cd /home/php-fpm/php_ext
cp -p -r apcu-5.1.23 /home/php-fpm/php-8.3.12/ext/apcu
cp -p -r redis-6.0.2 /home/php-fpm/php-8.3.12/ext/redis
cp -p -r yaml-2.2.3 /home/php-fpm/php-8.3.12/ext/yaml
cp -p -r apcu-5.1.23 /home/php-fpm/php-7.4.33/ext/apcu
cp -p -r redis-6.0.2 /home/php-fpm/php-7.4.33/ext/redis
cp -p -r yaml-2.2.3 /home/php-fpm/php-7.4.33/ext/yaml
2. 重新生成 php 配置
PHP 增加新扩展后,需要使用 autoconf
工具重新生成 配置脚本-configure
安装 autoconf 工具
apt install autoconf -y
重新生成 configure 配置脚本
cd /home/php-fpm/php-8.3.12/
mv configure{,.original}
./buildconf --force
cd /home/php-fpm/php-7.4.33/
mv configure{,.original}
./buildconf --force
pkg-config
构建 php 时,自己编译的依赖包需要手动加入到 pkg-config 中
使用 export 是临时加入环境变量中,但会永久记录在编译后的可执行文件信息里
1. 查看临时环境变量
查看当前终端临时的环境变量,避免多次引入路径,造成混淆
echo $PKG_CONFIG_PATH
2. 加入临时环境变量
将所需路径加入到当前终端临时的环境变量中
export PKG_CONFIG_PATH=/path/to/pkgConfig_1:$PKG_CONFIG_PATH
export PKG_CONFIG_PATH=/path/to/pkgConfig_1:/path/to/pkgConfig_2:$PKG_CONFIG_PATH
3. 查看环境变量列表
使用下面指令,可以查看当前终端的全部环境变量列表
pkg-config --list-all
构建 PHP
1. 安装依赖
本次 PHP 编译,系统还需要如下依赖项:
apt install g++ libsystemd-dev libsqlite3-dev libcurl4-openssl-dev libffi-dev libgmp-dev libonig-dev libsodium-dev libyaml-dev libzip-dev -y
# php 8.3.0 开始如果要启用 capstone
apt install libcapstone-dev -y
# libpq-dev 包含 libpq库(是 PostgreSQL 官方的客户端库),用于与 PostgreSQL 服务器进行通信
apt install libpq-dev -y
# rdkafka
apt install librdkafka-dev -y
TIP
- 不同版本所需依赖项可能不同
- 使用更多外部扩展,所需依赖项也会更多
- php 较低版本如果要在新版的 linux 系统上安装,很多依赖都需要自己去重新构建
所以很多时候你要学会去阅读 configure
的报错提,以及掌握 linux 软件包的编译安装
2. 创建构建目录
mkdir /home/php-fpm/php-7.4.33/build_php
mkdir /home/php-fpm/php-8.3.12/build_php
3. 环境变量
构建 PHP 需要额外将 sqlite3
的 pkgconfig
目录加入到临时环境变量里
export PKG_CONFIG_PATH=/server/sqlite3/lib/pkgconfig:$PKG_CONFIG_PATH
# 使用下面指令检查,sqlite3 是否正确加入
pkg-config --list-all | grep sqlite3
# 加入成功显示:
sqlite3 SQLite - SQL database engine
如果服务器上未安装 sqlite3,则需要安装 libsqlite3-dev
依赖库,这样也不用将 pkgconfig
加入到 PKG_CONFIG_PATH 环境变量中
4. 查看构建选项
# 全部构建选项
./configure -h
# 扩展构建选项
./configure -h | grep redis
./configure -h | grep yaml
# 导出构建选项
./configure -h > configure.txt
构建选项预览
`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>.
`configure' configures PHP 8.3.4 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
--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
--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.0.2)
--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
--without-pcre-jit Disable 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)
--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-openssl-dir FTP: Whether to enable FTP SSL support without
ext/openssl
--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
--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
--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-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
--disable-opcache-jit Disable JIT
--with-capstone support opcache JIT disassembly through capstone
--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-rdkafka Include rdkafka support
--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-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 instead of libxml2
--disable-xmlreader Disable XMLReader support
--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:
--disable-fiber-asm Disable the use of boost fiber assembly files
--disable-zend-signals whether to enable zend signal handling
--enable-zend-max-execution-timers
whether to enable zend max execution timers
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
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
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
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
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
PHP_MONGODB_BSON_CFLAGS
C compiler flags for PHP_MONGODB_BSON, overriding pkg-config
PHP_MONGODB_BSON_LIBS
linker flags for PHP_MONGODB_BSON, overriding pkg-config
PHP_MONGODB_MONGOC_CFLAGS
C compiler flags for PHP_MONGODB_MONGOC, overriding pkg-config
PHP_MONGODB_MONGOC_LIBS
linker flags for PHP_MONGODB_MONGOC, overriding pkg-config
PHP_MONGODB_MONGOCRYPT_CFLAGS
C compiler flags for PHP_MONGODB_MONGOCRYPT, overriding
pkg-config
PHP_MONGODB_MONGOCRYPT_LIBS
linker flags for PHP_MONGODB_MONGOCRYPT, overriding pkg-config
PHP_MONGODB_SNAPPY_CFLAGS
C compiler flags for PHP_MONGODB_SNAPPY, overriding pkg-config
PHP_MONGODB_SNAPPY_LIBS
linker flags for PHP_MONGODB_SNAPPY, overriding pkg-config
PHP_MONGODB_ZLIB_CFLAGS
C compiler flags for PHP_MONGODB_ZLIB, overriding pkg-config
PHP_MONGODB_ZLIB_LIBS
linker flags for PHP_MONGODB_ZLIB, overriding pkg-config
PHP_MONGODB_ZSTD_CFLAGS
C compiler flags for PHP_MONGODB_ZSTD, overriding pkg-config
PHP_MONGODB_ZSTD_LIBS
linker flags for PHP_MONGODB_ZSTD, overriding pkg-config
PHP_MONGODB_SASL_CFLAGS
C compiler flags for PHP_MONGODB_SASL, overriding pkg-config
PHP_MONGODB_SASL_LIBS
linker flags for PHP_MONGODB_SASL, overriding pkg-config
PHP_MONGODB_SSL_CFLAGS
C compiler flags for PHP_MONGODB_SSL, overriding pkg-config
PHP_MONGODB_SSL_LIBS
linker flags for PHP_MONGODB_SSL, overriding pkg-config
PHP_MONGODB_UTF8PROC_CFLAGS
C compiler flags for PHP_MONGODB_UTF8PROC, overriding pkg-config
PHP_MONGODB_UTF8PROC_LIBS
linker flags for PHP_MONGODB_UTF8PROC, 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
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
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
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>.
5. 进入构建目录
# php7.4 构建目录
cd /home/php-fpm/php-7.4.33/build_php/
# php8.3 构建目录
cd /home/php-fpm/php-8.3.12/build_php/
6. 安装指令
构建指令参考
../configure --prefix=/server/php/83/ \
--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
构建指令区别:
php8.1 默认已经对 openssl 启用 pcre-jit
实现正则即时编译
php8.1 的 gd 扩展增加的 --with-avif
选项
php8.3 增加 --with-capstone
选项
7. 编译并安装
# nohup make -j2 &
make -j2
make test
make install
PHP 配置
php.ini
是 PHP 的配置文件,具体选项可以阅读 官方手册
1. 配置文件模板
php 编译完成后,在源码包根目录下会自动生成两个推荐的配置文件模版
- 开发环境推荐:
php.ini-development
- 部署环境推荐:
php.ini-production
2. 配置文件路径
通过下面的指令可以快速获取到 PHP 配置文件存放路径
# php7.4
/server/php/74/bin/php --ini
# php8.3
/server/php/83/bin/php --ini
# php7.4
/server/php/74/bin/php-config --ini-path
# php8.3
/server/php/83/bin/php-config --ini-path
3. 拷贝配置文件
# php7.4
cp /home/php-fpm/php-7.4.33/php.ini-production /server/php/74/lib/php.ini
# php8.3
cp /home/php-fpm/php-8.3.12/php.ini-production /server/php/83/lib/php.ini
# php7.4
cp /home/php-fpm/php-7.4.33/php.ini-development /server/php/74/lib/php.ini
# php8.3
cp /home/php-fpm/php-8.3.12/php.ini-development /server/php/83/lib/php.ini
4. 检测配置文件
使用 php 程序,快速检测配置文件使用加载成功
# php7.4
/server/php/74/bin/php --ini
# php8.3
/server/php/83/bin/php --ini
5. 开启 OPcache
PHP 官方明确说明 OPcache 只允许编译为共享扩展,并且默认会构建它
使用 --disable-opcache
选项可以禁止构建
开启方式
在
php.ini
第 953 行,将;
去掉inizend_extension=opcache
性能配置
在
php.ini
第 1796 行,加入以下内容,可获得较好性能ini# 检查脚本时间戳是否有更新的周期,以秒为单位 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/83/etc/php-fpm.conf
pid=/run/php83-fpm/process.pid
error_log=/server/logs/php/error-83.log
include=/server/php/83/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/83/etc/php-fpm.d/default.conf
[default] ;子进程名,通常与子进程配置文件命名相同
;主进程不以 ROOT 运行时 user、group 选项将被忽略
;user = php-fpm ;子进程用户,默认为 nobody
;group = php-fpm ;子进程用户组,默认为 nobody
;工作池进程对应的监听地址,可选 监听tcp端口 或 socket文件
;listen = /run/php83-fpm/default.sock ;监听socket文件.socket性能更好,只支持本地
listen = 127.0.0.1:9683 ;监听127.0.0.1上的9683端口,tcp高并发更好
;listen = 9683 ;监听所有网卡的9683端口
listen.backlog = -1 ;设置 listen 的最大值,-1表示无限制,默认值:-1
;设置允许连接的客户端(IPv4 或 IPv6 地址列表),默认值:未设置(接受任何 IP 地址)
listen.allowed_clients = 127.0.0.1,192.168.66.254
;仅支持监听对象是 unix 套接字
listen.owner = php-fpm ;子进程监听用户,默认为 nobody
listen.group = php-fpm ;子进程监听用户组,默认为 nobody
listen.mode = 0660 ;监听权限
;固定进程数
;pm = static ;设置进程管理器管理的子进程数量是固定的
;pm.max_children = 50 ;pm 设置为 static 时表示创建的子进程的数量,pm 设置为 dynamic 时表示最大可创建的子进程的数量
;pm.max_requests = 1000 ;设置每个子进程重生之前服务的请求数,对于可能存在内存泄漏的第三方模块来说是非常有用的
;动态进程数
pm = dynamic
pm.max_children = 50
pm.start_servers = 2 ;设置启动时创建的子进程数目(仅在 pm=dynamic 时使用)
pm.min_spare_servers = 1 ;设置空闲服务进程的最低数目(仅在 pm=dynamic 时使用)
pm.max_spare_servers = 3 ;设置空闲服务进程的最大数目(仅在 pm=dynamic 时使用)
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 项目专用工作池案例
;/server/php/83/etc/php-fpm.d/tp.conf
[tp6]
listen = 127.0.0.1:9610
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
TIP
更多参数说明,请阅读 PHP 手册
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/83/var/run/php-fpm.pid
ExecStart=/server/php/83/sbin/php-fpm --nodaemonize --fpm-config /server/php/83/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.3 FastCGI Process Manager
After=network.target
[Service]
Type=notify
User=php-fpm
Group=php-fpm
RuntimeDirectory=php83-fpm
RuntimeDirectoryMode=0750
ExecStart=/server/php/83/sbin/php-fpm --nodaemonize --fpm-config /server/php/83/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/php83-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 php83-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/83/bin
curl -O https://mirrors.tencent.com/composer/composer.phar
chmod 770 composer.phar
# 软链接到 /usr/local/bin
ln -s /server/php/83/bin/composer.phar /usr/local/bin/composer
更多国内镜像
当前腾讯云是最正常的
- 腾讯云:
composer config -g repos.packagist composer https://mirrors.cloud.tencent.com/composer/
- 阿里云:
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
- 华为云:
composer config -g repo.packagist composer https://repo.huaweicloud.com/repository/php/
2. 全量镜像
推荐全局配置阿里云的 Composer 全量镜像
# 切换到开发者用户
su emad
# 使用国内 Composer 全量镜像
/server/php/83/bin/php /usr/local/bin/composer config -g repo.packagist composer https://mirrors.cloud.tencent.com/composer/
# 取消使用国内 Composer 全量镜像
/server/php/83/bin/php /usr/local/bin/composer config -g --unset repos.packagist
3. 升级
升级 composer 也非常简单,建议使用国内全量镜像后再升级
# 切换到php-fpm用户,只能从root进入
su - php-fpm -s /bin/zsh
/server/php/83/bin/php /usr/local/bin/composer self-update
网页版数据库管理工具
将 adminer、phpMyAdmin、phpRedisAdmin 加入到默认站点
mv adminer-xxx.php /server/default/adminer.php
mv phpMyAdmin-xxx/ /server/default/pma
mv phpRedisAdmin-xxx/ /server/default/pra
1. adminer
adminer 使用 pdo 链接数据库,支持管理多种数据库,不需要额外配置
TIP
adminer 无需配置
将服务器上 sql 文件导入到数据库
- sql文件路径:文件必须和 adminer.php 在同级目录下
- sql文件名称:`adminer.sql` 或者 `adminer.sql.gz`
2. phpMyAdmin
phpMyAdmin 使用 mysqli 链接,支持管理 MariaDB、MySQL
TIP
phpMyAdmin 需要配置
details 新建配置文件
在 pma 根目录下新建 config.inc.php 文件
bashcd /server/default/pma/ vim config.inc.php
配置文件内容
php<?php # /server/default/pma/config.inc.php declare(strict_types=1); $cfg['blowfish_secret'] = 'qWgP3sMqaGff5VyFHWWX5NkD7swtTx6x'; // 新版本,只能是32位 $i = 0; $i++; $cfg['Servers'][$i]['auth_type'] = 'cookie'; $cfg['Servers'][$i]['host'] = '127.0.0.1'; $cfg['Servers'][$i]['compress'] = false; $cfg['Servers'][$i]['AllowNoPassword'] = false; $cfg['UploadDir'] = ''; $cfg['SaveDir'] = ''; $cfg['TempDir'] = '/tmp/'; $cfg['DefaultLang'] = 'zh_CN'; $cfg['ThemeDefault'] = 'original';
TIP
pma 的密文
$cfg['blowfish_secret']
参数需要重新设置pma 密文参数
$cfg['blowfish_secret']
参数用于设置 pma 密文,支持如下字符类型组合:- 数值:
0-9
- 大写字母:
A-Z
- 小写字母:
a-z
- ascii 特殊字符:
\~!@#$%^&*()_+-=[]{}\|;:'"/?.>,<
- 数值:
3. phpRedisAdmin
phpRedisAdmin 需要使用 composer 安装依赖后,才能正常使用
su emad
cd /server/default/pra/
composer install
警告
通常不使用 composer update
指令,它有可能导致程序依赖被破坏
对于任何线上项目,都应该尽可能减少使用 composer update
的次数
升级 PHP
升级 PHP 跟正常编译几乎一样,下面是注意事项:
安装依赖
- PHP 跨主版本更新,必须重新编译安装动态扩展;
- PHP 跨次版本更新,建议重新编译安装动态扩展;
- PHP 小版本更新,如果 PHP 并未修改动态扩展,就不用重新编译安装动态扩展。
重命名执行程序 执行
make install
之前,先将sbin/php-fpm
文件重命名,实现平滑升级bash# php8.3 mv /server/php/83/sbin/php-fpm{,.bak}
配置文件
php.ini
- 小版本升级,需要修改配置文件,除非遇到 PHP 非常特殊的情况,
- 其他版本升级,就直接替换掉配置文件,然后将需要的动态扩展重新加上去即可
警告
服务器升级 PHP 乃至任何软件升级前,都应该先存快照,备份一份
动态安装 PECL 扩展
在为项目增加功能的时候,可能需要额外的扩展支持,这时候我们不可避免要去安装动态扩展
而 PHP 官方显然也是考虑到这一点,所以动态安装这块也非常轻松
本次计划提供下面几个 PECL 扩展的动态安装案例:
1. imagick
imagick 需要先安装依赖库 ImageMagick
安装 ImageMagick
apt install libtool -y
# 如果 make check 没有报错,下面这些依赖可以不用安装
apt install libheif-dev liblcms2-dev libopenjp2-7-dev liblqr-1-0-dev libopenexr-dev libwmf-dev libpango1.0-dev libraw-dev libraqm-dev libdjvulibre-dev libzstd-dev -y
mkdir /server/ImageMagick
cd /home/php-fpm/ImageMagick-7.1.0-51/
./configure --prefix=/server/ImageMagick/
make
make check
make install
安装 Imagick 扩展
export PKG_CONFIG_PATH=/server/ImageMagick/lib/pkgconfig
cd /home/php-fpm/php_ext/imagick-3.7.0
phpize
# 构建指令
./configure \
--with-php-config=/server/php/83/bin/php-config \
# --with-php-config=/server/php/74/bin/php-config \
--with-imagick=/server/ImageMagick/
# 编译并安装
make
make test
make install
./configure
指令检查有报错
2. xdebug
xdebug 是 php 的断点调试工具
cd /home/php-fpm/php_ext/xdebug-3.3.2
phpize
./configure --enable-xdebug --with-php-config=/server/php/83/bin/php-config
# ./configure --enable-xdebug --with-php-config=/server/php/74/bin/php-config
make -j4 > make.log
make install
# /server/php/83/lib/php.ini
[xdebug]
zend_extension=xdebug
xdebug.mode=develop,trace,debug
xdebug.client_host=127.0.0.1
; xdebug.client_host=192.168.6.254
xdebug.client_port=9083
; xdebug.client_port=9074
同时使用 Xdebug 和 OPCache 时,zend_extension=xdebug
须在 zend_extension=opcache
下面:
zend_extension=opcache
zend_extension=xdebug
3. swoole
Swoole 是一个使用 C++ 语言编写的基于异步事件驱动和协程的并行网络通信引擎,为 PHP 提供协程、高性能网络编程支持
4. rdkafka
# 安装依赖库 librdkafka
apt install librdkafka-dev -y
# 安装 php-rdkafka 扩展
cd /home/php-fpm/php_ext/rdkafka-6.0.3
phpize
./configure --with-php-config=/server/php/83/bin/php-config
make -j2
make install
# /server/php/83/lib/php.ini
extension=rdkafka
5. MongoDB
在实际工作中 PostgreSQL 通常可以取代 MySQL 和 MongoDB
cd /home/php-fpm/php_ext/mongodb-1.19.2
phpize
./configure --enable-mongodb --with-php-config=/server/php/83/bin/php-config
make -j2
make test
make install
# /server/php/83/lib/php.ini
extension=mongodb
开启动态扩展
extension=imagick
extension=swoole
extension=mongodb
extension=rdkafka
即将移除的扩展
lnpp 里即将移除的扩展
- yaml 可使用
symfony/yaml
包替代 - rdkafka 有需求再安装动态扩展
- apcu 有需求再安装动态扩展
- redis 移除,考虑使用 Postgres 替代
- mongodb 移除,完全转到 Postgres
- mysql 移除,完全转到 Postgres
权限
chown php-fpm:php-fpm -R /server/php /server/logs/php
find /server/php /server/logs/php -type f -exec chmod 640 {} \;
find /server/php /server/logs/php -type d -exec chmod 750 {} \;
# 可执行文件需要执行权限
chmod 750 -R /server/php/83/bin /server/php/83/sbin
# 权限同部署环境
# 开发用户 emad 加入 lnpp包用户组
usermod -a -G sqlite,redis,postgres,mysql,php-fpm,nginx emad