CentOS7中编译PHP及开启JIT

实施过程

1、安装相关依赖
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel

2、下载并解压
建议查看官网release 版本
wget https://www.php.net/distributions/php-8.0.30.tar.gz
tar -zxvf php-8.0.30.tar.gz

3、预编译

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
./configure \
--with-config-file-path=/usr/local/php80/etc \
--with-config-file-scan-dir=/usr/local/php80/etc/php.d \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-curl \
--with-freetype-dir=/usr/local/freetype \
--enable-gd \
--enable-gd-jis-conv \
--with-gettext \
--with-iconv=/usr/local/libiconv \
--with-libxml-dir=/usr \
--with-kerberos \
--with-libdir=/usr/lib64 \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--enable-pdo \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-jpeg-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--with-bz2 \
--with-mhash \
--with-password-argon2 \
--with-sodium=/usr/local \
--disable-rpath \
--disable-fileinfo \
--disable-debug \
--enable-intl \
--enable-exif \
--enable-ftp \
--enable-cli \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-xml \
--enable-zip

如果看到以下提示信息,说明 configure 成功。

4、安装
sudo make && make install
到安装目录查看版本
/usr/local/php80/bin/php -v

5、编辑配置
复制 php.ini
cp php.ini-production /usr/local/php80/etc/php.ini
复制 php-fpm
cp /usr/local/php80/etc/php-fpm.conf.default /usr/local/php80/etc/php-fpm.conf
cp /usr/local/php80/etc/php-fpm.d/www.conf.default /usr/local/php80/etc/php-fpm.d/www.conf
修改 php-fpm 配置,在 php-fpm.conf 中开启 pid = run/php-fpm.pid 配置项

6、配置启动 php-fpm
复制 php-fpm 的启动脚本
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
授权执行权限
chmod +x /etc/init.d/php-fpm
启动 php-fpm
/etc/init.d/php-fpm start 或者service php-fpm start

7、开启 openche 和 JIT

1
2
3
4
5
6
7
8
9
10
11
12
13
zend_extension=/usr/local/php80/lib/php/extensions/no-debug-non-zts-20231015/opcache.so

[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=192
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000

***

opcache.jit=1205
opcache.jit_buffer_size=64M

记录问题

Q: 编译时候出现错误,configure: error: Please reinstall the iconv library.
没有安装 iconv 库,iconv –version

iconv (GNU libiconv 1.17)
Copyright (C) 2000-2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Bruno Haible.

下载并编译

1
2
3
4
5
6
7
8
9
10
11
wget https://ftp.gnu.org/gnu/libiconv/libiconv-1.17.tar.gz
tar -zxvf libiconv-1.17.tar.gz
cd ./libiconv-1.17
./configure --prefix=/usr/local/libiconv --enable-static --enable-shared
#--prefix 参数表示安装目录,默认为 /usr/local;--enable-static 和 --enable-shared 参数表示编译时同时生成静态和动态库文件。
make
sudo make install
echo "/usr/local/lib" > /etc/ld.so.conf.d/libiconv.conf
echo "/usr/local/libiconv/lib" > /etc/ld.so.conf.d/libiconv.conf
sudo ldconfig -v
sudo ldconfig

若还是出现问题,建议先--without-iconv再后面 make 的时候
make ZEND_EXTRA_LIBS='-liconv'

Q: 编译时候出现错误,configure: error: Package requirements (libsodium >= 1.0.8) were not met:
libsodium 版本低了直接上yum install libsodium libsodium-devel解决
不行的话可以继续手动编译

1
2
3
4
5
6
wget https://github.com/jedisct1/libsodium/releases/download/1.0.18-RELEASE/libsodium-1.0.18.tar.gz
tar -zxvf libsodium-1.0.18.tar.gz
cd libsodium-1.0.18
./configure CC="gcc -m64" --prefix=/usr/local/libsodium --libdir=/usr/lib64
sudo make
sudo make install

Q: 提示 OpenSSL 找不到 / libssl.so.1.1: cannot open shared object file: No such file or directory:
请果断升级 openssl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz
tar -xvf openssl-1.1.1w.tar.gz
cd openssl-1.1.1w
./config shared --openssldir=/usr/local/openssl --prefix=/usr/local/openssl
make && make install
echo "/usr/local/lib64/" >> /etc/ld.so.conf
ldconfig
openssl version
# 如果不行继续敲入
mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/lib/openssl /usr/lib/openssl.old
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
sudo ldconfig -v
sudo ldconfig
openssl version
# OpenSSL 1.1.1w 11 Sep 2023
作者

Catooilg

发布于

2023-10-15

更新于

2023-10-15

许可协议

评论