yum install centos-release-scl
yum install devtoolset-7
# 先装epel
yum install -y epel-release
# 直接rpm安装 centos-release-scl
rpm -ivh https://mirrors.aliyun.com/centos-vault/7.9.2009/extras/x86_64/Packages/centos-release-scl-2-3.el7.centos.noarch.rpm
rpm -ivh https://mirrors.aliyun.com/centos-vault/7.9.2009/extras/x86_64/Packages/centos-release-scl-rh-2-3.el7.centos.noarch.rpm
cat > /etc/yum.repos.d/CentOS-SCLo-vault.repo <<'EOF'
[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/sclo/x86_64/sclo/
gpgcheck=0
enabled=1
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/sclo/x86_64/rh/
gpgcheck=0
enabled=1
EOF
sudo wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz
sudo tar -zxf openssl-1.1.1w.tar.gz
cd openssl-1.1.1w
# 配置安装到独立目录,不覆盖系统默认版本
sudo ./config --prefix=/usr/local/openssl-1.1.1w --openssldir=/usr/local/openssl-1.1.1w shared zlib
sudo make -j$(nproc)
sudo make install
yum-config-manager --disable ol7_latest ol7_UEKR5
yum clean all && rm -rf /var/cache/yum/*
yum makecache
yum install -y devtoolset-7-gcc devtoolset-7-gcc-c++
# 只是当前shell临时启用高版本gcc,只在你编译PHP8.5的时候开启
scl enable devtoolset-7 bash
# 设置openssl的pkg-config路径
export PKG_CONFIG_PATH=/usr/local/openssl-1.1.1w/lib/pkgconfig:$PKG_CONFIG_PATH
gcc -v
yum install -y cmake3
cmake3 --version
wget https://download.gnome.org/sources/libxml2/2.9/libxml2-2.9.14.tar.xz
tar xf libxml2-2.9.14.tar.xz
cd libxml2-2.9.14
rm -rf Makefile *.o .libs
mkdir build && cd build
./configure --prefix=/usr/local/libxml2-2.9.14 --without-python
make -j$(nproc)
make install
wget https://libzip.org/download/libzip-1.4.0.tar.gz
tar zxf libzip-1.4.0.tar.gz
cd libzip-1.4.0
# 隔离编译,和之前一样
./configure --prefix=/usr/local/libzip1.4 --with-zlib=/usr/local/zlib1.2.13
make -j$(nproc)
make install
rm -rf libzip-1.3.0 libzip-1.4.0 libzip-1.9.2
wget https://github.com/nih-at/libzip/releases/download/v1.9.2/libzip-1.9.2.tar.gz
tar zxf libzip-1.9.2.tar.gz
cd libzip-1.9.2
mkdir build && cd build
cmake3 \
-DCMAKE_INSTALL_PREFIX=/usr/local/libzip1.9 \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_LIBDIR=lib \
-DENABLE_PKGCONFIG=ON \
-DZLIB_ROOT=/usr/local/zlib1.2.13 \
-DENABLE_BZIP2=OFF \
-DENABLE_LZMA=OFF \
-DENABLE_ZSTD=OFF \
..
make -j$(nproc)
make install
# 编译安装到独立目录
./configure --prefix=/usr/local/libxml2-2.9.14 --without-python
make -j$(nproc)
make install
wget https://www.zlib.net/fossils/zlib-1.2.13.tar.gz
tar zxf zlib-1.2.13.tar.gz
cd zlib-1.2.13
# 隔离安装到独立目录
./configure --prefix=/usr/local/zlib1.2.13
make -j$(nproc)
make install
wget https://curl.se/download/curl-7.81.0.tar.gz
tar zxf curl-7.81.0.tar.gz
cd curl-7.81.0
# 编译,指定独立目录,并且链接我们刚才单独编译的openssl1.1.1w
./configure --prefix=/usr/local/curl7.81 --with-openssl=/usr/local/openssl-1.1.1w --without-libidn2
make -j$(nproc)
make install
wget https://github.com/unicode-org/icu/releases/download/release-70-1/icu4c-70_1-src.tgz
tar zxf icu4c-70_1-src.tgz
cd /data/src/icu/source
make clean
rm -rf config.status Makefile
unset CFLAGS
unset LDFLAGS
# 关键:--enable-shared 强制编译动态库,--disable-static 不生成静态库
./runConfigureICU Linux --prefix=/usr/local/icu70 --with-pic --enable-shared --disable-static
make -j$(nproc) && make install
wget https://www.sqlite.org/2022/sqlite-autoconf-3400100.tar.gz
tar zxf sqlite-autoconf-3400100.tar.gz
cd sqlite-autoconf-3400100
./configure --prefix=/usr/local/sqlite3.40
make -j$(nproc)
make install
cd /data/src/php-8.5.12
make clean
rm -f Makefile
export PKG_CONFIG_PATH=/usr/local/sqlite3.40/lib/pkgconfig:/usr/local/libzip1.9/lib/pkgconfig:/usr/local/curl7.81/lib/pkgconfig:/usr/local/zlib1.2.13/lib/pkgconfig:/usr/local/libxml2-2.9.14/lib/pkgconfig:/usr/local/openssl-1.1.1w/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=/usr/local/sqlite3.40/lib:/usr/local/libzip1.9/lib:/usr/local/curl7.81/lib:/usr/local/zlib1.2.13/lib:/usr/local/libxml2-2.9.14/lib:/usr/local/openssl-1.1.1w/lib:$LD_LIBRARY_PATH
export CFLAGS="-fPIE"
export LDFLAGS="-pie"
pkg-config --modversion zlib libcurl icu-uc
yum install -y gcc gcc-c++ make cmake autoconf automake libtool bison re2c \
libxml2-devel libpng-devel libjpeg-turbo-devel freetype-devel \
curl-devel libzip-devel bzip2-devel oniguruma-devel readline-devel \
icu-devel
wget https://www.php.net/distributions/php-8.5.12.tar.gz
tar -xzvf php-8.5.12.tar.gz
cd php-8.5.12
./configure --help
make clean
rm -f Makefile
./configure \
--prefix=/data/php85 \
--with-config-file-path=/data/php85/etc \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-fpm \
--with-mysqli \
--with-pdo-mysql \
--with-gettext \
--enable-mbstring \
--disable-mbstring-optimization \
--with-iconv \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml=/usr/local/libxml2-2.9.14 \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl=/usr/local/curl7.81 \
--with-zlib=/usr/local/zlib1.2.13 \
--with-zip=/usr/local/libzip1.9 \
--with-bz2 \
--enable-gd \
--with-jpeg \
--with-freetype \
--enable-ftp \
--with-readline \
--with-sqlite3=/usr/local/sqlite3.40 \
--with-pdo-sqlite=/usr/local/sqlite3.40 \
--without-ldap
make && make install
cp php.ini-production /data/php85/etc/php.ini
//将源码文件中的php.ini-production移动到php配置文件夹下作为php的配置文件
cp /data/php85/etc/php-fpm.conf.default /data/php85/etc/php-fpm.conf
然后设置php.ini,使用:
vim /data/php85/etc/php.ini
打开php配置文件找到cgi.fix_pathinfo配置项,这一项默认被注释并且值为1,根据官方文档的说明,这里为了当文件不存在时,阻止Nginx将请求发送到后端的PHP-FPM模块,从而避免恶意脚本注入的攻击,所以此项应该去掉注释并设置为0
php_value[session.save_path] = "/data/www/tmp/php85"
date.timezone = "Asia/Shanghai"
max_execution_time = 60
upload_max_filesize = 80m
post_max_size = 80m
extension=ftp
short_open_tag = On
error_log = /data/php85/var/log/php-fpm.log
extension=redis.so
cp /data/php85/etc/php-fpm.d/www.conf.default /data/php85/etc/php-fpm.d/www.conf
vim /data/php85/etc/php-fpm.d/www.conf
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
;listen = 127.0.0.1:9000
改为
listen = /data/php85/var/run/socket
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
echo "/usr/local/libzip1.9/lib" > /etc/ld.so.conf.d/libzip.conf
ldconfig
ldconfig -p | grep libzip.so.5
# 写入服务文件
cat > /usr/lib/systemd/system/php-fpm85.service <<'EOF'
[Unit]
Description=PHP85-FPM
After=network.target
[Service]
Type=simple
Environment="LD_LIBRARY_PATH=/usr/local/libzip1.9/lib:/usr/local/curl/lib:/usr/local/zlib/lib:/usr/local/libxml2/lib:/usr/local/openssl-1.1.1w/lib"
ExecStart=/data/php85/sbin/php-fpm --nodaemonize --fpm-config /data/php85/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGQUIT $MAINPID
PrivateTmp=true
Restart=on-failure
RestartSec=3
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable php-fpm85.service
systemctl restart php-fpm85.service
lsof |grep /data/php85/var/run/socket
# 先装依赖
yum install libtool -y
# 下载源码
cd /data/src
wget https://pecl.php.net/get/redis-6.3.0.tgz
tar zxf redis-6.3.0.tgz
cd redis-6.3.0
# 用你php85的phpize
/data/php85/bin/phpize
./configure --with-php-config=/data/php85/bin/php-config
make -j$(nproc) && make install
/data/php85/bin/php -m | grep redis
cd /data/src
wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz
tar -zxf libevent-2.1.12-stable.tar.gz
cd libevent-2.1.12-stable
# 编译libevent,带 --with-pic
./configure --prefix=/usr/local/libevent21 --with-pic
make -j$(nproc) && make install
# 注册动态库
echo "/usr/local/libevent21/lib" > /etc/ld.so.conf.d/libevent21.conf
ldconfig
pkg-config --modversion libevent
pkg-config --cflags libevent
# 临时把新版libevent的pkgconfig加到最前面
export PKG_CONFIG_PATH=/usr/local/libevent21/lib/pkgconfig:$PKG_CONFIG_PATH
# 再验证
pkg-config --modversion libevent
正常这时应该输出 `2.1.12-stable`
>
> ?? 注意:这个 export 只对当前 shell 生效,新开终端会失效
cd /data/src
wget https://pecl.php.net/get/event-3.0.8.tgz
tar xf event-3.0.8.tgz
cd event-3.0.8
export PKG_CONFIG_PATH=/usr/local/libevent21/lib/pkgconfig:$PKG_CONFIG_PATH
/data/php85/bin/phpize
./configure --with-php-config=/data/php85/bin/php-config --with-libevent=/usr/local/libevent21
make -j$(nproc) && make install
php.ini 写入
extension=event.so
打赏

微信扫一扫,打赏作者吧~