Apache2.4.6编译安装

编译安装Apache2.4.6

Apache2.4系列需要安装最新的apr和apr-util


#!/bin/bash

# 定义域名
domain='mogublog.cn'

yum install -y gcc make wget perl perl-devel pcre pcre-devel zlib zlib-devel openssl openssl-devel

####################################### 开始安装Apache #######################################

#  检查文件
if [ ! -s 'httpd-2.4.6.tar.gz' ]; then
wget http://archive.apache.org/dist/httpd/httpd-2.4.6.tar.gz
fi

if [ ! -s 'apr-1.4.8.tar.gz' ]; then
wget http://archive.apache.org/dist/apr/apr-1.4.8.tar.gz
fi

if [ ! -s 'apr-util-1.5.2.tar.gz' ]; then
wget http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.gz
fi

# 解压
tar zxvf httpd-2.4.6.tar.gz

tar zxvf apr-1.4.8.tar.gz
mv apr-1.4.8 httpd-2.4.6/srclib/apr
tar zxvf apr-util-1.5.2.tar.gz
mv apr-util-1.5.2 httpd-2.4.6/srclib/apr-util

# 编译安装
cd httpd-2.4.6
./configure 
--prefix=/usr/local/apache 
--enable-so --enable-headers --enable-mime-magic --enable-rewrite --enable-deflate --enable-ssl=shared 
--with-included-apr --with-mpm=prefork 
--disable-userdir --disable-cgid --disable-cgi --disable-autoindex --disable-status --disable-env --disable-actions --disable-negotiation --disable-alias --disable-include --disable-filter --disable-version --disable-asis
make && make install
cd ..

# 把Apache注册为服务
rm -f /etc/init.d/httpd
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
sed -i '2c# chkconfig: - 85 15' /etc/init.d/httpd
sed -i '3c# description: apache' /etc/init.d/httpd

# 设置Apache开机启动
chkconfig httpd --add
chkconfig httpd on

# 修改Apache配置文件
sed -i 's/^#ServerName www.example.com:80/ServerName '$domain':80/' /usr/local/apache/conf/httpd.conf
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm/g' /usr/local/apache/conf/httpd.conf
sed -i 's/Options Indexes FollowSymLinks/Options FollowSymLinks/g' /usr/local/apache/conf/httpd.conf

# Apache安全设置
echo "ServerTokens Prod" >> /usr/local/apache/conf/httpd.conf
echo "TraceEnable off" >> /usr/local/apache/conf/httpd.conf

# 创建Apache配置文件快捷方式
rm -f /etc/httpd.conf
ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf

# 设置防火墙开启80端口
if [ -s /sbin/iptables ]; then
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/init.d/iptables save
/etc/init.d/iptables restart
fi

# 清理文件
rm -rf httpd-2.4.6

发表评论