在这之前,我写过一篇《基于 CentOS7 制作 Apache HTTPD 2.4.63 的RPM安装包》的文章,还有一篇《基于BCLinux制作Apache HTTPD 2.4.63 的RPM安装包》,本文大部分内容和之前差不多,但因为操作系统由CentOS 7变成了Rocky Linux,所以,有些内容就删减了,只记录遇到的问题。
编译环境:
操作系统:Rocky Linux 9.5
httpd版本:2.4.66
制作工具:rpmbuild(这个之前的文章有介绍,看这里)
下载httpd源码:
官网目前的最新版本是2.4.66(2025-12-04发布),下载备用,并放入准备好的编译机器上。
检查环境:
在制作RPM包之前,先检查下本地环境是否已准备好,比如,GCC。输入以下命令查看:
bash
gcc -v
如果提示找不到命令等错误信息,那么需要先安装gcc,命令如下:
bash
yum install -y gcc
制作RPM包
找到安装包的位置,然后使用如下命令,即可开始制作RPM包:
bash
rpmbuild -tb httpd-2.4.66.tar.bz2
如果没有预先按照它所依赖的那些包,则会报相应的错误。比如,如下错误信息:
bash
[root@localhost SOURCES]# rpmbuild -tb httpd-2.4.66.tar.bz2
warning: line 19: It's not recommended to have unversioned Obsoletes: Obsoletes: httpd-suexec
warning: line 34: It's not recommended to have unversioned Obsoletes: Obsoletes: secureweb-devel, apache-devel
warning: line 51: It's not recommended to have unversioned Obsoletes: Obsoletes: secureweb-manual, apache-manual
error: Failed build dependencies:
apr-devel >= 1.4.0 is needed by httpd-2.4.66-1.x86_64
apr-util-devel >= 1.4.0 is needed by httpd-2.4.66-1.x86_64
autoconf is needed by httpd-2.4.66-1.x86_64
libuuid-devel is needed by httpd-2.4.66-1.x86_64
libxml2-devel is needed by httpd-2.4.66-1.x86_64
lua-devel is needed by httpd-2.4.66-1.x86_64
openldap-devel is needed by httpd-2.4.66-1.x86_64
pcre-devel >= 5.0 is needed by httpd-2.4.66-1.x86_64
缺少好些devel包,通过yum将他们都安装上:
bash
yum install -y apr-devel apr-util-devel pcre-devel openldap-devel libxml2-devel libuuid-devel autoconf
依赖包装好后,重新执行:
bash
rpmbuild -tb httpd-2.4.66.tar.bz2
还有错误:
bash
[root@localhost SOURCES]# rpmbuild -tb httpd-2.4.66.tar.bz2
warning: line 19: It's not recommended to have unversioned Obsoletes: Obsoletes: httpd-suexec
warning: line 34: It's not recommended to have unversioned Obsoletes: Obsoletes: secureweb-devel, apache-devel
warning: line 51: It's not recommended to have unversioned Obsoletes: Obsoletes: secureweb-manual, apache-manual
error: Failed build dependencies:
lua-devel is needed by httpd-2.4.66-1.x86_64
提示还缺少lua-devel,那我再装一遍:
bash
[root@localhost SOURCES]# yum install -y lua-devel
Last metadata expiration check: 0:02:12 ago on Tue 10 Feb 2026 02:23:47 PM CST.
No match for argument: lua-devel
Error: Unable to find a match: lua-devel
不行,根本装不了,那用这个命令查看一下仓库里面是否有这个rpm:
bash
[root@localhost SOURCES]# yum search lua | grep devel
Last metadata expiration check: 0:09:47 ago on Tue 10 Feb 2026 02:23:47 PM CST.
yum仓库里面都没有lua-devel?那我们换个思路来装,可以去网上找到CentOS 9的lua-devel,lua-devel又依赖lua和lua-lib。所以,我们最终需要把 CentOS 9 下的lua,lua-lib,lua-devel通过本地安装的方式装上。但,今天我们不用手动下载来安装依赖,我们换另外一种方式,输入如下命令:
bash
[root@localhost SOURCES]# dnf config-manager --set-enabled crb
[root@localhost SOURCES]# dnf makecache
然后再查一遍仓库是不是有了lua-devel:
bash
[root@localhost SOURCES]# yum search lua | grep devel
Last metadata expiration check: 0:00:21 ago on Tue 10 Feb 2026 02:34:50 PM CST.
lua-devel.i686 : Development files for lua
lua-devel.x86_64 : Development files for lua
还真有,既然都查出来了,那就安装吧:
bash
yum install -y lua-devel
装好之后,再次执行打包命令:
bash
rpmbuild -tb httpd-2.4.66.tar.bz2
如果没有其他问题,那应该就可以打包成功了。
安装httpd.rpm
由于rocky系统自带了httpd 2.4.62版本,所以我们可以使用升级的方式,将刚才打包成功的rpm进行安装,命令如下:
bash
[root@localhost httpd_2.4.66]# rpm -Uvh httpd-2.4.66-1.x86_64.rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
file /etc/httpd/conf/httpd.conf from install of httpd-2.4.66-1.x86_64 conflicts with file from package httpd-core-2.4.62-4.el9.x86_64
file /etc/httpd/conf/magic from install of httpd-2.4.66-1.x86_64 conflicts with file from package httpd-core-2.4.62-4.el9.x86_64
file /etc/httpd/run from install of httpd-2.4.66-1.x86_64 conflicts with file from package httpd-core-2.4.62-4.el9.x86_64
...
...
从上面的信息可看出,升级失败。经过一番折腾,还是不行,最后只能使出大招了:
bash
rpm -Uvh --replacefiles --replacepkgs *.rpm --nodeps
注意这里的*.rpm,是将刚才打包出来的所有与httpd有关的rpm都装上。然后使用了--nodeps,如果不加这个,就会因为依赖的原因导致老是安装失败。