从 Git 仓库代码安装 PHP-FPM 7.4.4

如何编译 PHP-FPM 其实很多人的博客都有,在此只是做一个记录,方便自己查找。

这里的编译选项应该是最全的了。由于都是套路,所以也不做解释了。只提两点:

  • 如果 PathInfo 编译错误,是内存不足的原因。
  • 要安装 snmp,才能使用 snmp 扩展,否则 PHP 程序会报错。(即使没有调用 snmp 函数)

安装依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
sudo apt-get install unzip snmp \
autoconf build-essential bison re2c \
libxml2-dev \
libsqlite3-dev \
libsystemd-dev \
libkrb5-dev \
libssl-dev \
libbz2-dev \
libcurl4-openssl-dev \
libenchant-dev \
libffi-dev \
libsodium-dev \
libpng-dev \
libwebp-dev \
libjpeg-dev \
libxpm-dev \
libfreetype6-dev \
libgmp-dev \
libc-client-dev \
libldap2-dev \
libsasl2-dev \
libonig-dev \
libpq-dev \
libpspell-dev \
libreadline-dev \
libsnmp-dev \
libargon2-0-dev \
libmhash-dev \
libtidy-dev \
libxslt1-dev \
libzip-dev \
-o Acquire::http::proxy="http://127.0.0.1:1081/"

最后一行是用来挂代理加速的,一般不用加。

获取代码(从 GitHub,有新版自己找新版)

1
2
wget https://github.com/php/php-src/archive/php-7.4.4.zip
unzip php-7.4.4.zip

Configure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
cd php-src-php-7.4.4
./buildconf --force

./configure \
--prefix=/usr/local \
--sysconfdir=/etc/php \
--localstatedir=/var/php \
--runstatedir=/run/php \
--enable-phpdbg \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--with-fpm-systemd \
--enable-fpm \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pgsql \
--with-pdo-pgsql \
--with-pdo-sqlite \
--enable-intl \
--enable-gd \
--enable-dba \
--with-jpeg \
--with-webp \
--with-freetype \
--with-xpm \
--enable-exif \
--with-zip \
--with-zlib \
--enable-soap \
--enable-xmlreader \
--with-xsl \
--with-tidy \
--with-xmlrpc \
--enable-magic-quotes \
--enable-sysvsem \
--enable-sysvshm \
--enable-shmop \
--enable-pcntl \
--with-readline \
--enable-mbstring \
--with-curl \
--with-gettext \
--enable-sockets \
--with-bz2 \
--with-openssl \
--with-gmp \
--enable-bcmath \
--enable-calendar \
--enable-ftp \
--with-pspell \
--with-enchant= \
--with-imap \
--with-imap-ssl \
--with-kerberos \
--enable-sysvmsg \
--with-ffi \
--with-sodium \
--with-ldap \
--with-ldap-sasl \
--with-password-argon2 \
--with-mhash \
--with-pear \
--with-snmp \
--with-config-file-path=/etc/php \
--with-config-file-scan-dir=/etc/php/php.conf.d

编译选项是从 PHP CI 源码里翻的,应该 PHP 自带的扩展都全了。

安装

下面其实不用多说了

1
2
3
make -j4
make test
make install

清理工作

清理 dev 包:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
sudo apt-get --purge remove \
libxml2-dev \
libsqlite3-dev \
libsystemd-dev \
libkrb5-dev \
libssl-dev \
libbz2-dev \
libcurl4-openssl-dev \
libenchant-dev \
libffi-dev \
libsodium-dev \
libpng-dev \
libwebp-dev \
libjpeg-dev \
libxpm-dev \
libfreetype6-dev \
libgmp-dev \
libc-client-dev \
libldap2-dev \
libsasl2-dev \
libonig-dev \
libpq-dev \
libpspell-dev \
libreadline-dev \
libsnmp-dev \
libargon2-0-dev \
libmhash-dev \
libtidy-dev \
libxslt1-dev \
libzip-dev

删除编译工具并清理缓存:

1
2
3
sudo apt-get --purge remove autoconf build-essential bison re2c \
&& sudo apt-get autoremove \
&& sudo apt-get autoclean

将 dev 依赖改为非 dev 依赖:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
sudo apt-get install \
aspell \
dictionaries-common \
emacsen-common \
enchant \
libaspell15 \
libc-client2007e \
libenchant1c2a \
libfreetype6 \
libgmpxx4ldbl \
libgraphite2-3 \
libgssrpc4 \
libharfbuzz-gobject0 \
libharfbuzz-icu0 \
libharfbuzz0b \
libhunspell-1.3-0 \
libjpeg-turbo8 \
libjpeg8 \
libkadm5clnt-mit9 \
libkadm5srv-mit9 \
libkdb5-8 \
libmhash2 \
libonig2 \
libpcre16-3 \
libpcre32-3 \
libpcrecpp0v5 \
libpng12-0 \
libpq5 \
libsodium18 \
libtidy-0.99-0 \
libwebp5 \
libwebpdemux1 \
libwebpmux1 \
libxpm4 \
libzip4 \
libcurl3

分享文章

链接
HTML
Markdown