• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
孙龙 程序员
少时总觉为人易,华年方知立业难
博客园    首页    新随笔    联系   管理    订阅  订阅

php重大安全漏洞安装补丁升级版本

php安全漏洞补丁升级

10月22日消息,两天前,代号 PHP2Shell 的两个 PHP 高危远程执行漏洞信息意外泄露,官方刚刚公开漏洞编号:CVE-2026-109618 和 CVE-2026-109619。

image

 

开始准备升级线上php版本为7.4.33 以前版本为7.2

#查看上线php版本的编译参数 ,之前php7.2编译的参数

[root@web-master conf]# /usr/local/php/bin/php-config
Usage: /usr/local/php/bin/php-config [OPTION]
Options:
  --prefix            [/usr/local/php]
  --includes          [-I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib]
  --ldflags           [ -L/usr/local/lib]
  --libs              [-lcrypt   -lresolv -lcrypt -lrt -lstdc++ -lrt -lm -ldl  -lxml2 -lssl -lcrypto -lsqlite3 -lz -lcurl -lxml2 -lssl -lcrypto -lz -lpng15 -ljpeg -lfreetype -licuio -licui18n -licuuc -licudata -lonig -lsqlite3 -lxml2 -lxml2 -lcrypt -lxml2 -lxml2 -lxml2 -lxml2 -lxslt -lz -ldl -lm -lxml2 -lexslt -lxslt -lz -lm -lgcrypt -ldl -lgpg-error -lxml2 -lzip -lbz2 -lz -lz -lssl -lcrypto -lcrypt ]
  --extension-dir     [/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902]
  --include-dir       [/usr/local/php/include/php]
  --man-dir           [/usr/local/php/php/man]
  --php-binary        [/usr/local/php/bin/php]
  --php-sapis         [ cli fpm phpdbg cgi]
  --ini-path          [/usr/local/php/etc]
  --ini-dir           [/usr/local/php/conf.d]
  --configure-options [--prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/conf.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype=/usr/local/freetype --with-jpeg --with-png --with-zlib --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-ftp --enable-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-zip --without-libzip --enable-soap --with-gettext --enable-opcache --with-xsl --with-pear PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:]
  --version           [7.4.21]
  --vernum            [70421]

#下载文件:

cd /data/opt/

wget https://www.php.net/distributions/php-7.4.33.tar.gz

tar zxf php-7.4.33.tar.gz

# 打补丁 到源码中 
php-7.4.33-php2shell.patch

[root@web-master php-7.4.33]# curl -L https://github.com/php/php-src/commit/712e60f9edfd03f0960fc4fc3c2c375f42b90aa2.diff -o php-7.4.33-php2shell.patch
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 40926  100 40926    0     0  35694      0  0:00:01  0:00:01 --:--:-- 35712
[root@web-master php-7.4.33]# patch -p1 < php-7.4.33-php2shell.patch
patching file Zend/zend_API.h
patching file Zend/zend_alloc.c
patching file Zend/zend_alloc.h
patching file Zend/zend_execute_API.c
patching file Zend/zend_hash.c
patching file Zend/zend_hash.h
patching file Zend/zend_llist.c
patching file Zend/zend_multiply.h
patching file Zend/zend_strtod.c
patching file Zend/zend_types.h
patching file Zend/zend_vm_def.h
patching file Zend/zend_vm_execute.h
patching file ext/session/session.c
patching file main/SAPI.c
patching file main/main.c
patching file main/php_variables.c
patching file main/rfc1867.c

#编译php源码

cd /data/opt/php-7.4.33

# 如果是手动编译的freetype,打开下面这行;yum安装的注释掉
export PKG_CONFIG_PATH=/usr/local/freetype/lib/pkgconfig:$PKG_CONFIG_PATH

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

./configure \
--prefix=/usr/local/php-7.4.33 \
--with-config-file-path=/usr/local/php-7.4.33/etc \
--with-config-file-scan-dir=/usr/local/php-7.4.33/conf.d \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv=/usr/local/libiconv \
--with-freetype \
--with-jpeg \
--with-png \
--with-zlib \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--enable-ftp \
--enable-gd \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--with-zip \
--without-libzip \
--enable-soap \
--with-gettext \
--enable-opcache \
--with-xsl \
--with-pear \
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:


make -j$(nproc)
make install



测试扩展是否成功

/usr/local/php-7.4.33/bin/php -r "var_dump(gd_info(), function_exists('imagettfbbox'));"

/usr/local/php-7.4.33/bin/php -r 'var_dump(ini_get("max_multipart_body_parts"));'



安装过程中可能会遇到验证无法打开问题 
/usr/local/php-7.4.33/bin/php -r "var_dump(gd_info(), function_exists('imagettfbbox'));"  false


--with-iconv=/usr/local/libiconv 
--with-freetype 





编译其他扩展:

cd /usr/local/soft
wget https://pecl.php.net/get/redis-5.3.7.tgz
tar zxf redis-5.3.7.tgz
cd redis-5.3.7

# 用你新编译好的7.4.33的phpize
/usr/local/php-7.4.33/bin/phpize

./configure --with-php-config=/usr/local/php-7.4.33/bin/php-config

make && make install



