apache一键安装脚本

最近在玩apache,首先安装apace要配置apr,apr-util,pcre,而配置这些基本都是千篇一律。所谓程序员的精神就是减少重复性的劳动,下面请看我写的apache安装脚本:
这个脚本我也放到我的github上

#!/bin/bash
# 需要sudo执行

dir=`pwd`

#要安装pcre先要安装 g++
if [[ `ls /etc|grep redhat-release` != "" ]]
then
    yum -y install gcc gcc-c++
elif [[ `ls /etc|grep debian_version` != "" ]]
then
    apt-get -y install gcc gcc-c++
fi

if [[ `ls|grep apr` == "" ]]
then
    wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz
fi
tar -zxvf apr-1.5.2.tar.gz
mkdir /usr/local/lib/apr-1.5.2
cd $dir/apr-1.5.2
./configure --prefix=/usr/local/lib/apr-1.5.2 
make
make install

cd $dir
if [[ `ls|grep apr-util` == "" ]]
then
    wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz
fi
tar -zxvf apr-util-1.5.4.tar.gz
mkdir /usr/local/lib/apr-util-1.5.4.tar.gz
cd $dir/apr-util-1.5.4
./configure --prefix=/usr/local/lib/apr-util-1.5.4 --with-apr=/usr/local/lib/apr-1.5.2
make 
make install

cd $dir
if [[ `ls|grep pcre` == "" ]]
then
    wget http://ncu.dl.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz
fi
tar -zxvf pcre-8.37.tar.gz
mkdir /usr/local/lib/pcre-8.37
cd $dir/pcre-8.37
./configure --prefix=/usr/local/lib/pcre-8.37
make 
make install

cd $dir
if [[ `ls|grep httpd` == "" ]]
then
    wget http://www.apache.org/dist/httpd/httpd-2.4.12.tar.gz
fi
tar -zxvf httpd-2.4.12.tar.gz
mkdir /usr/local/lib/httpd-2.4.12
cd $dir/httpd-2.4.12
./configure --prefix=/usr/local/lib/httpd-2.4.12 --with-apr=/usr/local/lib/apr-1.5.2  --with-apr-util=/usr/local/lib/apr-util-1.5.4 --with-pcre=/usr/local/lib/pcre-8.37  --enable-so
make
make install

#解决httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

sed -i 's/^#ServerName www.example.com:80/ServerName localhost/g' /usr/local/lib/httpd-2.4.12/conf/httpd.conf

/usr/local/lib/httpd-2.4.12/bin/apachectl start                          #启动apache
if [[ `curl -s localhost:80|grep "It works"` != "" ]]
then
    echo "----------------------安装成功-------------------------------------"
    cd $dir
    rm -rf apr-1.5.2/ apr-util-1.5.4/ pcre-8.37/ httpd-2.4.12/
fi
©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值