编译安装http2.4,实现可以正常访问

发布时间 2023-10-07 14:02:30作者: 小糊涂90
#1 安装相关包
[15:51:32 root@centos8 ~]#dnf install gcc make autoconf apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config -y

#2 下载并解压包
[15:53:11 root@centos8 ~]#wget https://archive.apache.org/dist/httpd/httpd-2.4.46.tar.bz2
[15:55:34 root@centos8 ~]#tar -xvf httpd-2.4.46.tar.bz2 -C /usr/local/src/

#3 配置
[15:56:37 root@centos8 src]#cd /usr/local/src/httpd-2.4.46/
[16:00:04 root@centos8 httpd-2.4.46]#./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd --enable-ssl

#4 编译并安装
[16:00:39 root@centos8 httpd-2.4.46]#make -j 2 && make install

#5 配置环境变量
[16:03:25 root@centos8 httpd-2.4.46]#echo 'PATH=/apps/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
[16:03:50 root@centos8 httpd-2.4.46]#. /etc/profile.d/httpd.sh

#6 启动
[16:03:58 root@centos8 httpd-2.4.46]#apachectl start

#7 指定apache用户运行
[16:04:16 root@centos8 httpd-2.4.46]#useradd -r -s /sbin/nologin -d /var/www -c Apache -u 48 apache
[16:04:38 root@centos8 httpd-2.4.46]#vim /etc/httpd/httpd.conf
User apache
Group apache

#8 配置生效
[16:08:51 root@centos8 httpd-2.4.46]#apachectl restart
[16:09:06 root@centos8 httpd-2.4.46]#ps aux |grep apache
apache    119719  0.0  0.3 1339488 7688 ?       Sl   16:08   0:00 /apps/httpd/bin/httpd -k start
apache    119720  0.0  0.4 1339488 9728 ?       Sl   16:08   0:00 /apps/httpd/bin/httpd -k start
apache    119721  0.0  0.6 1339488 13808 ?       Sl   16:08   0:00 /apps/httpd/bin/httpd -k start

#9 验证网页
[16:09:10 root@centos8 httpd-2.4.46]#curl localhost
<html><body><h1>It works!</h1></body></html>