一、备份原始httpd配置文件
**主要是httpd.conf文件,如果conf.d目录下有配置文件也需要备份**
[root@loaclhost ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: May 30 2023 14:01:11
[root@loaclhost ~]# mkdir apache_bak
[root@loaclhost ~]# cd /etc/httpd/conf
[root@loaclhost conf]# cp httpd.conf /root/apache_bak/
二、停止并卸载原始httpd服务
我这边是yum(rpm)安装的
[root@loaclhost conf]# systemctl stop httpd
[root@loaclhost conf]# rpm -qa | grep http
httpd-tools-2.4.6-99.el7.centos.1.x86_64
httpd-2.4.6-99.el7.centos.1.x86_64
[root@loaclhost conf]#
[root@loaclhost conf]# rpm -e `rpm -qa | grep http`
warning: /etc/httpd/conf/httpd.conf saved as /etc/httpd/conf/httpd.conf.rpmsave
[root@loaclhost conf]#
三、上传新版httpd安装包并安装
[root@loaclhost ~]# ll httpd_2.4.57_rpm_all.tar.gz
-rw-r--r-- 1 root root 9992002 Jan 15 17:13 httpd_2.4.57_rpm_all.tar.gz
[root@loaclhost ~]# tar -xf httpd_2.4.57_rpm_all.tar.gz
[root@loaclhost ~]#
[root@loaclhost ~]# cd httpd_2.4.57
[root@loaclhost httpd_2.4.57]#
[root@loaclhost httpd_2.4.57]# ll
total 10020
-rw-r--r-- 1 root root 1426560 Jul 27 2023 httpd-2.4.57-1.x86_64.rpm
-rw-r--r-- 1 root root 3889892 Jul 27 2023 httpd-debuginfo-2.4.57-1.x86_64.rpm
-rw-r--r-- 1 root root 211468 Jul 27 2023 httpd-devel-2.4.57-1.x86_64.rpm
-rw-r--r-- 1 root root 4411732 Jul 27 2023 httpd-manual-2.4.57-1.x86_64.rpm
-rw-r--r-- 1 root root 80600 Jul 27 2023 httpd-tools-2.4.57-1.x86_64.rpm
-rw-r--r-- 1 root root 48312 Jul 27 2023 mod_authnz_ldap-2.4.57-1.x86_64.rpm
-rw-r--r-- 1 root root 48328 Jul 27 2023 mod_lua-2.4.57-1.x86_64.rpm
-rw-r--r-- 1 root root 25260 Jul 27 2023 mod_proxy_html-2.4.57-1.x86_64.rpm
-rw-r--r-- 1 root root 99016 Jul 27 2023 mod_ssl-2.4.57-1.x86_64.rpm
[root@loaclhost httpd_2.4.57]#
[root@loaclhost httpd_2.4.57]# rpm -ivh *.rpm --nodeps
Preparing... ################################# [100%]
Updating / installing...
1:httpd-2.4.57-1 ################################# [ 11%]
2:httpd-devel-2.4.57-1 ################################# [ 22%]
3:httpd-manual-2.4.57-1 ################################# [ 33%]
4:mod_authnz_ldap-2.4.57-1 ################################# [ 44%]
5:mod_lua-2.4.57-1 ################################# [ 56%]
6:mod_proxy_html-1:2.4.57-1 ################################# [ 67%]
7:mod_ssl-1:2.4.57-1 ################################# [ 78%]
8:httpd-tools-2.4.57-1 ################################# [ 89%]
9:httpd-debuginfo-2.4.57-1 ################################# [100%]
[root@loaclhost httpd_2.4.57]#
四、先启动httpd,查看版本
这边已升级到2.4.57版本
[root@loaclhost httpd_2.4.57]# systemctl start httpd
[root@loaclhost httpd_2.4.57]#
[root@loaclhost httpd_2.4.57]# httpd -v
Server version: Apache/2.4.57 (Unix)
Server built: Jul 27 2023 16:50:18
[root@loaclhost httpd_2.4.57]#
五、还原配置文件
建议先把新版httpd的http.conf文件备份一下,防止版本差异配置文件不一样导致无法启动
[root@loaclhost conf]# cp httpd.conf httpd.conf.bak
[root@loaclhost conf]# rm -rf httpd.conf
[root@loaclhost conf]# cp /root/apache_bak/httpd.conf .
[root@loaclhost conf]# systemctl restart httpd