cd /usr/local/soft
wget https://pecl.php.net/get/mongodb-1.12.1.tgz
tar zxf mongodb-1.12.1.tgz
cd mongodb-1.12.1
/usr/local/php-7.4.33/bin/phpize
./configure --with-php-config=/usr/local/php-7.4.33/bin/php-config
make && make install




cd /usr/local/soft
wget https://pecl.php.net/get/amqp-1.10.0.tgz
tar zxf amqp-1.11.0.tgz
cd amqp-1.11.0
/usr/local/php-7.4.33/bin/phpize

# 重点:把rabbitmq-c的pkgconfig目录传给环境变量
export PKG_CONFIG_PATH=/usr/local/rabbitmq-c/lib64/pkgconfig:$PKG_CONFIG_PATH

./configure --with-php-config=/usr/local/php-7.4.33/bin/php-config
make && make install


安装报错
yum install -y epel-release
yum install -y librabbitmq librabbitmq-devel

pkg-config --modversion librabbitmq




# 查看单个扩展详情(推荐)
/usr/local/php-7.4.33/bin/php --ri redis
/usr/local/php-7.4.33/bin/php --ri mongodb
/usr/local/php-7.4.33/bin/php --ri amqp


/usr/local/php-7.4.33/bin/php -m | grep -E 'redis|mongodb|amqp'





代码小测试脚本(验证扩展函数可用,不是只加载 so)
新建 test_ext.php
<?php
echo "==== redis ====\n";
var_dump(extension_loaded('redis'));

echo "\n==== mongodb ====\n";
var_dump(extension_loaded('mongodb'));

echo "\n==== amqp ====\n";
var_dump(extension_loaded('amqp'));

/usr/local/php-7.4.33/bin/php test_ext.php

准备配置文件/usr/local/php-7.4.33/etc

php.ini

添加

memory_limit = -1
session.upload_progress.enabled = Off

[HP]
engine = On
short_open_tag = On
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = -1
disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
disable_classes =
zend.enable_gc = On
zend.exception_ignore_args = On
expose_php = On
max_execution_time = 300
max_input_time = 60
max_input_vars = 30000
memory_limit = -1
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = On
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 50M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
enable_dl = Off
cgi.fix_pathinfo=0
file_uploads = On
upload_max_filesize = 50M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[CLI Server]
cli_server.color = On
[Date]
date.timezone = PRC
[filter]
[iconv]
[imap]
[intl]
[sqlite3]
[Pcre]
[Pdo]
[Pdo_mysql]
pdo_mysql.default_socket=
[Phar]
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
[OCI8]
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.cookie_samesite =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.sid_length = 26
session.trans_sid_tags = "a=href,area=href,frame=src,form="
session.sid_bits_per_character = 5
session.upload_progress.enabled = Off
[Assertion]
zend.assertions = -1
[COM]
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[dba]
[opcache]
[curl]
extension="redis.so"
extension="amqp.so"
extension="mongodb.so"
[openssl]
[ffi]
php.ini

php-fpm.conf

[root@web-master etc]# cat php-fpm.conf
[global]
pid = /usr/local/php-7.4.33/var/run/php-fpm.pid
error_log = /usr/local/php-7.4.33/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi-7.4.33.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 80
pm.start_servers = 40
pm.min_spare_servers = 40
pm.max_spare_servers = 80
pm.max_requests = 1024
pm.process_idle_timeout = 10s
request_terminate_timeout = 100
request_slowlog_timeout = 5
slowlog = var/log/php7.4.33.slow.log
php-fpm.conf

etc/init.d/php-fpm74启动文件

[root@web-master etc]# cat /etc/init.d/php-fpm74 
#!/bin/sh
# chkconfig: - 85 15
# description: php-fpm74

prefix=/usr/local/php-7.4.33
exec=${prefix}/sbin/php-fpm
pid=${prefix}/var/run/php-fpm.pid

case "$1" in
    start)
        if [ -f $pid ];then
            echo "$pid exists, already running"
        else
            $exec
            echo "php-fpm74 start ok"
        fi
        ;;
    stop)
        if [ -f $pid ];then
            kill -QUIT `cat $pid`
            rm -f $pid
            echo "php-fpm74 stop ok"
        else
            echo "pid file not found"
        fi
        ;;
    restart)
        $0 stop
        sleep 1
        $0 start
        ;;
    reload)
        if [ -f $pid ];then
            kill -USR2 `cat $pid`
            echo "reload ok"
        fi
        ;;
    status)
        if [ -f $pid ];then
            echo "php-fpm74 is running"
        else
            echo "php-fpm74 stopped"
        fi
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac
exit 0
php-fpm74

/etc/init.d/php-fpm74 restart

最后修改nginx配置

[root@web-master conf]# vim enable-php-pathinfo.conf

        location ~ [^/]\.php(/|$)
        {
            fastcgi_pass  unix:/tmp/php-cgi-7.4.33.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
            include pathinfo.conf;
        }

如果 /usr/local/php7.4/bin/php -r 'var_dump(ini_get("max_multipart_body_parts"));' 不等于false,就说明补丁包编译成功了

 

image

 

 

 

 

本文来自博客园,作者:孙龙-程序员,转载请注明原文链接:https://www.cnblogs.com/sunlong88/p/23411057

posted on 2026-10-23 11:05  孙龙-程序员  阅读(33)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3