安裝環境:centos6.5 部分依賴包已提前安裝。
yum install -y apr-devel \
apr-util-devel \
openssl-devel \
libevent-devel \
pcre-devel
源碼包目錄:/usr/local/src/
安裝目錄:/usr/local/apache2
因為script里有用到相對目錄的操作,所以不能用bash或者 ./ 執行,因為這兩種方式會切換到子shell環境,提示找不到路徑。
需要這樣執行或者將腳本路徑全部換成真實路徑。
# source auto_install_apache.sh
#!/bin/bash
#centos6.5
#2.6.32-431.el6.x86_64
#auto install httpd to /usr/local/apache2
#by sunny 2015
yum install -y \
zlib-devel \
openssl-devel
#path
prefix=/usr/local/apache2
file=httpd-2.2.34.tar.gz
filedir=httpd-2.2.34
hurl=http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/
#download apache
cd /usr/local/src/
wget -c $hurl$file
if [ $? -eq 0 ];then
tar -zxvf $file &&cd $filedir
fi
#configure ; install
if [ "$PWD" = "/usr/local/src/$filedir" ];then
./configure \
--prefix=$prefix \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-ssl \
--enable-rewrite \
--enable-modules=most \
--enable-so
if [ $? -eq 0 ];then
make &&make install
echo -e "\033[32m apache install successful...\033[0m"
echo -e "\033[32m apache install dir:$prefix \033[0m"
else
echo -e "\033[32m error,please check the configure..\033[0m"
fi
else
echo -e "\033[32m error,please check..\033[0m"
fi
本腳本只安裝,接下來配置服務
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
如果需要httpd開機啟動
[root@localhost data]# chkconfig --add httpd [root@localhost data]# chkconfig httpd on [root@localhost data]# chkconfig --list|grep httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
可能chkconfig --add會報錯,編輯 /etc/init.d/httpd,加上兩行內容即可
#chkconfig:235 61 61
#description:apache
