Apache一键源码编译安装脚本(CentOS7、8)

发布时间 2024-01-09 09:57:19作者: 潇瀚

测试环境
CentOS7.9.2009、 CentOS8.5.2111

#!/bin/bash
  
# install httpd scripts
# 将apache版本号定义为变量
VER=2.4.58

# 先安装必要的工具, 其中bzip2和gzip用于解压源码包, 如果源码包下载的是bz2,只安装bzip2即可;如果源码包是gzip压缩的,只安装gzip即可
# 如果是CentOS7,不需要安装redhat-rpm-config-125-1.el8.noarch
yum -y install wget gcc make bzip2 gzip apr-devel apr-util-devel  pcre-devel redhat-rpm-config-125-1.el8.noarch

wget https://dlcdn.apache.org/httpd/httpd-${VER}.tar.bz2 --no-check-certificate
# 可能由于网络原因,下载会失败,可以再添加判断下载成功的代码
tar -xjvf httpd-${VER}.tar.bz2
cd httpd-${VER}/

# 最简单的configure, 如果要添加其他功能,指定参数即可
./configure --prefix=/usr/local/httpd
make -j2 && make install
groupadd -r -g 88 apache
useradd -u 88 -g apache -s /sbin/nologin -d /var/www apache

# 使用sed修改用户和组信息
sed -i -e '/^User/c User apache' -e '/^Group/c Group apache' /usr/local/httpd/conf/httpd.conf
echo 'PATH=/usr/local/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
. /etc/profile.d/httpd.sh

# 启动apache
apachectl start