安装依赖:
yum install gcc expat-devel openssl-devel pcre pcre-devel libxm12-devel libtool
额外依赖:安装包放在/usr/local/src
cd /usr/local/src
mkdir /usr/local/dependence #新建依赖文件夹
1.apr-1.7.0:
cd /usr/local/src
wget https://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz
tar -zxvf apr-1.7.0.tar.gz
编译安装:
cd apr-1.7.0
./configure --prefix=/usr/local/dependence/apr # 我的编译安装地址
make
make install
如果报错:rm: cannot remove `libtoolT': No such file or directory
在configure里面 把RM='$RM'改为RM='$RM -f' 即可
2.apr-util-1.6.1:
cd /usr/local/src
wget https://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
编译安装:
cd apr-util-1.6.1
./configure --prefix=/usr/local/dependence/apr-util --with-apr=/usr/local/dependence/apr #我的编译安装地址
make
make install
如果上述两个链接失效,那么进官网查看最新版本 :https://apr.apache.org/download.cgi
下载Apache源码:官网地址:https://httpd.apache.org/download.cgi#apache24
cd /usr/local/src
wget https://mirror.bit.edu.cn/apache//httpd/httpd-2.4.43.tar.gz
tar -zxvf httpd-2.4.43.tar.gz
我下载的地址为 /usr/local/src
进行编译安装:注意--with-apr=路径(为你安装apr的路径)
cd httpd-2.4.43
./configure --prefix=/usr/local/apache/ --with-apr=/usr/local/dependence/apr/ --with-apr-util=/usr/local/dependence/apr-util/ --enable-so --enable-ssl --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support
make
make install
进入Apache下的bin目录
cd /usr/local/apache/bin
打开httpd服务
./apachectl start
如果报错:
去/usr/local/apache/conf文件下 修改配置文件,为其添加域名即可
cd /usr/local/apache/conf
vim httpd.conf
再次启动
使用systemctl进行控制httpd服务
1.找到apachectl所在文件路径
find / -name apachectl
2.将其拷贝到/etc/rc.d/init.d目录下,并且重新命名为httpd (服务名称)
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
3.在相应的启动级别如3,5中加入链接
ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S61httpd
4.修改配置文件httpd,在#!/bin/sh下面添加两行
cd /etc/rc.d/init.d
vim httpd
5.保存后执行
chkconfig --add httpd
如果报错error reading information on service httpd : No such file or directory
chkconfig httpd on
6.查看系统服务
chkconfig --list
7.使用systemctl控制httpd服务
(1)查看状态
systemctl status httpd
(2)停止服务
systemctl stop httpd
(3)启动服务
systemctl start httpd
(4)重启服务
systemctl restart httpd