安装前准备:关闭防火墙和selinux
1.安装相关的包
[root@y_zilong ~]# yum install -y gcc make autoconf apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config
2.下载并解压包
[root@y_zilong ~]# wget https://mirrors.bfsu.edu.cn/apache//httpd/httpd-2.4.46.tar.gz
3.配置
[root@y_zilong ~]# tar xvf httpd-2.4.46.tar.gz -C /usr/local/src
4.编译并安装
[root@y_zilong ~]# cd /usr/local/src/httpd-2.4.46/
[root@y_zilong httpd-2.4.46]# ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd --enable--ssl
[root@y_zilong httpd-2.4.46]# make && make install
5.配置环境
[root@y_zilong httpd-2.4.46]# echo 'PATH=/apps/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
[root@y_zilong httpd-2.4.46]# . /etc/profile.d/httpd.sh
6.运行
[root@y_zilong httpd-2.4.46]#apache start
7.指定用apache用户运行
[root@y_zilong httpd-2.4.46]# useradd -r -s /sbin/nologin -d /var/www -c Apache -u 48 apache
[root@y_zilong ~]# vi /etc/httpd/httpd.conf
更改用户和组
User apache
Group apache
8.配置生效和验证
[root@y_zilong ~]# apachectl restart
9.查看进程和版本
[root@y_zilong ~]# ps -aux
apache 21759 0.0 0.0 456056 4440 ? Sl 05:13 0:00 /apps/httpd/bin/httpd -k restart
apache 21760 0.0 0.0 456056 4448 ? Sl 05:13 0:00 /apps/httpd/bin/httpd -k restart
apache 21761 0.0 0.0 456056 4452 ? Sl 05:13 0:00 /apps/httpd/bin/httpd -k restart
[root@y_zilong ~]# apachectl -v
Server version: Apache/2.4.46 (Unix)
Server built: Apr 8 2021 05:09:02
[root@y_zilong ~]#
10.用浏览器打开IP地址,会出现It works!