apache2.4脚本一键安装(linux环境)

1.下载apache安装包和相关组件

下载地址:https://pan.baidu.com/s/1o85i6Jw

其中包括

apache安装包:httpd-2.4.29.tar.gz

apache安装所需其他模块:apr-1.6.3.tar.gz、apr-util-1.6.1.tar.gz、pcre-8.41.tar.gz

apache一键安装脚本:install_apache24.sh

2.安装准备

root身份登录,创建安装文件上传目录

# mkdir /installpkgs

上传以上下载的5个文件至该目录( /installpkgs)下 

3.执行脚本

# cd /installpkgs

# chmod  755  install_apache24.sh

# sh install_apache24.sh

 执行过程中会有3次yum下载安装其他软件 输入"y"回车即可

4.结果演示

执行完安装之后,确定防火墙已关闭或已开放80端口

关闭防火墙:

此次生效:# service iptables stop

重启后生效:# chkconfig iptables off

输入ip地址可以看到如下界面,说明apache安装成功,脚本就是这么几步,不然正常安装可能提示少了这些哪些模块什么的(apache2.4版本的没集成apr、apr-util、pcre模块,需要另行下载)

附:脚本说明

#!/bin/bash
#apr安装
tar -xvf /installpkgs/apr-1.6.3.tar.gz -C /installpkgs
cd /installpkgs/apr-1.6.3
./configure --prefix=/usr/local/apache2/installmodules/apr
make && make install

#apr-util安装
yum install expat-devel
tar -xvf /installpkgs/apr-util-1.6.1.tar.gz -C /installpkgs
cd /installpkgs/apr-util-1.6.1
./configure --prefix=/usr/local/apache2/installmodules/apr-util --with-apr=/usr/local/apache2/installmodules/apr
make && make install

#pcre安装
yum install -y gcc gcc-c++
tar -xvf /installpkgs/pcre-8.41.tar.gz -C /installpkgs
cd /installpkgs/pcre-8.41
./configure --prefix=/usr/local/apache2/installmodules/pcre
make && make install

#mod_ssl
yum install openssl-devel

#httpd安装
tar -xvf /installpkgs/httpd-2.4.29.tar.gz -C /installpkgs
cd /installpkgs/httpd-2.4.29
./configure 
--prefix=/usr/local/apache2      #apache安装目录
--sysconfdir=/etc/httpd24        #apache配置文件目录
--enable-so 
--enable-ssl 
--enable-cgi 
--enable-rewrite 
--with-zlib 
--with-pcre=/usr/local/apache2/installmodules/pcre 
--with-apr=/usr/local/apache2/installmodules/apr 
--with-apr-util=/usr/local/apache2/installmodules/apr-util 
--enable-modules=most 
--enable-mpms-shared=all 
--with-mpm=prefork
make && make install

#修改ServerName
if ! grep "ServerName localhost:80" /etc/httpd24/httpd.conf
then
echo "ServerName localhost:80" >> /etc/httpd24/httpd.conf
fi

#apache服务启动
/usr/local/apache2/bin/apachectl -k start
原文地址:https://www.cnblogs.com/haoxianrui/p/8017652.html