安装环境Centos7,联网进行安装。
脚本如下:
#!/bin/bash
[ $(id -u) != "0" ] && echo "error,not root user" && exit 1
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/bin:/usr/sbin
which httpd
if [ $? -eq 0 ];then
yum remove ‘yum list installed | grep httpd‘ -y
#移除httpd 在已经安装的软件中搜索httpd 然后卸载
exit 1
fi
if [ ! -d /opt ];then
#检查是/opt是否为目录,不是则创建并进入,是则进入
mkdir /opt && cd /opt
else
cd /opt
fi
echo "是否下载apache(y/n)"
read -p "请输入y/n" cho
case $cho in
y)
echo "正在下载Apache"
wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.35.tar.bz2
wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.5.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
a=httpd-2.4.35
b=apr-1.6.5
c=apr-util-1.6.1
;;
n)
echo "退出下载"
exit 0
;;
*)
echo "错误退出请输入(y/n)"
;;
esac
if [ $? -eq 0 ];then
tar xjf $a.tar.bz2
tar zxf $b.tar.gz
tar zxf $c.tar.gz
else
echo "下载错误"
exit 1
fi
cp -R $b /opt/$a/srclib/apr
cp -R $c /opt/$a/srclib/apr-util
yum install gcc gcc-c++ pcre pcre-devel zlib-devel expat-devel -y
cd /opt/$a
./configure \
--prefix=/usr/local/httpd \
--enable-deflate \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--disable-cgi
make && make install
grep -v "#" /usr/local/httpd/bin/apachectl > /etc/init.d/httpd
sed -i ‘1i # description:Apache is a World Wide Web server.‘ /etc/init.d/httpd
sed -i ‘1i # chkconfig:2345 85 15‘ /etc/init.d/httpd
sed -i ‘1i #!/bin/sh‘ /etc/init.d/httpd
chmod +x /etc/init.d/httpd
chkconfig --add httpd
chkconfig --level 35 httpd on
ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf
新手上路,请大家多多指点。
原文地址:http://blog.51cto.com/13760226/2293803