一键安装apache2.2.34
安装环境: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